Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1060205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:17:31+00:00 2026-05-16T18:17:31+00:00

After searching the web for information, I have managed to create a service which,

  • 0

After searching the web for information, I have managed to create a service which, depending on the command line, can install or uninstall itself, or just run as an application.

However, the uninstalling code isn’t working correctly.

The related code:

Private Function UnInstallService(ByVal args As String(), ByRef errMsg As String) As Boolean
    Dim si As New ServiceInfo

    If (Not GetServiceInfo(args, si)) Then
        errMsg = "Error..."
        Return False
    End If

    If (Not IsServiceInstalled(si.Name)) Then
        errMsg = "Error..."
        Return False
    End If

    Try
        Dim installer As ServiceProcessInstaller = GetServiceInstaller(si)
        Dim stateSaver As IDictionary = New Hashtable
        Try
            installer.Uninstall(stateSaver)
        Catch e As exception
            errMsg = "Error..."
            Return False
        End Try
    Catch e As exception
        errMsg = "Error..."
        Return False
    End Try
End Function

Private Function GetServiceInstaller(ByVal si As ServiceInfo) As ServiceProcessInstaller
    Dim installer As ServiceInstaller = New ServiceInstaller()
    Dim pInstaller As New ServiceProcessInstaller
    pInstaller.Context = New InstallContext("", si.CommandLine)

    installer.Description = si.Description
    installer.DisplayName = si.DisplayName
    installer.ServiceName = si.Name
    installer.StartType = ServiceStartMode.Automatic

    If (si.Account = "LocalSystem") Then
        pInstaller.Account = ServiceAccount.LocalSystem
    ElseIf (si.Account = "LocalService") Then
        pInstaller.Account = ServiceAccount.LocalService
    ElseIf (si.Account = "NetworkService") Then
        pInstaller.Account = ServiceAccount.NetworkService
    Else
        pInstaller.Account = ServiceAccount.User
        pInstaller.Password = si.Password
        pInstaller.Username = si.Account
    End If

    pInstaller.Context.Parameters("assemblypath") = si.FullPath

    pInstaller.Installers.Add(installer)
    installer.Parent = pInstaller

    Return pInstaller
End Function

It throws a NullReferenceException in the call to installer.Uninstall
The code for installation is exactly the same, except for checking if the service is installed, and calling installer.Install and then installer.Commit instead of Uninstall. I’m passing it exactly the same parameters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:17:31+00:00Added an answer on May 16, 2026 at 6:17 pm

    I have found the problem here:
    http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/58505d7b-cb78-4486-88fc-9b86890664e0

    The problem lies in the line

    installer.Uninstall(stateSaver)
    

    which, instead, should have been

    installer.Uninstall(Nothing)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After searching the web for hours you are my last hope: I have to
I have never really thought about this until today, but after searching the web
After days of searching the web (Including MSDN) for a way to get Hardware
After searching through some existing libraries for JSON, I have finally ended up with
After searching the other questions none have answered the specific issue I have. We
I have been attemptng to create a DLL with C/C++ that can be accessed
Based on some standard web searching, I have narrowed down my problem to this:
I don't why, but after 6h of searching the bug, I can't identify it.
I am trying to understand how classpath really works. After searching around the web
After trying many and searching web option to compile and load dll I could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.