使用" Runas"执行程序

时间:2014-03-28 17:01:03

标签: c# vb.net batch-file

我使用.bat和.vbs运行带有命令/参数的runas来绕过SRP限制(仅限教育),.vbs文件是隐藏命令窗口,我该怎么办在VB.Net或C#上写这个。我想把它变成一个独立的.exe文件,因为我还想在机器上使用SRP也不允许命令提示符和VBScript。

HideBat.vbs

    CreateObject("Wscript.Shell").Run "run.bat", 0, True

的run.bat

    @ ECHO OFF
    runas /trustlevel:"Unrestricted" "C:\Program Files\Deluge\deluged.exe"

这是我到目前为止所提出的。

     Dim myprocess As New System.Diagnostics.Process()
     myprocess.StartInfo.FileName = Path.Combine(GetFolderPath(SpecialFolder.System), "runas.exe")
     myprocess.StartInfo.Arguments = "/trustlevel:"Unrestricted"" & " " & "c:\program.exe"
     myprocess.Start()

由于引号,Unrestricted存在问题。

1 个答案:

答案 0 :(得分:1)

假设C#(我不知道你为什么把它标记为VB.NET和C#)

Process myprocess = new Process();
myprocess.StartInfo.FileName = Path.Combine(GetFolderPath(SpecialFolder.System), "runas.exe");
myprocess.StartInfo.Arguments = "/trustlevel:\\\"Unrestricted\" \"C:\\Program Files\\Deluge\\deluged.exe\"";
myprocess.Start();

使用反斜杠转义字符串中的双引号。

更新了答案 - 忘了反斜杠路径中的反斜杠。

相关问题