Hi,
I am trying to automate a process, whereby each time a user logs on a certain file (saved on a shared drive) is copied to their desktop. If that file already exists on the desktop (i.e. an old version), then it is deleted and replaced with the current one.
After some help from a fellow Tek-tips expert, I have managed to get this far....
On error goto 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'Create a Path to a log file
Const fileName = "c:\vbslog.txt"
Dim WshShell,WshEnv
Dim WshNetwork:Set WshNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objFSO = CreateObject("Scripting.FileSystemObject")
SysDrive = WshEnv("SYSTEMDRIVE")
Dim objDomain:Set objDomain = getObject("LDAP://rootDse")
Dim DomainString
omainString = objDomain.Get("dnsHostName")
Dim UserString:UserString = WshNetwork.UserName
Dim objADSysInfo:Set objADSysInfo = CreateObject("ADSystemInfo")
strComputer = WshNetwork.ComputerName
UserDesktop = WshShell.SpecialFolders("Desktop")
'Your file name
fname = "test.xls"
'Source file location
SFile = SysDrive & "\\dxbserver1\public\" & fname
'Destination Location
Dfile = "\\dxbserver1\users\" & UserString & "\Desktop"
'Delete The file
path = dfile & "\" & fname
wscript.echo path
Set file = objFSO.GetFile(path)
If objFSO.FileExists(path) Then
objFSO.DeleteFile file.Path
End if
'Wait 5 seconds
wscript.sleep 5000
'Log Success and Failure
Set fso = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(Data_Path & filename) Then
Set f = fs
penTextFile(Data_Path & fileName,2, True)
Else
Set f = fs
penTextFile(Data_Path & fileName,8)
End If
If strComputer = "" Then
f.WriteLine VbCrLf & strComputer &" did not respond."
Else
f.WriteLine VbCrLf & strcomputer & " responded."
objfso.CopyFile SFile, DFile, overwrite = TRUE
End If
But when running this I get a error:
Line: 35
Char: 1
Error: file not found
Code: 800A0035
Please note that the user's desktop redirects to a share on my file server, i.e. \\dxbserver1\users\%username%\desktop
Any help would be greatly appreciated!
Steve
I am trying to automate a process, whereby each time a user logs on a certain file (saved on a shared drive) is copied to their desktop. If that file already exists on the desktop (i.e. an old version), then it is deleted and replaced with the current one.
After some help from a fellow Tek-tips expert, I have managed to get this far....
On error goto 0
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'Create a Path to a log file
Const fileName = "c:\vbslog.txt"
Dim WshShell,WshEnv
Dim WshNetwork:Set WshNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
Set objFSO = CreateObject("Scripting.FileSystemObject")
SysDrive = WshEnv("SYSTEMDRIVE")
Dim objDomain:Set objDomain = getObject("LDAP://rootDse")
Dim DomainString
Dim UserString:UserString = WshNetwork.UserName
Dim objADSysInfo:Set objADSysInfo = CreateObject("ADSystemInfo")
strComputer = WshNetwork.ComputerName
UserDesktop = WshShell.SpecialFolders("Desktop")
'Your file name
fname = "test.xls"
'Source file location
SFile = SysDrive & "\\dxbserver1\public\" & fname
'Destination Location
Dfile = "\\dxbserver1\users\" & UserString & "\Desktop"
'Delete The file
path = dfile & "\" & fname
wscript.echo path
Set file = objFSO.GetFile(path)
If objFSO.FileExists(path) Then
objFSO.DeleteFile file.Path
End if
'Wait 5 seconds
wscript.sleep 5000
'Log Success and Failure
Set fso = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(Data_Path & filename) Then
Set f = fs
Else
Set f = fs
End If
If strComputer = "" Then
f.WriteLine VbCrLf & strComputer &" did not respond."
Else
f.WriteLine VbCrLf & strcomputer & " responded."
objfso.CopyFile SFile, DFile, overwrite = TRUE
End If
But when running this I get a error:
Line: 35
Char: 1
Error: file not found
Code: 800A0035
Please note that the user's desktop redirects to a share on my file server, i.e. \\dxbserver1\users\%username%\desktop
Any help would be greatly appreciated!
Steve