• 0

Remotely Execute Command


Question

Im looking to remotely execute a command c:\program files\novell\zenworks\zwsreg.exe -unreg but cant seem to get it to work. Any help would be appreciated. What im doing is remotely renaming the machine and need to unregister it from a novel container at the same time before i do the reboot, here is what i have below.

sOld=wscript.arguments.named("old")
sNew=wscript.arguments.named("new")
if sOld="" or sNew="" then
  wscript.echo "/old:oldname /new:newname"
end if
sDomainUser = "user"
sDomainPasswd ="password"
sAdminUser=sOld & "\user"
sAdminPassword= "password"

set oWMILocator = CreateObject("WbemScripting.SWbemLocator")
oWMILocator.Security_.AuthenticationLevel = 6
set oWMIComputer = oWMILocator.ConnectServer(sOld, "root\cimv2",sOld & sAdminUser,sAdminPassword)
set oWMIComputerSystem = oWMIComputer.Get("Win32_ComputerSystem.Name='" & sOld & "'")

rc = oWMIComputerSystem.Rename(sNew,sDomainPasswd,sDomainUser)
if rc <> 0 then
 WScript.Echo "Rename failed with error: " & rc
else
 WScript.Echo "Successfully renamed " & sOld & " to " & sNew
 wscript.echo "Now rebooting"
 rebootMachine sOld
end if

[b]strComputer = sOld
strCommand = "C:\Program Files\Novell\ZENworks\zwsreg.exe -unreg"
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objProcess = objWMIService.Get("Win32_Process")
errReturn = objProcess.Create(strCommand, null, null, intProcessID)[/b]

Sub RebootMachine(scompName)
	Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Security,Shutdown)}!\\" & scompName & "\root\cimv2")
	Set OS_Set = oWMI.Get("Win32_OperatingSystem")
	For Each os in OS_Set.Instances_()
	  '*** Force Reboot ***
	  ret = os.Win32Shutdown(6)
	Next
End Sub

updated, i figured it out, the answer is in bold.

Edited by Got3n
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

a sneaky psexec \\pcname c:\program files\novell\zenworks\zwsreg.exe -unreg no good to you i guess :p

ok I'm way off the mark there lol, you need real code help not my 2bit psexec

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.