Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

WMI Win32_Process class (run proces on remote computer)



  • Please log in to reply
3 replies to this topic
Proxx
  • Members
  • 9 posts
  • Last active: Mar 17 2013 12:22 PM
  • Joined: 23 Mar 2011

Hi All,

 

i'm having trouble to get a function working.

with a vbscript i am able to run notepad.exe on a different pc:

strComputer = "computername"
strCommand = "notepad.exe"

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")

errReturn = objProcess.Create(strCommand, null, null, intProcessID)

 

this is working well but now i am trying to do the same with Autohotkey

 

strComputer := "computername"
strCommand := "notepad.exe"

objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
objProcess := objWMIService.Get("Win32_Process")

errReturn := objProcess.Create("" . strCommand . ", Null, Null, intProcessID")
msgbox %errReturn%

 

this wil alway return error 9 (Path Not Found)

 

its not even working with the full path or with a working directory. im clearly missing something. but cant figure out what!

 



uname
  • Members
  • 194 posts
  • Last active: Oct 17 2015 08:46 AM
  • Joined: 13 Jun 2012
✓  Best Answer
strComputer := "computername"
strCommand := "notepad.exe"
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
objProcess := objWMIService.Get("Win32_Process")
errReturn := objProcess.Create(strCommand) 

if processID is required :

strComputer := "computername"
strCommand := "notepad.exe"

objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
objProcess := objWMIService.Get("Win32_Process")

Null := ComObjMissing()
VarSetCapacity(processID, 4, 0)
processIDRef := ComObjParameter(0x4|0x4000, &processID)

errReturn := objProcess.Create(strCommand, Null, Null, processIDRef)
msgbox % errReturn . "`n" . NumGet(processID)


Proxx
  • Members
  • 9 posts
  • Last active: Mar 17 2013 12:22 PM
  • Joined: 23 Mar 2011

Whohooo my hero,

 

i knew i was missing something stupid. thanks bro :D



Proxx
  • Members
  • 9 posts
  • Last active: Mar 17 2013 12:22 PM
  • Joined: 23 Mar 2011

an other question i'm pretty sure is possible

i have a function that can start stop en view the state of a remote service

Now i have tried to manipulate the result := objProcess.state, [ startService ] [ stopService ]

so when you call the function:

 

srvCtrl(computername,servicename,stopService)

 

It will be: result := objProcess.stopService

 

Only i cannot figure out how to use a variable on that location

 

srvCtrl(strComputer,strService,srvCMD) {
        objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
	objProcess := objWMIService.Get("Win32_Service.Name='" . strService . "'")
	result := objProcess.%srvCMD%
        return %result%
}

Now i have created a Workaround by using a if/else but im pretty sure that is not necessarily.

srvCtrl(strComputer,strService,srvCMD) {
	objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
	objProcess := objWMIService.Get("Win32_Service.Name='" . strService . "'")
	if srvCMD = state
	{
		result := objProcess.state
		return %result%
	}
	else if srvCMD = start 
	{
		result := objProcess.startService
		return %result%
	}
	else if srvCMD = stop
	{
		result := objProcess.stopService
		return %result%
	}
}

 

Thanks in advance