none
Windows 8 UAC Problem

    Question

  • I might not be in the right forum for this, so if not let me know and I can move my question elsewhere...

    I have a vb.NET application that basically does a bunch of stuff with services, starting, stopping etc, and seems to require that it be run with elevated privileges. On windows 7 if the user running it didn't have administrative privileges already we would elevate ourselves to have them using the following.

       Private Function AdminElevate(ByVal args As String)
            If Not IsRunAsAdmin() Then
                '-- Re-launch the program as administrator
                Dim psinfo As New ProcessStartInfo()
                psinfo.UseShellExecute = True
                psinfo.WorkingDirectory = Environment.CurrentDirectory
                psinfo.FileName = Application.ExecutablePath
                psinfo.Arguments = args
                psinfo.Verb = "runas"
    
                Try
                    Process.Start(psinfo)
                Catch ex As Exception
                    Return False
                End Try
                Application.Exit()
                System.Environment.Exit(0)
            End If
            Return True
        End Function
        Friend Function IsRunAsAdmin() As Boolean
            Dim principal As New WindowsPrincipal(WindowsIdentity.GetCurrent)
            Return principal.IsInRole(WindowsBuiltInRole.Administrator)
        End Function

    This seemed to work fine on Windows 7 and even on Vista with no problems with UAC, but now running on Windows 8 everytime we run we get a UAC prompt.  

    What can I do to avoid this? Is there a way to run elevated without triggering the UAC prompt?

    I tried a manifest but either had it coded wrong or it didn't work...

    Rodney

    Friday, September 28, 2012 8:36 PM

Answers

All replies

  • This thread may be of assistance, specifically the last post in it. It concerns the UAC prompt for of all things when running Visual Studio on Win8 platform. Anyhow changing the noted registry key appears not only to resolve the UAC prompt issue but other permissions issues as well for an elevated user. Don't have Win8 though so don't know if this would resolve your issue which sounds similar in nature.

     http://superuser.com/questions/462912/always-start-visual-studio-as-an-administrator-on-windows-8

    "I posted about this on Stack Overflow before finding this question and then tried everything the other answers here suggested. I started running into some issues right away though.

    When running VS2012 with elevated permissions I was no longer able to drag & drop files into it from Explorer which I assume is because Explorer isn't running with elevated permissions.

    Then after I used VSCommands to always run Visual Studio with elevated permissions I was no longer able to open files associated with Visual Studio, aside from solution files, by double clicking them in Explorer. Visual Studio would open but then I'd get an error saying There was a problem sending the command to the program. and they wouldn't open.

    This left me having to use the open file dialog if I wanted to open any non solution/project file.

    Despite there being no UI to turn off UAC like in the past, that I saw at least, you can still do so through the registry. The key to edit is:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
    EnableLUA - DWORD 1-Enabled, 0-Disabled
    

    After changing this Windows will prompt you to restart. Once restarted you'll be back to everything running with admin permissions if you're an admin. The issues I reported above are now gone as well."


    You've taught me everything I know but not everything you know.

    Friday, September 28, 2012 10:29 PM
  • This might fix my problem as a developer, but how can I write code programatically to get around it so the client doesn't see it.  Surely it is possible.  Antivirus programs do it and I know they must be doing things that require elevation...

    Rodney

    Monday, October 01, 2012 8:15 AM
  • Perhaps, when your program is installed, you can programatically change the registry of win 8 computers if it is not current to your needs and require a restart of the computer if in fact this "fix" resolves your problem.

    If this "fix" actually works for a win 8 system you can obviously detect win 8 with your code and verify the registries content before your application runs.

    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim osInfo As OperatingSystem
            osInfo = Environment.OSVersion
            TextBox1.AppendText(osInfo.ToString & vbCrLf)
    
            Dim Value As String = (My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", "EnableLUA", Nothing))
            TextBox1.AppendText("EnableLUA REG_DWORD is set to " & (Value))
    
        End Sub
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    End Class


    You've taught me everything I know but not everything you know.

    • Marked as answer by Mike FengModerator Monday, October 08, 2012 11:05 AM
    • Unmarked as answer by RodneyB Monday, October 08, 2012 11:32 AM
    Monday, October 01, 2012 9:46 AM
  • This just seems to turn UAC off in general and I don't think my clients would be too happy about that at all.  I want to leave it on for them, but don't want my application to get the prompt.  I thought that is what the manifest was for, but as I said that didn't seem to work.  Am I using it incorrectly? Does anyone have experience with using them successfully to avoid this problem?

    Rodney

    Monday, October 08, 2012 11:34 AM
  • Hi Rodney,

    >>I want to leave it on for them, but don't want my application to get the prompt.

    I don't think so. Let's assume if you can, then the GAC didn't affect your program, because you can just use an "runas" verb to avoid it. When the user doesn't see this dialog, it is unreasonable the program has been elevated. The primary purpose of GAC is when a program need to access the system security part, it should be promoted explicitly by users.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, October 09, 2012 5:29 AM
  • If you disable UAC in the registry, you can't start Windows Store apps anymore. Instead, you'll get a dialog saying "This app can’t open. App can’t open while User Account Control is turned off". See OTT Explains – UAC (User Account Control) in Windows 8.

    Tuesday, October 09, 2012 12:59 PM