mabo
asked on
starting services with a script in windows 2000
I want to start a few services in windows 2000...with windows script..if possible....let's call the service name X...can someone suggest a sample code...
thanks...
thanks...
Or, if you want to do it with WMI (browser example again):
Set System = GetObject("winmgmts:{imper sonationle vel=impers onate}!Win 32_Service .Name=Brow ser")
System.StartService
regards
Mark
Set System = GetObject("winmgmts:{imper
System.StartService
regards
Mark
I'd imagine you could also just use "NET START <service>" where service is the service name found under HKEY_LOCAL_MACHINE\SYSTEM\ CurrentCon trolSet\Se rvices
leew, yeah, I'd suggest good 'ole batch for NT4, but as we're in the brave new world of W2K, lets make the most of the scripting features now available to us. Once you've learn't (even some of it) it's much more powerful.
Mark
Mark
ASKER
hmmm....
I am actually trying to start/stop Oracle DBMS services in win2k environment...I don't want to go to services....and click click.......
let's say Oracle services are called X and Y ...so if I pass these two parameter to a windows script then it would be good if I start/stop Oracle.....
any comments.....
I am actually trying to start/stop Oracle DBMS services in win2k environment...I don't want to go to services....and click click.......
let's say Oracle services are called X and Y ...so if I pass these two parameter to a windows script then it would be good if I start/stop Oracle.....
any comments.....
Create a script called "ToggleService.vbs" as below:
'Toggle service(s) (passed as params) state between stop/started
Const ADS_SERVICE_STOPPED = 0x00000001
If Wscript.Arguments.Count > 0 Then
Do While iArg <= Wscript.arguments.Count - 1
Call ToggleServ(Wscript.argumen ts.Item(iA rg)
Loop
Sub ToggleServ(ByVal Name)
Set oService = GetObject("WinNT://./")
If oService.Status = ADS_SERVICE_STOPPED Then
oService.Start
Else
oService.Stop
End If
Set oService = Nothing
End Sub
Then invoke the script from a cmd line with:
cscript ToggleService.vbs ServiceX ServiceY
Or create a shortcut to do this for you.
Or change the script to either just start, and have another that just stops the services you specify.
Mark
'Toggle service(s) (passed as params) state between stop/started
Const ADS_SERVICE_STOPPED = 0x00000001
If Wscript.Arguments.Count > 0 Then
Do While iArg <= Wscript.arguments.Count - 1
Call ToggleServ(Wscript.argumen
Loop
Sub ToggleServ(ByVal Name)
Set oService = GetObject("WinNT://./")
If oService.Status = ADS_SERVICE_STOPPED Then
oService.Start
Else
oService.Stop
End If
Set oService = Nothing
End Sub
Then invoke the script from a cmd line with:
cscript ToggleService.vbs ServiceX ServiceY
Or create a shortcut to do this for you.
Or change the script to either just start, and have another that just stops the services you specify.
Mark
ASKER
It gives error in line
const ADS_SERVICE_STOPPED = 0x00000001
"expected end of statement"
any suggestions.....
const ADS_SERVICE_STOPPED = 0x00000001
"expected end of statement"
any suggestions.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Const ADS_SERVICE_STOPPED = 0x00000001
'Status Constant
'ADS_SERVICE_STOPPED 0x00000001
'ADS_SERVICE_START_PENDING
'ADS_SERVICE_STOP_PENDING 0x00000003
'ADS_SERVICE_RUNNING 0x00000004
'ADS_SERVICE_CONTINUE_PEND
'ADS_SERVICE_PAUSE_PENDING
'ADS_SERVICE_PAUSED 0x00000007
'ADS_SERVICE_ERROR 0x00000008
'ADS_SERVICE_OWN_PROCESS 0x00000010
'ADS_SERVICE_SHARE_PROCESS
'ADS_SERVICE_KERNEL_DRIVER
'ADS_SERVICE_FILE_SYSTEM_D
'ADS_SERVICE_BOOT_START SERVICE_BOOT_START
'ADS_SERVICE_SYSTEM_START SERVICE_SYSTEM_START
'ADS_SERVICE_AUTO_START SERVICE_AUTO_START
'ADS_SERVICE_DEMAND_START SERVICE_DEMAND_START
'ADS_SERVICE_DISABLED SERVICE_DISABLED
'ADS_SERVICE_ERROR_IGNORE 0
'ADS_SERVICE_ERROR_NORMAL 1
'ADS_SERVICE_ERROR_SEVERE 2
'ADS_SERVICE_ERROR_CRITICA
' Start the browser service.
Set oBrowser = GetObject("WinNT://./brows
If oBrowser.status = ADS_SERVICE_STOPPED Then
oBrowser.start
End If
Set oBrowser = Nothing