?
Solved

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

Posted on 2008-11-18
7
Medium Priority
?
598 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:CMHSW3
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:ExEx-Austin
ID: 22994005
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
 

Author Comment

by:CMHSW3
ID: 22995368
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
 
LVL 1

Expert Comment

by:ExEx-Austin
ID: 22995553
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:CMHSW3
ID: 22996241
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
 
LVL 1

Accepted Solution

by:
ExEx-Austin earned 1000 total points
ID: 22996397
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
 

Author Comment

by:CMHSW3
ID: 23005769
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
 

Author Closing Comment

by:CMHSW3
ID: 31518052
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Integration Management Part 2
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question