VB Script needed to alter local server services

Posted on 2008-11-15
Last Modified: 2012-05-05
I have a couple of servers, that whenever they reboot critical services fail to start.  I have to log into the server and change the password on the local service accounts.  I then am able to start the services just fine.

I really need a VB Script that can automate this for me.  I need it to be able to assign user name and password for the service locally, then I need it to start the service.

I spent 4 hours on the phone with Symantec and they were no help.  I also have a SQL server that is doing the same thing on a remote network in a different domain and context altogether.

Any help would be great!
Question by:bbanis2k
    LVL 4

    Accepted Solution

    instead of using VB just use a batch file and the SC command

    SC config to set password
    (sc <server> config [service name] <option1> <option2>)

    sc start and stop
    (sc <server> start [service name] <arg1> <arg2>)

    go to a command prompt and type SC /? or SC Config /?.

    If you are dead set on VBS then just start the command prompt and stream the commands into the command window.

    Author Comment

    I will try that...
    LVL 6

    Expert Comment

    Here a a VBScript that does what you need
    strComputer = "computername"
    strService = ".\servicename"
    strPassword = "password"
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service")
    For Each objservice in colServiceList
        If objService.Startname = strService Then
            errReturn = objService.Change( , , , , , , ,strPassword)
            errReturn = objService.StartService()
        End If 

    Open in new window


    Author Closing Comment

    This worked pefectly fine!  Thank you

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
    Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now