Asked by:
VBScript: How create a process in new desktop?

Question
-
I'm trying create a process in a new desktop using the code below, but happens that the process is executed on default desktop. How solve?
set wmi = GetObject( "winmgmts:{impersonationLevel=impersonate}!root/cimv2") set proc = wmi.Get("Win32_Process") set si = wmi.get("WIN32_ProcessStartup") si.WinstationDesktop = "winsta0\LLTTestDesktop1" ' "LLTTestDesktop1" is my new desktop si.CreateFlags = 16 ' Create_New_Console si.ShowWindow = 1 ' SW_NORMAL proc.Create "calc.exe", "C:\Windows\System32", si
- Moved by Reed KimbleMVP Saturday, May 26, 2018 9:45 PM vb script in vb.net language
- Moved by Bill_Stewart Friday, July 27, 2018 8:39 PM Abandoned
Saturday, May 26, 2018 8:34 PM
All replies
-
The forum is dedicated to VB.NET. You should use Bing or Google and search out a VBScript forum.Saturday, May 26, 2018 8:45 PM
-
Please see The Official Scripting Guys Forum!, Microsoft Script Center, Creating a WMI Script and Windows PowerShell
La vida loca
Saturday, May 26, 2018 9:18 PM -
I'll move this for you.
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Saturday, May 26, 2018 9:45 PM -
Please review the following for instructions on how to correctly create the parameters and use them:
https://msdn.microsoft.com/en-us/library/aa394375%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
Here is a correct example:
strCommand = "Notepad.exe" Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") ' ' Configure the Notepad process to show a window Set objStartup = objWMIService.Get("Win32_ProcessStartup") Set objConfig = objStartup.SpawnInstance objConfig.ShowWindow = 1 '' Create Notepad process 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: " & intReturn Else Wscript.Echo "Process created." & vbNewLine & "Command line: " & strCommand & vbNewLine & "Process ID: " & intProcessID End If
\_(ツ)_/
- Edited by jrv Saturday, May 26, 2018 10:02 PM
Saturday, May 26, 2018 10:00 PM