#86306 - 2002-06-26 03:34 PM
remote execution
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
hahahahahhahahahahahah
got it... No error checking yet, but here is the basics.
code:
rmtexec("notepad.exe","wheelerc_2nd") ? @error @serror
;**************************************************************************************************** FUNCTION RMTEXEC($cmd, $computer, optional $pid) dim $rmt, $exec if not $pid $pid=999 endif
$rmt = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$computer \root\cimv2:Win32_Process") $exec = $rmt.Create($cmd,,,$pid)
exit @error ENDFUNCTION
|
|
Top
|
|
|
|
#86308 - 2002-06-26 06:49 PM
Re: remote execution
|
krabourn
Hey THIS is FUN
   
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
Good Job!
Looks like we started this one about the same time.
This is mine. I have to be able to login to WMI on some workstations.
code:
Function RemoteRun ($RemoteCommand, Optional $RemoteStartDir, Optional $ComputerName, Optional $AdminName, Optional $AdminPassword, Optional $NameSpace) Global $RemoteProcessPid If Not $ComputerName Or $ComputerName = '' $ComputerName = @Wksta EndIf If $NameSpace = '' $NameSpace = 'root\cimv2' EndIf $SystemLocator = CreateObject ('WbemScripting.SWbemLocator') $SystemSet = $SystemLocator.ConnectServer($ComputerName, $NameSpace, $AdminName, $AdminPassword) If @Error <> 0 $WMIQuery = '' Exit @Error EndIf $SystemSet.Security_.ImpersonationLevel = 3 $ObjProcesses = $SystemSet.Get('Win32_Process') $ObjProcessIns = $ObjProcesses.Methods_('Create').InParameters.SpawnInstance_ $ObjProcessIns.CommandLine = $RemoteCommand If $RemoteStartDir And $RemoteStartDir <> '' $ObjProcessIns.CurrentDirectory = $RemoteStartDir EndIf $ObjProcessOut = $SystemSet.ExecMethod('Win32_Process', 'Create', $ObjProcessIns) If @Error = 0 $RemoteProcessPid = $ObjProcessOut.processid Else $RemoteProcessPid = '' EndIf Exit $ObjProcessOut.returnvalue EndFunction
Have you tried finding out who the owner of the process is (GetOwner)? I have not been able to get the use and domain from it. It just returns zero.
Thanks
_________________________
Kelly
|
|
Top
|
|
|
|
#86309 - 2002-06-26 06:51 PM
Re: remote execution
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
anyone know what those addl parameters in the create statement are?
|
|
Top
|
|
|
|
#86310 - 2002-06-26 06:59 PM
Re: remote execution
|
Anonymous
Anonymous
Unregistered
|
|
|
Top
|
|
|
|
#86312 - 2002-06-26 07:57 PM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Why is it necessary to specify the PID?...
Brian
|
|
Top
|
|
|
|
#86314 - 2002-06-26 08:04 PM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
If you like, I'll whip up a script that can check what userid a process is running under.. then you can check it.
Brian
|
|
Top
|
|
|
|
#86317 - 2002-06-26 08:16 PM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I'm getting the same thing.. going to have to fiddle around with this getting userid/domain stuff. For some reason KiXtart doesn't like returning info into variables in a method.
Brian
|
|
Top
|
|
|
|
#86318 - 2002-06-26 08:47 PM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
vbs code:
code:
set wmiobj=GetObject("winmgmts:") set procobj = wmiobj.ExecQuery("Select * From Win32_Process Where Name = 'iexplore.exe'") For each Process in procobj RetVal = Process.GetOwner(struser,strdomain) wscript.echo struser wscript.echo strdomain Next
{fixed.. should work now}
Brian [ 26 June 2002, 21:53: Message edited by: BrianTX ]
|
|
Top
|
|
|
|
#86319 - 2002-06-26 09:00 PM
Re: remote execution
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
|
|
Top
|
|
|
|
#86321 - 2002-06-26 09:51 PM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Let me fix it.. it was working a minute ago.. lol {edit} Ok.. works for me now.. I was fiddling with it and posted the "fiddling" code instead of the code that works.
Brian [ 26 June 2002, 21:54: Message edited by: BrianTX ]
|
|
Top
|
|
|
|
#86322 - 2002-06-26 11:17 PM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
This frustrates me:
Methods cannot set OUTput parameter variables in KiXtart. Has ANYONE gotten this to work? I'm willing to concede I may not have the syntax right, but I have tried several different ways without success.
Brian
|
|
Top
|
|
|
|
#86323 - 2002-06-27 12:00 AM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I think we can safely say (unless someone has proof to the contrary) that KiXtart does not support OUT parameters for object methods.. is this something I should add to the suggestion box, or is this a bug?
Brian
|
|
Top
|
|
|
|
#86325 - 2002-06-27 04:28 PM
Re: remote execution
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Ok.. I've been fiddling with this.. gotten some more progress.. anyone care to try this?
code:
$computer = "@WKSTA" $uName = "" $upass = "" $namespace = "root\cimv2" $command = "c:\winnt\system32\cmd.exe" $sysloc = CreateObject("WbemScripting.SWbemLocator") $sysset = $sysloc.ConnectServer($computer, $namespace, $uname, $upass) $sysset.Security_.ImpersonationLevel = 3
$objProcStart = $sysset.Get("Win32_ProcessStartup") $ProcStartInst = $objProcStart.SpawnInstance_ $ProcStartInst.Title = "Hi, How are you?" $ProcStartInst.ShowWindow = 1 ; this part doesn't seem to work right. $procStartInst.Put_
$objProc = $sysset.Get("Win32_Process") $objProcInst = $ObjProc.Methods_("Create").InParameters.SpawnInstance_ $objProcInst.CommandLine = $command $objProcInst.ProcessStartupInformation = $ProcStartInst $objProcOut = $sysset.ExecMethod("Win32_Process","Create",$objProcInst) $pid = $objProcOut.Processid "PID used is: " + $pid
Brian
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 1055 anonymous users online.
|
|
|