|
|
|
| 16 December 2002 | RemoteCommand() |
| Author | Radimus |
| Action | Execute a command, local to that PC, using the system account. |
| Syntax | RemoteCommand ("computer","command") |
| Parameters | |
| Remarks | This uses the local system account, and interacts with the user's desktop. As such, it CANNOT access network resources. I'm writing another function to push a folder to the remote PCs temp folder, for the purposes on installing apps remotely. I wouldn't suggest deploying MS Office like this. |
| Returns | @error |
| Dependencies | Kix 4, Rcmd service from reskit, WMI, xnet from Kix distro |
| Examples |
$command= 'c:\temp\$folder\$executable'
RemoteCommand($computer, $command)
RemoteCommand("computer","format c:")
|
| Source |
FUNCTION RemoteCommand ($computer, $command)
DIM $tools, $tempcommand, $loop, $char, $objwmiservice, $colsettings, $remotewindir
$tools="\\Server\tools"
IF NOT $command = ''
$tempcmd=''
FOR $loop=1 TO Len($command)
$char=Substr($command,$loop,1)
IF ($char = '"')
$tempcmd=$tempcmd + '"' + '"'
ENDIF
$tempcmd=$tempcmd + $char
NEXT
$command = $tempcmd
USE "\\$computer\ipc$$"
$objwmiservice = GetObject("winmgmts:{impersonationLevel=impersonate}!\\$computer\root\cimv2")
$colsettings = $objwmiservice.execquery("Select * from Win32_OperatingSystem")
FOR EACH $objoperatingsystem IN $colsettings
$remotewindir = $objoperatingsystem.windowsdirectory
NEXT
SHELL '%comspec% /c $tools\xnet list $computer | find /i "rcmdsvc" > nul'
IF @error = 0
SHELL '%comspec% /c $tools\xnet stop \\$computer\rcmdsvc > nul'
SHELL '%comspec% /c $tools\xnet remove \\$computer\rcmdsvc /y > nul'
ENDIF
COPY "$tools\rcmd*.exe" "\\$computer\admin$$\system32"
IF @error <> 0
EXIT(@error)
ENDIF
SHELL '%comspec% /c $tools\xnet install \\$computer\rcmdsvc /b:$RemoteWinDir\system32\rcmdsvc.exe /n:"Remote Command Service" /u:localsystem /i:y /s:auto > nul'
SHELL '%comspec% /c $tools\xnet start \\$computer\rcmdsvc > nul'
SHELL '%comspec% /c $tools\rcmd.exe \\$computer "$command"'
SHELL '%comspec% /c $tools\xnet stop \\$computer\rcmdsvc > nul'
SHELL '%comspec% /c $tools\xnet remove \\$computer\rcmdsvc /y > nul'
DEL "\\$computer\admin$$\system32\rcmd*.exe"
USE "$computer\ipc$$" /delete
$colsettings = 0
$objwmiservice = 0
ENDIF
ENDFUNCTION ; - RemoteCommand -
|
|
|
|