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

What is the Java equivalent of PHP's $_POST ? After searching the web for
After searching online, the best solution I've found so far is to just make
I've run across an interesting PHP/SOAP error that has me stymied. After searching I
After lots of attempts and search I have never found a satisfactory way to
I'm starting to learn and practice some CoreData, with no programming experience. After searching
I've made an Intraweb ISAPI application. After building the dll, I've created an Web
We've got a WCF service that we're consuming from a web app. The client
After reading the Head First Design Patterns book and using a number of other
After the suggestion to use a library for my ajax needs I am going
After reading this question , I was reminded of when I was taught Java

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.