ServiceStart Method

Starts a named service.

Syntax

bSuccess = IShellDispatch2.ServiceStart(sServiceName, vPersistent)

Parameters

sServiceName Required. A String that contains the name of the service.
vPersistent Required. A Variant value that is set to true to have the service started automatically by the service control manager during system startup. To leave the service configuration unchanged, set vPersistent to false.

Return Value

Variant. Returns true if successful, or false otherwise.

Remarks

The method returns false if the service has already been started. Before calling this method, you can call IsServiceRunning to ascertain the status of the service.

This method is not currently available in Microsoft Visual Basic.

Examples

The following example uses ServiceStart to start the Messenger service. Proper usage is shown for Microsoft JScript and Visual Basic Scripting Edition (VBScript).

JScript:

<script language="JScript">
    function fnServiceStartJ()
    {
        var objShell = new ActiveXObject("Shell.Application");
        var bReturn;
        
        bReturn = objShell.ServiceStart("Messenger", true);
    }
</script>

VBScript:

<script language="VBScript">
    function fnServiceStartVB()
        dim objShell
        dim bReturn

        set objShell = CreateObject("Shell.Application")

        bReturn = objShell.ServiceStart("Messenger", true)

        set objShell = nothing
    end function
</script>

Applies To

IShellDispatch2
Tags :


Community Content

Thomas Lee
Driver Services?
Does this function work with "driver services"?

I couldn't make it work with the smb service in Windows Vista.

[tfl - 25 09 09] Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1
SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
Windows : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.windows%2C&
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&


Page view tracker