BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
VBScript File Copy Help
Tuesday, January 24, 2012 3:15 AM
( permalink)
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) Any help would be greatly appreciated. Here is the last script i was trying to use that wouldnt do it. There has to be a way to do this. Thanks.. 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 [/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style] [/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style][/style]
<message edited by BrentW on Tuesday, January 24, 2012 3:17 AM>
|
|
|
|
dm_4ever
-
Total Posts
:
3687
- Scores: 82
-
Reward points
:
0
- Joined: 6/29/2006
- Location: Orange County, California
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 4:57 AM
( permalink)
Have you tried something like this: Option Explicit
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objNetwork : Set objNetwork = CreateObject("Wscript.Network")
Dim strUserName : strUserName = objNetwork.UserName
Dim strSource : strSource = "\\VEOFS02\emailsigs\" & strUserName & "\*"
objFSO.CopyFile strSource, "c:\Documents and Settings\" & strUserName & "\Application Data\Microsoft\Signatures\"
|
|
|
|
BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 5:11 AM
( permalink)
I get path not found on the profile location even though the path is fine and if I were to change the file being copied to a generic txt file it would copy and use that path without a problem. And I did just try that and it copies a text.txt file without any trouble but if I use the string trying to get it to find file names based on user names it fails out and gives me a Line: 24 Char: 1 Error: Path not found Code: 800A004C Line 24 is objFSO.CopyFile strSource, "c:\Documents and Settings\" & strUserName & "\Application Data\Microsoft\Signatures\" And that is the same location I copied test.txt file to in order to prove the script. This is where I have been stuck. It keeps coming back to the fact that it just cant find the file name based on a wildcard but it cant be this hard.
<message edited by BrentW on Tuesday, January 24, 2012 5:12 AM>
|
|
|
|
dm_4ever
-
Total Posts
:
3687
- Scores: 82
-
Reward points
:
0
- Joined: 6/29/2006
- Location: Orange County, California
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 5:17 AM
( permalink)
If you add the following before the copy...does the output look correct? WScript.Echo strSource WScript.Echo "c:\Documents and Settings\" & strUserName & "\Application Data\Microsoft\Signatures\"
|
|
|
|
BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 5:26 AM
( permalink)
Nope.. It shows \\VEOFS02\emailsigs\bwall\* instead of bwall.* So I changed Dim strSource : strSource = "\\VEOFS02\emailsigs\" & strUserName & "\*" To Dim strSource : strSource = "\\VEOFS02\emailsigs\" & strUserName & ".*" and it reads correct and it doesnt error out but nothing copies still.. I am at a loss on this.. no idea what is going on. I can manually copy and reach all of these paths. I just cant get this script to do it.
|
|
|
|
BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 5:27 AM
( permalink)
Oh wait.. As soon as I hit ok on that little box it copied.. It worked with my tweak in there. Now to see if it works for other people.. I will let you know if it does. I appreciate the help.. I can usually tweak something to suit my needs but I cant do it all alone. thanks a bunch.
|
|
|
|
dm_4ever
-
Total Posts
:
3687
- Scores: 82
-
Reward points
:
0
- Joined: 6/29/2006
- Location: Orange County, California
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 5:35 AM
( permalink)
Ok...let us know if you run into any other issues and hopefully we can help.
|
|
|
|
BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 6:55 AM
( permalink)
The only thing now is that when you manually copy the htm version of the signature it will automatically copy the folder containing the images. In my case that folder is named bwall_files. When the vbscript copies the files it doesnt automatically take the folder with it like a manual copy does. I have tried adding it into the script a few different ways but it doenst like it. Any idea on that one? Its in the same folder and they are all named like the files, username_files but its a folder.
|
|
|
|
BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 7:01 AM
( permalink)
Oh and another dumb question. How do I make this script completely bail out if there isnt a file for that person? I would like to to run silently so the users has no idea it even happened and if they dont have a file to be copied that it just aborts and doesn't give them a error.
|
|
|
|
BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 7:43 AM
( permalink)
Ok.. here is what I have. I had to do it in two scripts. But I would like it to be in one and I have two questions also. First here are the two scripts. This one is to copy the Sig Files And it works fine now Option Explicit
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objNetwork : Set objNetwork = CreateObject("Wscript.Network")
Dim strUserName : strUserName = objNetwork.UserName
Dim strSource : strSource = "\\VEOFS02\emailsigs\" & strUserName & ".*"
objFSO.CopyFile strSource, "c:\Documents and Settings\" & strUserName & "\Application Data\Microsoft\Signatures\" And this one copies the files to the username_files folder and it works also provided the folder is there Option Explicit
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objNetwork : Set objNetwork = CreateObject("Wscript.Network")
Dim strUserName : strUserName = objNetwork.UserName
Dim strSource : strSource = "\\VEOFS02\emailsigs\" & strUserName & "_files\*.*"
objFSO.CopyFile strSource, "c:\Documents and Settings\" & strUserName & "\Application Data\Microsoft\Signatures\" & strUserName & "_files\" Can I smash these into one script easily? When I try I get errors. Also I need it to abort if there is an error and if possible look and create the username_files folder if it is missing. I know I am being a pest but this is kicking my butt today.. lol
|
|
|
|
dm_4ever
-
Total Posts
:
3687
- Scores: 82
-
Reward points
:
0
- Joined: 6/29/2006
- Location: Orange County, California
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 9:30 AM
( permalink)
Not tested but maybe something like this Option Explicit
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objNetwork : Set objNetwork = CreateObject("Wscript.Network")
Dim strUserName : strUserName = objNetwork.UserName
Dim strSource1 : strSource1 = "\\VEOFS02\emailsigs\" & strUserName & ".*"
Dim strSource2 : strSource2 = "\\VEOFS02\emailsigs\" & strUserName & "_files\*.*"
Dim strDestFolder : strDestFolder = "c:\Documents and Settings\" & strUserName & "\Application Data\Microsoft\Signatures\"
objFSO.CopyFile strSource1, strDestFolder
If Not objFSO.FolderExists(strDestFolder & strUserName & "_files\") Then objFSO.CreateFolder strDestFolder & strUserName & "_files\"
objFSO.CopyFile strSource1, strDestFolder & strUserName & "_files\"
|
|
|
|
BrentW
-
Total Posts
:
8
- Scores: 0
-
Reward points
:
0
- Joined: 1/24/2012
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 9:40 AM
( permalink)
Almost worked.. It copied the .htm, .rtf and .txt files into both locations, the root and the folder. I figured it out though.. I changed the last line to strSource2 and it got that. I see you have the If Not statement in there. Will that be enough to where it will ignore completely if a user has nothing to copy. no source or destination? I am going to try and give it a test run on a user to see but not all of our users have the signatures or even e-mail for that matter.. But your my hero either way.. I knew i wasnt real far off but I would not have gotten it figure out. I had tried changing the strSource but I just made one of them strSource2 and didnt make the other one 1 and it threw it all out of whack.. lol.. I know just enough to tear it up..
|
|
|
|
dm_4ever
-
Total Posts
:
3687
- Scores: 82
-
Reward points
:
0
- Joined: 6/29/2006
- Location: Orange County, California
-
Status: offline
|
Re:VBScript File Copy Help
Tuesday, January 24, 2012 11:52 AM
( permalink)
You'll want to add some more If statements in there to check if folder/files don't exists. Look at the FolderExists and FileExists methods of the FileSystemObject
|
|
|
|