Link to home
Create AccountLog in
Avatar of barrykeel
barrykeel

asked on

Script Does Not Work

Can't figure this script out. It runs, returns no errors but does not work. The file does not copy. And yes the file does exists. I am trying to use the variable %USERNAME% in the script.
Option Explicit
Dim objFSO, objShell
Dim strUser
Set objShell = CreateObject("Wscript.Shell")
strUser = objShell.ExpandEnvironmentStrings("%USERNAME%")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If objFSO.FileExists("C:\Documents and Settings\ & strUser & \Application Data\Microsoft\Outlook\ & strUser & .NK2") Then
     objFSO.CopyFile "C:\Documents and Settings\ & strUser & \Application Data\Microsoft\Outlook\ & strUser & .NK2" , "\\servername\ & strUser & \ & strUser & .NK2" , True
 
End If
 
set objFSO = nothing
set strUser = nothing
WScript.Quit

Open in new window

Avatar of gs121
gs121
Flag of United States of America image

You could try this to get the login name....

dim wsh
set wsh = createobject("WScript.Shell")
login_name = wsh.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name")

src = "C:\documents and settings\" & login_name & "\Favorites"
dim wsh
set wsh = createobject("WScript.Shell")
login_name = wsh.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Logon User Name")

src = "C:\documents and settings\" & login_name & "\Favorites"
ASKER CERTIFIED SOLUTION
Avatar of wtstadd
wtstadd
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer