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

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

CMHSW3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ExEx-AustinCommented:
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...
0
CMHSW3Author 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

0
ExEx-AustinCommented:
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"

0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

CMHSW3Author 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.
0
ExEx-AustinCommented:
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\"

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CMHSW3Author 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!
0
CMHSW3Author 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!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.