Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need File Copy VBScript or other suggestion

Status
Not open for further replies.

Brent1972

IS-IT--Management
Jan 24, 2012
3
US
I have been trying to find a script to make a simple file copy at login that has turned out to be not so simple. I dont write code myself but I can usually find something on line that I can manipulate to fit my needs. In this case it seems I am doing something out of the ordinary and while I am not above begging for help I would be glad to have someone point me towards something that can do what I need or if it is simple enough to write something me. What I am doing is trying to copy a user signature file into the c:\Documents and Settings\" & StrUsername & "\Application Data\Microsoft\Signatures\ directory at logon. The problem is the files for these users are named by their user names so in my case my signature file is bwall.htm. I have tried using typical vbscript wildcards regarding usernames and while they work in a directory string I cant get them to call the filename and copy it. I can make the scripts I have used copy a simple text file with a generic name just to prove to myself that the scripts work but I cant get it to see the user name with it being a user name. These files are all in one directory on our network to make it easier for us to edit and keep track of them. So I am copy from a network share to a local folder within the user profile so there are several variables here.
*Copying from a network location that the user does have access to
*copying to the users profile so there is a wildcard in the folder string
*copying a files with the username as the file name. 3 Files (<username>.htm, <username>.rtf and <username>.txt)


Option Explicit
Dim objFSO, objNetwork, strUserName
Dim strShare, strSource

' Specify source for file to copy.
'strShare = "\\VEOFS02\emailsigs"
strSource = "\\VEOFS02\emailsigs\ & StrUsername & *.*"


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")

' Retrieve user name.
strUserName = objNetwork.UserName

' Map drive.
' objNetwork.MapNetworkDrive "S:", strShare

' Copy file.
objFSO.CopyFile strSource, "c:\Documents and Settings\" & StrUsername & "\Application Data\Microsoft\Signatures\"

' Clean up.
' objNetwork.RemoveNetworkDrive "S:", True, True
 
The first thing I notice is you are trying to use the value of strUserName in strSource before you retrieve a value for the user.

This may not be the magic bullet, but needs to be fixed.
 
And how do I do that. I do not write code at all.. I can play around with other things and usually get them to work for me but as far as writing it or knowing what you just told me to do.. Not a chance.. lol.. I appreciate the suggestion though..
 
Code:
...
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.UserName
strSource = "\\VEOFS02\emailsigs\" & strUserName & "*.*" 
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Now I get a Error: Object Required:" on the following line

strUserName = objNetwork.UserName

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top