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)

oshell.Run "xcopy ""C:\Users\" & strUsername & "\AppData\Local\VirtualStore\Windows\Payroll.ini"" ""M:\Sage Payroll Favourites - Do Not Delete\"" /E /Y",1,True
0 Comments   [ - ] Hide Comments


Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity


check this link
Answered 03/13/2012 by: mahendraKumar
Senior Yellow Belt

Please log in to comment
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\""
strDsetinationFolder = "M:\Sage Payroll Favourites - Do Not Delete\"

Set objShellApp = CreateObject("Shell.Application")
Set objFolder = objShellApp.NameSpace(strSourceFolder)
If objFSO.fileExists(strSourceFolder + strTargetFile) Then
objFolder.CopyHere strDestinationFolder + strTargetFile, FOF_CREATEPROGRESSDLG 'Change the install file(s) location as needed.
End If
Answered 03/20/2012 by: Trinity
Brown Belt

Please log in to comment