I finally found a way to start and stop a service silently without showing the console window, and UAC displayed for a Microsoft signed program (wscript.exe), with VBScript that uses WMI to start and stop a service.
Start a service:
Create a file StartService.vbs with this code and change the first line with the service you want to start.
strServiceName = "YourServiceName"
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1
WScript.Quit
End If
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next
to start the service:
wscript pathto\StartService.vbs
Stop a service:
Create a file StopService.vbs with the code:
strServiceName = "YourServiceName"
If Not WScript.Arguments.Named.Exists("elevate") Then
CreateObject("Shell.Application").ShellExecute WScript.FullName _
, """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1
WScript.Quit
End If
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next
to stop the service:
wscript pathto\StopService.vbs
Any time you elevate a command, the UAC will be displayed. The UAC is being displayed for
nircmd
so it can runnet start
with the proper elevated privileges (which are required by Windows). – Anaksunaman – 2018-06-30T02:09:56.157if you read my question you'll see that what I want is that the UAC being asked for the net.exe program, not another program like nircmd, and after that I want the console window to be hidden. – liamZ – 2018-06-30T18:15:17.993