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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:11:42+00:00 2026-06-02T19:11:42+00:00

When a user needs to enter their license key, we want to put it

  • 0

When a user needs to enter their license key, we want to put it in HKLM if we can, and in HKCU if we cannot. If it is in HKLM then all users on the computer have the license without each having to enter it.

We are an AddOn to Office so we run with Office rights. Generally this is not admin rights (unless they have UAC turned off). So WindowsPrincipal.IsInRole(Administrator) will return false regardless of what the user could do.

If the user has local admin rights, we want to launch an applet that has runas=admin and they can then set it in HKLM. However, if they do not have local admin rights, then we put it in HKCU.

So… How can I determine if a user can do runas=admin? We’re on .net 3.5.

thanks – dave

  • 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-02T19:11:43+00:00Added an answer on June 2, 2026 at 7:11 pm

    The process I generally use in some client software we wrote looks like this:

    1. Attempt to start elevated process to set registry keys.
    2. Wait until the process has completed or thrown an exception.
    3. Validate registry keys were set by attempting to read expected keys (non-admin can do this)
    4. If keys were not set, run fallback method (e.g., write to HKCU)

    I have a helper function for running elevated code that looks like this (VB.Net). Since I just use the same application with command-line flags to run the elevated process, you can see I’m using the current assembly for the process name. You can replace with your particular process.

    Private Function RunElevated(commandLine As String, Optional ByVal timeout As Integer = 0) As Boolean
        Dim startInfo As New ProcessStartInfo
        startInfo.UseShellExecute = True
        startInfo.WorkingDirectory = Environment.CurrentDirectory
        Dim uri As New Uri(Assembly.GetEntryAssembly.GetName.CodeBase)
        startInfo.FileName = uri.LocalPath
        startInfo.Verb = "runas"
        startInfo.Arguments = commandLine
    
        Dim success As Boolean
        Try
            Dim p As Process = Process.Start(startInfo)
            ' wait thirty seconds for completion
            If timeout > 0 Then
                If Not p.WaitForExit(30000) Then
                    ' did not complete in thirty seconds, so kill
                    p.Kill()
                    success = False
                Else
                    success = True
                End If
            Else
                p.WaitForExit()
                success = True
            End If
        Catch ex As Win32Exception
            success = False
        Catch ex As Exception
            MsgBox("Error occurred while trying to start application as administrator: " & ex.Message)
            success = False
        End Try
        Return success
    End Function
    

    In the code above I handle exceptions as a failure code, and also I limit the execution to 30 seconds for our environment. You may not want to have a time-limit in your case, so you can just remove that part of the code.

    In the admin mode process, I double-check I’m actually an administrator first using this helper function:

    Public Function IsAdmin() As Boolean
        Dim id As WindowsIdentity = WindowsIdentity.GetCurrent
        Dim p As New WindowsPrincipal(id)
        Return p.IsInRole(WindowsBuiltInRole.Administrator)
    End Function
    

    Once I know I’m an admin, then I go ahead and set the registry keys and return. The caller program then validates the keys were set successfully to determine whether the fallback procedure needs to be run. This is when RunElevated returns back to the caller, because at that time the sub-process has completed and was either successful or failed to set the keys. That code looks something like this:

    Public Function UpdateSettings(...) As Boolean
        Dim success As Boolean
        Try
            If Not IsAdmin() Then
                ' try to create the registry keys as administrator
                success = RunElevated(Command() & " /admin", 30000)
            Else
                ' if we're already admin, then just update directly
                success = UpdateSettingsAdmin(...)
            End If
            success = success And ValidateUpdateSettings(...)
        Catch ex As Exception
            success = False
        End Try
        Return success
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to allow my customer users to enter their credit card information so
I have a very common use case. The user needs to enter their address
I have a JSF page where users can enter their car into my database.
For a project I'm working on, the user needs to enter a direction, like
HI, i am developing an application, where the user needs to enter the start
There's several section of our site where the user needs to enter some information,
I'm coding a new website that will need users to enter their mobile phone
Consider a data entry form where the user needs to enter times in military
I have an application that displays a dialog when the user needs to enter
For my website, I need to have a way for users to enter their

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.