Logoff Script to copy one file.
Hi all,
I'm trying to use a VB script to copy a file from under the user profile relating to a piece of software. I'm thinking of trying to copy it just before or as the user is logging off. The script I am using is below. I have it linked in Group Policy under User Configuration, Policies, Windows Settings, Scripts, Logoff. The script does not appear to run or is getting cancelled before it has a chance to run. Am I missing something? Please give me all the basic's to look at please.
strComputer = "."
Set oShell = WScript.CreateObject ("WSCript.shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'explorer.exe'")
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strUserName)
Next
oshell.Run "xcopy ""C:\Users\" & strUsername & "\AppData\Local\VirtualStore\Windows\Payroll.ini"" ""M:\Sage Payroll Favourites - Do Not Delete\"" /E /Y",1,True
WScript.Quit()
I'm trying to use a VB script to copy a file from under the user profile relating to a piece of software. I'm thinking of trying to copy it just before or as the user is logging off. The script I am using is below. I have it linked in Group Policy under User Configuration, Policies, Windows Settings, Scripts, Logoff. The script does not appear to run or is getting cancelled before it has a chance to run. Am I missing something? Please give me all the basic's to look at please.
strComputer = "."
Set oShell = WScript.CreateObject ("WSCript.shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'explorer.exe'")
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strUserName)
Next
oshell.Run "xcopy ""C:\Users\" & strUsername & "\AppData\Local\VirtualStore\Windows\Payroll.ini"" ""M:\Sage Payroll Favourites - Do Not Delete\"" /E /Y",1,True
WScript.Quit()
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
mahendraKumar
12 years ago
Posted by:
Trinity
12 years ago
You could also use Folder.CopyHere method. A progress bar will be displayed prior to log off. This example contains an IF EXISTS ELSE THEN statement that can be easily removed. If you remove the IF EXISTS ELSE THEN statement you will need to remove the END IF as well.
strSourceFolder = ""C:\Users\" + strUsername + "\AppData\Local\VirtualStore\Windows\""
strTargetFile="Payroll.ini"
strDsetinationFolder = "M:\Sage Payroll Favourites - Do Not Delete\"
Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.NameSpace(strSourceFolder)
'---------------------------------------------------------------------------
If objFSO.fileExists(strSourceFolder + strTargetFile) Then
Else
objFolder.CopyHere strDestinationFolder + strTargetFile, FOF_CREATEPROGRESSDLG 'Change the install file(s) location as needed.
End If
strSourceFolder = ""C:\Users\" + strUsername + "\AppData\Local\VirtualStore\Windows\""
strTargetFile="Payroll.ini"
strDsetinationFolder = "M:\Sage Payroll Favourites - Do Not Delete\"
Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.NameSpace(strSourceFolder)
'---------------------------------------------------------------------------
If objFSO.fileExists(strSourceFolder + strTargetFile) Then
Else
objFolder.CopyHere strDestinationFolder + strTargetFile, FOF_CREATEPROGRESSDLG 'Change the install file(s) location as needed.
End If
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.