Solved

starting services with a script in windows 2000

Posted on 2000-03-21
9
183 Views
Last Modified: 2010-04-12
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...
0
Comment
Question by:mabo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Expert Comment

by:carmine
ID: 2639676
Using VBScript to start the browser service (Uses ADSI):


Const ADS_SERVICE_STOPPED = 0x00000001

'Status                         Constant
'ADS_SERVICE_STOPPED            0x00000001
'ADS_SERVICE_START_PENDING      0x00000002
'ADS_SERVICE_STOP_PENDING       0x00000003
'ADS_SERVICE_RUNNING            0x00000004
'ADS_SERVICE_CONTINUE_PENDING   0x00000005
'ADS_SERVICE_PAUSE_PENDING      0x00000006
'ADS_SERVICE_PAUSED             0x00000007
'ADS_SERVICE_ERROR              0x00000008
'ADS_SERVICE_OWN_PROCESS        0x00000010
'ADS_SERVICE_SHARE_PROCESS      0x00000020
'ADS_SERVICE_KERNEL_DRIVER      0x00000001
'ADS_SERVICE_FILE_SYSTEM_DRIVER 0x00000002
'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_CRITICAL     3

' Start the browser service.
Set oBrowser = GetObject("WinNT://./browser")
If oBrowser.status = ADS_SERVICE_STOPPED Then
    oBrowser.start
End If
Set oBrowser = Nothing

0
 
LVL 6

Expert Comment

by:Lermitte
ID: 2640401
0
 
LVL 5

Expert Comment

by:carmine
ID: 2640489
Or, if you want to do it with WMI (browser example again):

Set System = GetObject("winmgmts:{impersonationlevel=impersonate}!Win32_Service.Name=Browser")

System.StartService


regards
Mark
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 2640777
I'd imagine you could also just use "NET START <service>" where service is the service name found under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
0
 
LVL 5

Expert Comment

by:carmine
ID: 2643627
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
0
 

Author Comment

by:mabo
ID: 2647826
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.....
0
 
LVL 5

Expert Comment

by:carmine
ID: 2648479
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.arguments.Item(iArg)
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

0
 

Author Comment

by:mabo
ID: 2655402
It gives error in line

const ADS_SERVICE_STOPPED = 0x00000001

"expected end of statement"

any suggestions.....
0
 
LVL 5

Accepted Solution

by:
carmine earned 10 total points
ID: 2660056
????

Make sure there are no spurious trailing characters.

Try changing to:

Const ADS_SERVICE_STOPPED = 1

OR

Dim ADS_SERVICE_STOPPED
ADS_SERVICE_STOPPED = 1


I'm puzzled as to why you get that error.

Mark
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question