Sign Out, Restart and Shutdown Access Denied (5) when invoking from VB.NET

1k views Asked by At

I created a Windows Form App with Visual Studio Community 2019 for my users.

I added 3 buttons in my Form to Logoff (SignOff), Restart and Shutdown the Computer with a single click: Control buttons.

But when pressed the result is Access Denied (5):
enter image description here

This is for the current user in his computer (not remotely).
The user has the permissions to shutdown, restart and logoff his own computer.
The App is installed PER USER. If I use RunAs it will ask for permissions in a task that normally does not require permission.

If I run these commands in Powershell or CMD it worked without elevation.

This is the code I am using:

Private Sub Btn_SignOut_Click(sender As Object, e As EventArgs) Handles Btn_SignOut.Click
    Dim process As New Process()
    Dim result As DialogResult = MessageBox.Show("Do you want to Sign Off?",
                  "Account SignOff",
                  MessageBoxButtons.YesNo)

    If (result = DialogResult.Yes) Then
        Process.Start("c:\windows\System32\shutdown.exe", " /r /t 300")
    Else
        MsgBox("Sign Off Cancelled")
    End If
End Sub
0

There are 0 answers