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: .
But when pressed the result is Access Denied (5):
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