Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Remote Execution of Code

2 views
Skip to first unread message

pin...@gmail.com

unread,
Dec 29, 2005, 10:44:06 AM12/29/05
to
I'm in a Windows AD environment that isn't very conducive to running
startup scripts to achieve my goal. What I am trying to do is copy a
vbs script to a remote client machine, and then execute that script on
that machine using my credentials. The script itself, when manually
run on a client works perfectly. What I can't get to work is the
remote execution of the script. I can start a process for notepad.exe
and calc.exe, but I cannot start the script itself. Any ideas?

joe.e...@gmail.com

unread,
Jan 22, 2006, 5:27:17 AM1/22/06
to
You might want to look into the PSEXEC.exe tool that comes as part of
the PSTools pack on www.sysinternals.com.
SECURITY NOTE:
If you use the /p: command line switch with PSEXEC.exe to specify a
password then bear in mind that this password is transmitted in clear
text and not encrypted. If you need to specify alternate credentials
with PSEXEC at run time then try running it as a scheduled task.

If 3rd party tools is not an option then you could use WMI.
See the fRunRemoteCMD() function below:

'<------ START VBSCRIPT CODE --->

Call fRunRemoteCMD("notepad.exe", "192.168.1.2")

'******************************************************************************
'* Name: fRunRemoteCMD(ByVal strCmd, ByVal strComputer)
'* Description: Uses WMI to create a process to execute
' strCmd on strComputer
'******************************************************************************

Function fRunRemoteCMD(strCmd,strComputer)
Dim objWMI
Dim errReturn
Dim intProcessID

If Len(strCmd) > 0 and Len(strComputer)> 0 Then
Err.Clear
On Error Resume Next
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}" _
& "!\\" & strComputer & "\root\cimv2:Win32_Process")


If Err.Number <> 0 Then
'Couldn't connect to WMI on remote machine
Wscript.Echo Err.Number & Err.Description
Exit Function
End If

On Error GoTo 0

Wscript.Echo UCase(strcomputer) & ":"
WScript.Echo vbTab & "Running CMD: " & strCmd
errReturn = objWMI.Create(strCmd, null, null, intProcessID)

If errReturn = 0 Then
Wscript.Echo vbTab & strCmd _
& " was started with a process ID of " & intProcessID
Else
Wscript.Echo vbTab & strCmd _
& " could not be started due to error " & errReturn
End If
Set objWMI = Nothing
End If
End Function


'<------ END VBSCRIPT CODE ---->

chris...@gmail.com

unread,
Feb 7, 2006, 3:55:06 PM2/7/06
to
And if you use WMI then you won't be able to use network resources from
the script on the remote machine for security reasons.

chris...@gmail.com

unread,
Feb 7, 2006, 3:57:57 PM2/7/06
to
I forgot to also mention that there is a registry setting that needs to
be enabled on the remote machine to allow scripts to run via WMI.

0 new messages