Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am very new to VBS scripting and would like some help to create a vbs logon script to check and make sure that the file does not exsist on the local account/profile directory first and then copy some files from a network location to a local account/profile that is currently logon to a PC. I did some online research and found this script.
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Documents and Settings\%username%\") = False Then
objFSO.CopyFolder "\\server\share\*", "C:\Documents and Settings\%username%\"
objFSO.CopyFile "\\server\share\*.txt", "C:\Documents and Settings\%username%\"
End IfWhen doing a test run of the script, I get a windows script host msg of the folowing:
Error: path not found
Code: 800A004CIf some one can help me with this I would really appreciate it. Thanks!

You have to change this line:
"\\server\share\*"
to reflect your UNC path.
"Computer security." — Oxymoron

I'd try changing it but got the same error. It looks like it is no able to find the path of C:\Documents and Settings\%username%. I tried using a test folder name 'test' instead of %username% and it worked so it seems that I need help on getting the correct UNC path for the logon user account/profile. What would be the correct UNC path to copy the files to a logon user?

You need to use the ExpandEnvironmentStrings() function.
Set oShell = CreateObject( "WScript.Shell" )
username=oShell.ExpandEnvironmentStrings("%UserName%")
dim objFSO
set objFSO=CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\Documents and Settings\username\") = False Then
objFSO.CopyFolder "\\server\share\*", "C:\Documents and Settings\username\"
objFSO.CopyFile "\\server\share\*.txt", "C:\Documents and Settings\username\"
End IfI do not know VBScript, but to me, this looks like it should work.
"Computer security." — Oxymoron

Thanks, for getting back to me but I tried this and I am still getting the same error of path not found. It is telling me that the path on Line 6 is not found, which is;
objFSO.CopyFolder "\\server\share\*", "C:\Documents and Settings\username\"
Do you have any other ideas?

Well since I don't know VBScript, I'm not going to waste your time with useless VBScripts. Here is a solution in batch.
@echo off
if not exist "C:\Documents and Settings\%username%" (
goto :_copy
) else (
goto :eof
):_copy
net use t: \\server\share /user:domain\user password
xcopy t:\*.txt "C:\Documents and Settings\%username%"Replace the italicized text with your information
"Computer security." — Oxymoron

Just build the path and store it in a string:
path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%\")
Then just refer to THAT as needed:
objFSO.CopyFolder "\\server\share\*", path

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |