Microsoft, VB script, Any, login, copy file from server to user profile, group policy

CMHSW3
CMHSW3 used Ask the Experts™
on
I was given the challenge today to create a group policy that would copy a single file from a server share to c:\documents and settings\username\application data\subfoldername.

I experimented with a login script that used a batch file that contained a UNC to the file on the server, but discovered that it balked at using the UNC (not all of the users have the same drive mapping to the share on the server so I can't use a mapped drive letter).

I tried creating an msi file with WinINSTALL LE - that was overkill...

So I decided to try my hand at writing a script. I've scoured EE & other sources for scripts but have not had much success in modifying them for my need. At the most I have created a script that will copy all the files from the source folder but it does not get to the correct destination. The files wind up in a subfolder of the directory from which I'm running the script.
I've attached the most successful script I have...
Set oShell=CreateObject( "WScript.Shell" )
username=oShell.ExpandEnvironmentStrings("%UserName%")
path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserName%")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Documents and Settings\%UserName%\Application Data\subfoldername\") = False Then
objFSO.CopyFolder "\\server\share1\share2", "path"
objFSO.CopyFile "\\server\share1\share2\*.ini", "path"
End If

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I am guessing the subfolder you mention is of the username.
The path variable you create in line 3 is only the username.  In 7 & 8 you use the username as the path, and that causes the subfolder to be created.

Re-write the path statement in line 3 to get the complete path you need,
  or expand the path in lines 7 & 8 as you did in line 6,
  or move to the destination parent directory before running the sript...

Author

Commented:
I tried this but got an error on line 7 char. 1 saying the path could not be found. I'm confused as to which path it's referring.
Set oShell=CreateObject( "WScript.Shell" )
username=oShell.ExpandEnvironmentStrings("%UserName%")
path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserName%")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Documents and Settings\%UserName%\Application Data\subfolder\") = False Then
objFSO.CopyFolder "\\server\share1\share2", "C:\Documents and Settings\%UserName%\Application Data\subfolder\"
objFSO.CopyFile "\\server\share1\share2\*.ini", "C:\Documents and Settings\%UserName%\Application Data\subfolder\"
 
End If

Open in new window

Have you confirmed that line 6 is working correctly?  This coul dbe done by running the script on a system that already has the file in place, so the expression evaluates "True" and skips the rest.
This will validate your syntax.

On line 7 - does the floder named "subfolder" already exist?
Does line 8 run, and end up making a folder called "subfolder" and place the file in it?  Or does it error-out?
Try trimming Line 7 to "C:\Documents and Settings\%UserName%\Application Data"

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Author

Commented:
The file is already there on my test PC, and I get the error referringto line 7 path could not be found, so I'm guessing that line 6 isn't correct.

The subfolder in line 7 already exists. I don't get an error referring to line 8.

I just now modified line 7 to say objFSO.CopyFolder "\\server\share1\share2", "C:\Documents and Settings\%UserName%\Application Data" and got the same error sayin the path could not be found.
OK, so the syntax in 6 & 7 are off, and I am not sure on some of this as I can't do any testing at the moment.
But, for the path in 7, try "C:\Documents and Settings\" & UserName & "\Application Data\subfolder\"

Author

Commented:
YES! That worked! Initially it balked at line 8, so I applied it to that line as well and the file came over to the intended destination.

Many thanks!

Author

Commented:
I apologize for not getting back to you sooner but I had a couple late testers try it out for me and they didn't get back to me until a few minutes ago.
Thank you very much for your patience and effort in this!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial