Cannot execute Scanstate.exe using VBS.

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
stuffs88
Posts: 18
Joined: Wed Jan 12, 2011 7:58 pm

Cannot execute Scanstate.exe using VBS.

Post by stuffs88 » Mon Sep 19, 2011 10:21 pm

Hi All,

I am supposed to execute scanstate.exe with arguments in it as a part of my vb script. I have tried most of the options possible and I could not figure one out. Please help!

These are the options I tried.

-1- MachineName = "."strCommand = "scanstate /i:MigUser.xml /i:MigApp.xml /i:MigDocs.xml c:Profilecapturetool /o /c /nocompress /HardLink"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & MachineName & "rootcimv2")
Set objProcess = objWMIService.Get("Win32_Process")intReturn = objProcess.Create (strCommand, Null, objConfig, intProcessID)If intReturn <> 0 Then Wscript.Echo "Process could not be created." & _ vbNewLine & "Command line: " & strCommand & _ vbNewLine & "Return value: " & intReturnElse Wscript.Echo "Process created." & _ vbNewLine & "Command line: " & strCommand & _ vbNewLine & "Process ID: " & intProcessIDEnd If


-2-

Have tried Run command
wshshell.Run " pathscanstate.exe,1,true"
This is not waiting for the process to finish. It takes quite sometime to complete. I trie giving exit code, wscript.sleep in a loop and also tried objshell.exec("scanstate.exe")

Is there any particular way to ensure that the process completes? Please let me know..thannks in advance.

User avatar
stuffs88
Posts: 18
Joined: Wed Jan 12, 2011 7:58 pm

Cannot execute Scanstate.exe using VBS.

Post by stuffs88 » Mon Sep 19, 2011 10:21 pm

Hi All,

I am supposed to execute scanstate.exe with arguments in it as a part of my vb script. I have tried most of the options possible and I could not figure one out. Please help!

These are the options I tried.

-1- MachineName = "."strCommand = "scanstate /i:MigUser.xml /i:MigApp.xml /i:MigDocs.xml c:Profilecapturetool /o /c /nocompress /HardLink"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & MachineName & "rootcimv2")
Set objProcess = objWMIService.Get("Win32_Process")intReturn = objProcess.Create (strCommand, Null, objConfig, intProcessID)If intReturn <> 0 Then Wscript.Echo "Process could not be created." & _ vbNewLine & "Command line: " & strCommand & _ vbNewLine & "Return value: " & intReturnElse Wscript.Echo "Process created." & _ vbNewLine & "Command line: " & strCommand & _ vbNewLine & "Process ID: " & intProcessIDEnd If


-2-

Have tried Run command
wshshell.Run " pathscanstate.exe,1,true"
This is not waiting for the process to finish. It takes quite sometime to complete. I trie giving exit code, wscript.sleep in a loop and also tried objshell.exec("scanstate.exe")

Is there any particular way to ensure that the process completes? Please let me know..thannks in advance.

User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Cannot execute Scanstate.exe using VBS.

Post by rasimmer » Tue Sep 20, 2011 1:52 am

You should be able to do something simple, like:

Dim objWSHShell : Set objWSHShell = CreateObject("WScript.Shell")Dim strUSMTPath : strUSMTPath = "servershareUSMT"Dim strCMD : strCMD = "%COMSPEC% /C " & strUSMTPath & "scanstate.exe C:StateStore /o /localonly /c /efs:copyraw " &_ "/v:5 /l:C:MyLogsUSMTscanstate.log /progress:C:MyLogsUSMTscanstateprogress.log " &_ "/i:" & strUSMTPath & "Custom.xml " &_ "/i:" & strUSMTPath & "MigApp.xml " &_ "/i:" & strUSMTPath & "MigDocs.xml " &_ "/nocompress /hardlink" Dim errReturn : errReturn = objWSHShell.Run(strCMD, 1, True)If errReturn = 0 Then WScript.Echo "Command completed successfully"Else WScript.Echo "Command returned error " & errReturnEnd If

You should definently make sure you are generating logs and setting the verbosity high if you are just starting to work with ScanState or LoadState and would also recommend the progress log so that you can validate that scanstate is running if you want to it silently.

User avatar
rasimmer
Posts: 182
Joined: Fri Jan 30, 2009 12:37 am

Cannot execute Scanstate.exe using VBS.

Post by rasimmer » Tue Sep 20, 2011 5:26 am

You need to look at your command line and make sure it's the same thing as your manual command line (i.e. WScript.Echo strCMD). You can also look at scanstate.log to see the command that was run and make a comparison and also determine if you are utilizing the same XML rules in your manual command. It's irrelvant that VBScript is running the command, what is relevant is that you are using the same switches and XML rulesets during command execution AND that it is being run as administrator. If you run SCANSTATE with a non-administrator account, it will only capture that users account information.

User avatar
stuffs88
Posts: 18
Joined: Wed Jan 12, 2011 7:58 pm

Cannot execute Scanstate.exe using VBS.

Post by stuffs88 » Tue Sep 20, 2011 9:57 pm

And, How can I run as administrator through VB script?

I am running it manually in a local command prompt itself, not as a administrator.

jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Cannot execute Scanstate.exe using VBS.

Post by jvierra » Tue Sep 20, 2011 10:24 pm

And, How can I run as administrator through VB script?

I am running it manually in a local command prompt itself, not as a administrator.


To run a script as an administrator you need to go to a prompt and type:
RunAs /u:admin "cmd /k cscript f:projectsscriptsmyscript.vbs"


User avatar
stuffs88
Posts: 18
Joined: Wed Jan 12, 2011 7:58 pm

Cannot execute Scanstate.exe using VBS.

Post by stuffs88 » Tue Sep 20, 2011 11:43 pm

Hi,

I belong to the latter case, XP with admin credentials and hence I am able to capture all the profiles when executing it manually!
You must run the ScanState command on Windows® XP from an account with administrative credentials. Otherwise, some operating system settings may not migrate - for example, wallpaper settings, screen-saver selections, modem options, media-player settings, and Remote Access Service (RAS) connection phone book (.pbk) files and settings. For this reason, we recommend that you run the ScanState and LoadState commands from within an account with administrative credentials.
And I think, after looking at the scanstate.logs, I need to elevate the priviledge of the vbs script itself.

I had been using this script up till now:

MachineName = "."strCommand = "C:Landesk-Scripttest.bat"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!" & MachineName & "rootcimv2")
Set objProcess = objWMIService.Get("Win32_Process")intReturn = objProcess.Create (strCommand, Null, objConfig, intProcessID)
If intReturn <> 0 ThenWscript.Echo "Process could not be created." & _vbNewLine & "Command line: " & strCommand & _vbNewLine & "Return value: " & intReturn
ElseWscript.Echo "Process created." & _vbNewLine & "Command line:" & strCommand & _vbNewLine & "Process ID: " & intProcessIDEnd If


where the .bat file contains the scanstate.exe command.


I tried these ways in VAIN to elevate the priviledge:

Const ABOVE_NORMAL = 32768
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" _
& strComputer & "rootcimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcesses
objProcess.SetPriority(ABOVE_NORMAL)
NextThe above script does not execute .bat file.Later tried: - -Set objSh = CreateObject("Shell.Application")objSh.ShellExecute "notepad.exe", "" , "", "runas", 1Doesn't seem to work too.Now going to try: Set colProcesses = GetObject( _ "winmgmts:{impersonationLevel=impersonate}" _ ).ExecQuery( "Select * From Win32_Process", , 48 )Got this from msdn, not sure if it would be working. Please tell me if these methods are wrong!

Locked