Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
startservice (advapi32)
The StartService function starts a service.

C# Signature:

[DllImport("advapi32", SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool StartService(
                IntPtr        hService,
            int        dwNumServiceArgs,
            string[]        lpServiceArgVectors

VB .NET Signature:

Declare Function StartService Lib "advapi32.dll" Alias "StartServiceA" (ByVal hService As IntPtr, ByVal dwNumServiceArgs As Long, ByVal lpServiceArgVectors As String) As Boolean

User-Defined Types:




Tips & Tricks:

Please add some!

C# Sample Code:

// Now, start the service on the remote machine

Win32.StartService( hService, 0, null ) ;

VB .NET Sample Code:

' Start Service
' When this button is clicked it will attempt to start a service called Service_Name with SERVICE_ALL_ACCESS privelages
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    Dim hSCManager As IntPtr = New IntPtr(OpenSCManager(Nothing, Nothing, SCMAccess.SC_MANAGER_ALL_ACCESS))
    If (hSCManager.ToInt32 = 0) Then
        MsgBox("The service control manager could not be opened!", MsgBoxStyle.Critical)
        Exit Sub
    End If

    Dim scManager As IntPtr = OpenService(hSCManager, "Service_Name", SCAccess.SERVICE_ALL_ACCESS)
    If (scManager.ToInt32 = 0) Then
        MsgBox("The service could not be opened!", MsgBoxStyle.Critical)
        Exit Sub
    End If

    Dim ret As Boolean = StartService(scManager, 0, Nothing)
    If (Not ret) Then
        MsgBox("The service could not be started!", MsgBoxStyle.Critical)
    End If


End Sub

Alternative Managed API:

Do you know one? Please contribute it!


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version