Hi Scripters!
I pieced together a script from many online examples which takes care of several obstacles that I encounter on my employer's domain when attempting to offer
Unsolicited Remote Assistance, and I'd like to make it a lot prettier. I am interested in displaying a GUI to the technician that has check marks for each of the steps. I have the front-end working fine (a simple window with an input box and 4 checkmarks), but I was disappointed to learn that .vbs code isn't compatible with VB.NET. I'm looking to convert a few of the following functions into valid VB.NET code:
This portion queries the user to enter a computer hostname, and then runs
psexec to add a localgroup called techSupportGroup to the Administrator's group:
' Explain psexec and need for admin password:
prompt=msgBox("The next script attempts to add tech" _
& "SupportGroup to the Administrator group. Please enter the " _
& "administrator password for the target computer when " _
& "prompted. Type exit when complete.",4096,"Admin Password")
'Add "techSupportGroup" to the Administrator's group:
objShell.Run("%COMSPEC% /K psexec \\" & strComputer & " -u " _
& "" & strComputer & "\administrator net localgroup " _
& "administrators ""domainName\techSupportGroup"" /add"),1,TRUE I'm sure there exists a better method to add a name to a localgroup on a remote PC rather than psexec, but I don't know where to look to find the syntax.
Another branch of the code stops a service, performs a command-line execution, then resumes the service:
'***********************************
'* * * restart service * * *
'***********************************
'
'
'* * * ADDED FOR DEBUGGING ONLY * * *
strComputer = "."
'* * * END DEBUGGING * * *
'
' ReStartService.vbs
' Sample script to Stop or Start a Service
' www.computerperformance.co.uk/
' Created by Guy Thomas December 2005 Version 2.4
' -------------------------------------------------------'
' Explain psexec and need for admin password:
prompt=msgBox("The next script attempts to restart the " _
& "sessmgr service. Please enter the administrator " _
& "password for the target computer when " _
& "prompted. Type exit when complete.",4096,"Admin Password")
'Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strService, intSleep 'strComputer
'strComputer = "."
intSleep = 5000
WScript.Echo " Click OK, then wait " _
& intSleep/1000 & " seconds"
'On Error Resume Next
' NB strService is case sensitive.
strService = " 'rdsessmgr' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " ")
For Each objService in colListOfServices
objService.StopService()
WSCript.Sleep intSleep
objShell.Run("%COMSPEC% /K psexec \\" & strComputer & " -u " _
& strComputer & "\administrator %systemroot%\system32\" _
& "sessmgr.exe -service"),1,TRUE
WSCript.Sleep intSleep
objService.StartService()
Next
WScript.Echo "Your "& strService & " service has Started"
'WScript.Quit
' End of Example WMI script to Start / Stop services Again, I am attempting to replace the psexec portion of the code with standard VB.NET functions.
If anyone has some ideas, I'd be grateful to being pointed in the right direction. I'm also eager to share the completed code (after I add some error-checking) in the code forum.
Thanks,
Mike