【问题标题】:Need to prompt user for UAC when attempting to open a share using Process.Start尝试使用 Process.Start 打开共享时需要提示用户输入 UAC
【发布时间】:2015-06-08 19:36:20
【问题描述】:

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

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

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

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

我也尝试了以下方法:

    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 打开“记事本”。

这对打开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 时遇到问题。

【问题讨论】:

    标签: vb.net uac


    【解决方案1】:

    您不想执行文件夹本身,而是希望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)
    

    【讨论】:

      猜你喜欢
      • 2010-10-29
      • 1970-01-01
      • 2021-06-22
      • 2023-04-10
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      • 2011-12-31
      相关资源
      最近更新 更多