Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Installing services programmically

Installing services programmically

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpwindows-admin
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alsvha
    wrote on last edited by
    #1

    Hiya all. I use advapi32.dll via VB.net to install a service, however I do not seem to think it goes as well as I'd like. Often when I run the install, everything seems to indicate that it succeedes, but I can't find the service in neither my service list nor registry - although if I use the ServiceController class, I can get a status out on the service. Similar when I attempt to start or stop the service, the code seems to run fine, but .... alas no service work seems to be done. Lastly - I am having problems, again similar, with uninstalling - and about 50/50 I either can or can not uninstall (meaning the code runs through fine or not), yet because I can not see my service in the list when installed - I have no visible proof it is uninstalled other then the ServiceController class crashes if I try to get status. This is the code I am using (VB.NET ... sorry, my company uses that instead of C# :) ) Private Declare Auto Function OpenSCManager Lib "advapi32.dll" (ByVal strMachineName As String, ByVal strServiceControllerDB As String, ByVal intServiceController As Integer) As IntPtr Private Declare Auto Function CreateService Lib "advapi32.dll" (ByVal SCHANDLE As IntPtr, ByVal strServiceName As String, ByVal strDisplayName As String, _ ByVal intDesiredAccess As Integer, ByVal intServiceType As Integer, ByVal intStartType As Integer, ByVal intErrorControl As Integer, ByVal strServicePath As String, _ ByVal strLoadOrderGroup As String, ByVal intTagId As Integer, ByVal strDependencies As String, ByVal strServiceStartName As String, ByVal strPassword As String) As IntPtr Private Declare Auto Sub CloseServiceHandle Lib "advapi32.dll" (ByVal SCHANDLE As IntPtr) Private Declare Auto Function StartService Lib "advapi32.dll" (ByVal SVHANDLE As IntPtr, ByVal intNumServiceArgs As Integer, ByVal strServiceArgVectors As String) As Integer Private Declare Auto Function OpenService Lib "advapi32.dll" (ByVal SCHANDLE As IntPtr, ByVal strServiceName As String, ByVal intNumServiceArgs As Integer) As IntPtr Private Declare Auto Function DeleteService Lib "advapi32.dll" (ByVal SVHANDLE As IntPtr) As Integer Private Declare Auto Function GetLastError Lib "advapi32.dll" () As Integer Private Declare Function ControlService Lib "advapi32.dll" (ByVal SVHANDLE As IntPtr, ByVal intControl As Integer, ByVal objServiceStatus As SERVICE_STATUS) As Integer Friend Function InstallService(ByVal strServicePath As String, ByVal strServiceName As String, ByVal strServiceDisplayName As String) As Boolean

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups