【问题标题】:Executing psexec from c# code从 C# 代码执行 psexec
【发布时间】:2014-10-21 11:46:00
【问题描述】:

我正在尝试通过将一些变量传递给“psexec”来执行命令。尝试了各种方法来执行它,但仍然无法完成它。

我想使用按钮事件处理程序执行以下操作。

private void button3_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = "psexec.exe"; //currently its in debug folder
        proc.StartInfo.Arguments = "/c \\10.10.1.10 -u domain\test1 -p testpass " + "C:\\windows\\system32\\cmd.exe";
        proc.Start();

       // proc.WaitForExit();
        MessageBox.Show("Command Exected");


    }

【问题讨论】:

  • 转义你传递给 .Arguments 或@"/c \\10...的内容
  • 我已经尝试过了,但没有任何作用。
  • 它应该让世界变得与众不同。字符串的第一部分只能编译,因为它恰好在第三个反斜杠之后包含t。但这意味着您要发送“域”+ [制表符]+“est1”。我认为这会对您的通话产生影响。
  • 为什么有人喜欢对真正的问题投反对票。版主应该禁止这些用户..

标签: c# winforms event-handling command psexec


【解决方案1】:

我不太了解 C#,但这是我用来在 VB.NET 中做非常相似的事情的工作代码:

    Private Sub startProcess(ByVal remotePC As String, ByVal remotePC_URL As String, ByVal remoteUser As String, ByVal password As String)
    Dim proc As New System.Diagnostics.Process
    proc.StartInfo = New ProcessStartInfo("CMD")
    proc.StartInfo.Arguments = "/k psexec \\" & remotePC & " -u " & remoteUser & " -p " & password & " -i -d ""C:\Program Files (x86)\Internet Explorer\iexplore.exe"" -k " & remotePC_URL & ""
    proc.StartInfo.CreateNoWindow = True
    proc.StartInfo.UseShellExecute = False
    proc.Start()
End Sub 'startProcess

【讨论】:

    猜你喜欢
    • 2017-03-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2015-08-29
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多