Page 1 of 2 12>
Topic Options
#86306 - 2002-06-26 03:34 PM remote execution
Radimus Moderator Offline
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

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86307 - 2002-06-26 03:36 PM Re: remote execution
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
rad, you are MAD!
_________________________
!

download KiXnet

Top
#86308 - 2002-06-26 06:49 PM Re: remote execution
krabourn Offline
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 Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
anyone know what those addl parameters in the create statement are?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#86310 - 2002-06-26 06:59 PM Re: remote execution
Anonymous
Unregistered


Try,
GetOwnerSid Method in Class Win32_Process

See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/getownersid_method_in_class_win32_process.asp

Top
#86311 - 2002-06-26 07:20 PM Re: remote execution
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Rad, addl parameters ? You mean like ProcessStartupInformation ? We were playing with that in that Remote Execution Driving Me Insane thread ... Can create a blank Win32_ProcessStartup object, then datafill with startup parameters, like window attributes, process priority, etc ... then pass to Create, I guess.
Top
#86312 - 2002-06-26 07:57 PM Re: remote execution
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Why is it necessary to specify the PID?...

Brian

Top
#86313 - 2002-06-26 07:59 PM Re: remote execution
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Let me restate what I am looking for.

I am trying to determine what user name and domain the process ($ObjProcessOut) that I just created is running under.

I would assume it is running as the account that I used to log into WMI. That account has administrative rights.

Does anyone know what account the new process is running under?
_________________________
Kelly

Top
#86314 - 2002-06-26 08:04 PM Re: remote execution
BrianTX Offline
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. [Smile]

Brian

Top
#86315 - 2002-06-26 08:07 PM Re: remote execution
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Thanks.

I think, I just need the syntax.

I get a zero back for @Error, but I don't know how to access the user and domain part.
_________________________
Kelly

Top
#86316 - 2002-06-26 08:08 PM Re: remote execution
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
As per that "Remote Execution driving me insane" thread. The remote process "appears" to be running with your WMI credentials (eg, if you look in XP taskmgr on remote machine, your accountid is attached to the process). But, because of some limitations with NTLM challenge response - the process on the remote machine DOES NOT really have full network rights. If you need to access a remote share - have to map it with username & password supplied.

From reading the literature. This is an basic Windows NT problem, and affects not just WMI, but other things such as remote TELNET sessions.

My two cents. Sorry if not much help in furthering the cause. Might want to inverstigate further.

Top
#86317 - 2002-06-26 08:16 PM Re: remote execution
BrianTX Offline
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 Offline
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 Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
This looks vaguely familar - http://cwashington.netreach.net/depo/wmifaq/execution_of_a_remote_command.htm

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#86320 - 2002-06-26 09:24 PM Re: remote execution
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
BrianTX,

Does that VBS code work for you? It does not work for me.
_________________________
Kelly

Top
#86321 - 2002-06-26 09:51 PM Re: remote execution
BrianTX Offline
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 Offline
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 Offline
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
#86324 - 2002-06-27 03:54 PM Re: remote execution
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Yes!!!! [Smile]

Thanks for the help.
_________________________
Kelly

Top
#86325 - 2002-06-27 04:28 PM Re: remote execution
BrianTX Offline
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
Page 1 of 2 12>


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1055 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.089 seconds in which 0.029 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org