【发布时间】:2019-07-18 13:48:11
【问题描述】:
我正在尝试将字符串从 vb.net 传递到命令提示符窗口。最后,我想使用 runas 并使用之前在登录应用程序时提供的密码作为密码。基本上我想运行 runas 命令,然后在窗口中输入密码(或以某种方式将其提供给 cmd)
Public Sub runCmd(ByVal pass As String, ByVal command As String, ByVal arguments As String, ByVal permanent As Boolean)
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments
pi.FileName = "cmd.exe"
pi.Verb = "runas"
p.StartInfo = pi
p.Start()
End Sub
这是我得到目录错误的更新代码
Public Sub runCmd(ByVal pass As String, ByVal user As String, ByVal domainName As String, ByVal command As String, ByVal arguments As String, ByVal permanent As Boolean)
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments
pi.FileName = "cmd.exe"
pi.Verb = "runas"
pi.UserName = user
pi.Domain = domainName
pi.Password = getSecureString(pass)
p.StartInfo = pi
pi.UseShellExecute = False
p.Start()
End Sub
【问题讨论】:
-
你试过看here吗?
-
是的,使用 createprocesswithlogonW 会给我一个提升错误,我正在使用 runas 作为解决方法,因为我无法禁用 UAC。