armyman Posted March 10, 2011 Posted March 10, 2011 Hello all, I'm trying to write a program that can disable one service and enable another service. However if I try to run the two functions as shown in the code only the first service is disabled and the second service is not enabled. But if I run them seperately the code works. Not sure why I can't do them together. Thanks! _GetService("Windows Firewall/Internet Connection Sharing (ICS)", "Disabled") _GetService("Windows Firewall/Internet Connection Sharing (ICS)", "Automatic") Func _GetService($service, $State) Dim $objWMIService, $colServiceList, $objService, $errReturnCode Dim $strComputer $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colServiceList = $objWMIService.ExecQuery _ ("Select * from Win32_Service where Name = '" & $service & "'") If $State = "Disabled" then For $objService In $colServiceList If $objService.State = "Running" Then $objService.StopService() Sleep(5000) EndIf $objService.ChangeStartMode($State) Next Else For $objService In $colServiceList $objService.ChangeStartMode($State) $objService.StartService() Sleep(5000) Next EndIf EndFunc
Xenobiologist Posted March 10, 2011 Posted March 10, 2011 (edited) There are a lot of funtions dealing with services. Have you tried them. What happens when you do it manually via cmd net start/stop Edited March 10, 2011 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
tiggerah Posted May 10, 2011 Posted May 10, 2011 Try changing these lines: _GetService("Windows Firewall/Internet Connection Sharing (ICS)", "Disabled") _GetService("Windows Firewall/Internet Connection Sharing (ICS)", "Automatic") To these lines: _GetService("SharedAccess", "Disabled") _GetService("SharedAccess", "Automatic") Reason: The code is referencing the Display name when it should be referencing the Service name.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now