尝试使用 Process.Start 打开共享时需要提示用户输入 UAC

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

如果当前用户有权访问 UNC 路径,则此方法有效。打开它。

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

但是,由于代码中的 SQL 权限,我必须以无法访问 UNC 路径的用户身份 运行 整个程序。

我在应用程序中创建了一个按钮,它将在资源管理器中打开 UNC 路径 window,但我不知道如何强制执行 运行as 操作。

我也试过以下方法:

    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)

这有效并提示使用 UAC 打开 "notepad"。

这无法打开 UNC 路径:

    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)

我知道打开文件共享与将 .FileName 指向可执行文件不同。

我在尝试打开远程文件夹之前尝试让应用程序提示 UAC 时遇到问题。

您不想执行文件夹本身,而是 explorer.exe 以文件夹作为参数:

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)