regisp Posted November 14, 2005 Share Posted November 14, 2005 hello the world. just this silly question asked in the title. i'm checking the status of a service with wmi and need to start it if disabled. if change it's state in the registry from 4 to 2 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\wuauserv and need to manualy start it. i receive an error message when i try to do a "net start" command. if i do it via the managemnt console all is fine. is there another key to change to be able to do a "net start" or another prg to run to change the status of the service from "disable" to "auto" or "manual". thx for your answers Link to comment Share on other sites More sharing options...
GaryFrost Posted November 14, 2005 Share Posted November 14, 2005 You might want to look at the code in my Admin Tool (see signature), it has those option in it. Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
regisp Posted November 14, 2005 Author Share Posted November 14, 2005 ok, i've just looked at your code (very impressive), i think i'll lose a lot of time to understand the function. so if someone have something already done and small. i'll be pleased. Link to comment Share on other sites More sharing options...
GaryFrost Posted November 14, 2005 Share Posted November 14, 2005 (edited) expandcollapse popup_SetServiceState(@ComputerName, "Norton AntiVirus Auto Protect Service", "Start") Func _SetServiceState($s_pcname, $s_servicename, $State) Local $colItems = "", $even = 1, $objItem, $ret_status = -1, $s_pc Local $a_status[25] = ["Success", "Not supported", "Access denied", "Dependent services running", _ "Invalid service control", "Service cannot accept control", "Service not active", "Service request timeout", _ "Unknown failure", "Path not found", "Service already stopped", "Service database locked", "Service dependency deleted", _ "Service dependency failure", "Service disabled", "Service logon failed", "Service marked for deletion", "Service no thread", _ "Status circular dependency", "Status duplicate name", "Status - invalid name", "Status - invalid parameter", _ "Status - invalid service account", "Status - service exists", "Service already paused"] If ($s_pcname <> $LV_ERR) Then If Ping($s_pcname) Then Local $objWMIService = ObjGet("winmgmts:\\" & $s_pcname & "\root\CIMV2") If @error Then MsgBox(16, "_SetServiceState", "ObjGet Error: winmgmts") Return EndIf $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If @error Then MsgBox(16, "_SetServiceState", "ExecQuery Error: SELECT * FROM Win32_Service") Return EndIf If IsObj($colItems) Then For $objItem In $colItems If $objItem.Name = $service Then Select Case $State = "Boot" Or $State = "System" Or $State = "Automatic" Or $State = "Manual" Or $State = "Disabled" $ret_status = $objItem.ChangeStartMode ($State) Case $State = "Stop" $ret_status = $objItem.StopService () Case $State = "Start" $ret_status = $objItem.StartService () Case $State = "Pause" $ret_status = $objItem.PauseService () Case $State = "Resume" $ret_status = $objItem.ResumeService () Case $State = "Delete" $ret_status = $objItem.Delete () EndSelect ExitLoop EndIf Next EndIf EndIf EndIf EndFunc ;==>_SetServiceState Edited November 14, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
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