小编use*_*788的帖子

使用管理员权限运行cmd.exe

这是我的代码尝试使用admin priviligies运行cmd.exe.但是,我得到请求操作需要提升.如果我通过我的Windows运行带有"以管理员身份运行"的cmd.exe,它可以通过vb运行,但它没有.这是我的代码.

Try
        Dim process As New Process()
        process.StartInfo.FileName = "cmd.exe "
        process.StartInfo.Verb = "runas"
        process.StartInfo.UseShellExecute = False
        process.StartInfo.RedirectStandardInput = True
        process.StartInfo.RedirectStandardOutput = True
        process.StartInfo.RedirectStandardError = True
        process.StartInfo.CreateNoWindow = True

        process.Start()
        process.StandardInput.WriteLine("route add 8.31.99.141 mask 255.255.255.255 " & cmdorder)
        process.StandardInput.WriteLine("exit")
        Dim input As String = process.StandardOutput.ReadToEnd
        process.Close()
        Dim regex As Regex = New Regex("(ok)+", RegexOptions.IgnoreCase) ' wa requested
        ' txtLog.AppendText(input)
        Return regex.IsMatch(input)
Run Code Online (Sandbox Code Playgroud)

谢谢.

vb.net

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

vb.net ×1