Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

lgtshadow (TechnicalUser) (OP)
30 Mar 05 0:05
Is it possible to start and stop window's services using a script? (or command line/dos command)
Currently I have a large batch file that is set to run every night and it's now become necessary to stop/start the database service so that I can minuplate the database files without them getting messed up/potentaly accessed.
5jgibbs (IS/IT--Management)
30 Mar 05 0:39
well.. i can do any programing what so ever.. but a google gave me this..

tell me if this helps

http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/services/
mrdenny (Programmer)
30 Mar 05 2:16
You can start and stop services using the net stop and net start command via a batch file.

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible.  All it takes is a little research. (Me)


http://www.mrdenny.com (My very old site)

markdmac (MIS)
30 Mar 05 8:49
yes, this can be done using a script with WMI.

There is an example that I wrote to stop and start the spooler service.

CODE

'==========================================================================
'
' NAME: StopStartSpooler.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: http://www.thespidersparlor.com
' DATE  : 10/18/2004
'
' COMMENT: <comment>
'
'==========================================================================

On Error Resume Next

'start with getting the local computer name
strComputer = "."

'now stop the services
Set objWMI = getobject("winmgmts://" & strComputer)
StopService ("Spooler")
WScript.Sleep 3000
StartService ("Spooler")

'sub to stop the services
Sub StopService (ServiceName)
         queryString = "select state from win32_service " _
               & "where displayname='"& ServiceName & "'"
         set results = objWMI.execquery(queryString)
         for each service in results
            if service.state = "Running" then
             service.stopService
            end if
          next
End Sub

'sub to start the services
Sub StartService (ServiceName)
         queryString = "select state from win32_service " _
               & "where displayname='"& ServiceName & "'"
         set results = objWMI.execquery(queryString)
         for each service in results
            if service.state <> "Running" then
             service.startService
            end if
          next
End Sub

I hope you find this post helpful.  Please let me know if it was.

Regards,

Mark

ascotta (Vendor)
30 Mar 05 8:54
Markdmac As added kwezzie here, where can I get tutorials on WMI scripting etc, need to learn some stuff ? I need to upgrade my cat skinners badge

Arguably the best cat skinner around !

Cheers
Scott

markdmac (MIS)
30 Mar 05 9:15
best place to start is at http://www.microsoft.com/scripting.

You can also pick up a lot at http://www.W3Schools.com.

Best advice if you understand the basics of scripting (if you can follow my example above) is to get a copy of Microsoft's free SCRIPTOMATIC tool that will give you sample code.  Often requires a lot of editing becuase it gives you TOO MUCH information, but it is a great place to start.

MS Free Tools I recommend:
ScriptOmatic
ADSI ScriptOmatic
TweakOmatic

Make sure you read all of the docs on these as they are hysterical.  The scripting team at Microsoft have really great senses of humor.  To paraphrase from the TweakOmatic "We thought about making a admOmatic (for custom GPO templates) but the Group Policy Team is really mean and we didn't want to make them mad."

I hope you find this post helpful.  Please let me know if it was.

Regards,

Mark

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close