Home All Groups Group Topic Archive Search About

Copy File to user's profile



Author
20 Apr 2007 2:48 PM
Michael Martis
I need to copy a config file to each user's Documents and Setting/Local
Settings. This is what I have so far,

Const OverwriteExisting = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\Server\Share\LinkConfig\Config.ini" , "C:\Documents and
Settings\%USERNAME%\Application Data\LinkConfig\", OverwriteExisting

My main problem is getting the file to copy to the logged in user's profile.

Any help would be greatly appreciated!!

Author
21 Apr 2007 2:12 AM
Marty List
VBScript won't automatically expand the %USERNAME% variable, that's a
CMD.EXE/Command Prompt feature.  You could use the ExpandEnvironmentStrings
method:
http://msdn2.microsoft.com/en-us/library/dy8116cf.aspx

But the 'Documents and Settings' folder might be on D:\, so you should use
%USERPROFILE%.  But the user's Application Data folder could be redirected
somewhere else, so even better would be %APPDATA%.

Another way would be to use WSH's SpecialFolders property:

Set objShell = WScript.CreateObject("WScript.Shell")
AppData = objShell.SpecialFolders("AppData")
objFSO.CopyFile "\\Server\Share\LinkConfig\Config.ini" , AppData &
"\LinkConfig\", OverwriteExisting



Show quote
"Michael Martis" <Michael Mar***@discussions.microsoft.com> wrote in message
news:61290DBD-B995-4274-BF83-3D1893D6A486@microsoft.com...
>I need to copy a config file to each user's Documents and Setting/Local
> Settings. This is what I have so far,
>
> Const OverwriteExisting = TRUE
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> objFSO.CopyFile "\\Server\Share\LinkConfig\Config.ini" , "C:\Documents and
> Settings\%USERNAME%\Application Data\LinkConfig\", OverwriteExisting
>
> My main problem is getting the file to copy to the logged in user's
> profile.
>
> Any help would be greatly appreciated!!
>

AddThis Social Bookmark Button