run command on remote pc

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
funnysun
Posts: 15
Joined: Wed Apr 08, 2009 7:16 pm

run command on remote pc

Post by funnysun »

hello guys,

I just have a simple question, here is script i found on scripting Guy (MS site)
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2:Win32_Process")
objWMIService.Create "notepad.exe", null, null, intProcessID

Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")

Set colMonitoredProcesses = objWMIService.ExecNotificationQuery _
("Select * From __InstanceDeletionEvent Within 1 Where TargetInstance ISA 'Win32_Process'")

Do Until i = 1
Set objLatestProcess = colMonitoredProcesses.NextEvent
If objLatestProcess.TargetInstance.ProcessID = intProcessID Then
i = 1
End If
Loop

Wscript.Echo "Notepad has been terminated."
my question is that does this code work while nobody is currently logged on remote machine?i have tested a couple time, the result is random, sometimes it works, sometimes no.eg: i ran "gpupdate /force /boot" command on remotewith user logged on, it worked great and rebooted, but if noboday is looged on, remote does not reboot,(i cant see cmd window since noboday is logged on, so i dont know if it worked) Can anyone please confirm with me if this script works while nobody is logged on remote machine?many thanks

jvierra
Posts: 14550
Joined: Tue May 22, 2007 9:57 am
Contact:

run command on remote pc

Post by jvierra »

I am pretty sure that gpupdate will only run if the console session is logged in or there is an interactive user.

Look to SpecOps for free AD tool that will do this remotely and its free.
http://www.specopssoft.com/products/specopsgpupdate/

Works great and can do a group in a flash.


User avatar
funnysun
Posts: 15
Joined: Wed Apr 08, 2009 7:16 pm

run command on remote pc

Post by funnysun »

thank you guys!
your info is much appreciated, i will try your suggestions

Locked