user3508511 user3508511 - 5 months ago 13
Vb.net Question

Need to prompt user for UAC when attempting to open a share using Process.Start

This works, if the current user has rights to the UNC path. Opens it right up.

Process.Start("\\USERSHARE\VALUE\EMPLOYEES\")


However, I have to run the entire program as a user that doesn't have access to the UNC path due to SQL permissions in the code.

I made a button in the app that will open the UNC path in an explorer window, but I cannot figure out how to force a runas for the operation.

I have tried the following as well:

Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process

With procStartInfo
.UseShellExecute = True
.FileName = "Notepad.exe"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With

procExecuting = Process.Start(procStartInfo)


This works and prompts with UAC to open "notepad".

This doesn't work to open the UNC path:

Dim procStartInfo As New ProcessStartInfo

With procStartInfo
.UseShellExecute = True
.FileName = "\\USERSHARE\VALUE\EMPLOYEES\"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With

Process.Start(procStartInfo)


I understand opening the fileshare isn't the same as pointing the .FileName at an executable.

I'm having problems trying to have the app prompt for UAC before attempting to open the remote folder.

Answer

You don't want to execute the folder itself, but rather explorer.exe with the folder as an argument:

Dim procStartInfo As New ProcessStartInfo

With procStartInfo
    .UseShellExecute = True
    .FileName = "explorer.exe"
    .Arguments = "\\USERSHARE\VALUE\EMPLOYEES\"
    .WindowStyle = ProcessWindowStyle.Normal
    .Verb = "runas" 'add this to prompt for elevation
End With

Process.Start(procStartInfo)