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 8694397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:46:43+00:00 2026-06-13T00:46:43+00:00

I implemented a web page (ASP .NET, VB) to start/stop a Windows service. I

  • 0

I implemented a web page (ASP .NET, VB) to start/stop a Windows service.

I used impersonification, as described here: http://support.microsoft.com/kb/306158

Everything it’s ok when the page reads the service’s status:

_domain = Me.TextBoxDomain.Text
_user = Me.TextBoxUserName.Text
_password = Me.TextBoxPassword.Text
_s = New ServiceController(Constant.ServiceName)
If impersonateValidUser(_user, _domain, _password) Then
    Me.LabelServerStatusValue.Text = _s.Status.ToString    
    undoImpersonation()
Else
    'Error
End If

The problem occurs when the page tries to start (or stop) the service:

_domain = Me.TextBoxDomain.Text
_user = Me.TextBoxUserName.Text
_password = Me.TextBoxPassword.Text
_s = New ServiceController(Constant.ServiceName)
If impersonateValidUser(_user, _domain, _password) Then
    If _s.Status = ServiceControllerStatus.Stopped And _s.Status <> ServiceControllerStatus.StartPending Then
        _s.Start()
        _s.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(5))
    End If
    undoImpersonation()
Else
    'Error
End If

Comments:

  • Exception is “Access denied”, but the impersonated user is the same, both for the status and the start/stop
  • The user is the same user I logged in the PC. And I can start/stop user from the Service console

Any idea?

I added the identity element in the web.config and it works, but I don’t want the whole application impersonates the Administrator user (it was just a test):

<identity impersonate="true" userName="domain\user" password="password"/>
  • 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-06-13T00:46:45+00:00Added an answer on June 13, 2026 at 12:46 am

    Solution proposed here http://support.microsoft.com/kb/306158
    said

    Dim LOGON32_LOGON_INTERACTIVE As Integer = 2
    Dim LOGON32_PROVIDER_DEFAULT As Integer = 0
    
    If LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
        [...]
    End if
    

    It didn’t work for me.

    I replaced LOGON_32_LOGON_INTERACTIVE with LOGON32_LOGON_SERVICE:

    Dim LOGON32_LOGON_INTERACTIVE As Integer = 2
    Dim LOGON32_LOGON_NETWORK As Integer = 3
    Dim LOGON32_LOGON_BATCH As Integer = 4
    Dim LOGON32_LOGON_SERVICE As Integer = 5
    Dim LOGON32_LOGON_UNLOCK As Integer = 7
    Dim LOGON32_LOGON_NETWORK_CLEARTEXT As Integer = 8
    Dim LOGON32_LOGON_NEW_CREDENTIALS As Integer = 9
    Dim LOGON32_PROVIDER_DEFAULT As Integer = 0
    
    If LogonUserA(userName, domain, password, LOGON32_LOGON_SERVICE,LOGON32_PROVIDER_DEFAULT, token) <> 0 Then
        [...]
    End if
    

    And it works for me: the ASP .NET page can start/stop the service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I implemented 6 months ago in our web application site(Asp.Net) a page where you
I implemented OpenID support for an ASP.Net 2.0 web application and everything seems to
I've implemented an ASP.NET web application that supports 5 different languages. The web application
I have developed an asp.net web application containing 40-50 pages. I have implemented logger
My asp.net web page shows a list of Youtube videos. I want to show
I created an ASP.NET web application (to consume a WCF Data Service) and added
I have an ASP.NET web page that displays a variety of fields that need
I'm using VS2010,C# to develop my ASP.NET web app, I've implemented an internal communication
I'm developing an ASP.NET web application. When a user loads a specific page on
I have implemented ASP.Net application deployed in IIS with http and https port enabled.

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.