从c#代码执行psexec



我试图通过向"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 domaintest1 -p testpass " + "C:\windows\system32\cmd.exe";
        proc.Start();
       // proc.WaitForExit();
        MessageBox.Show("Command Exected");

    }

我对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 Exploreriexplore.exe"" -k " & remotePC_URL & ""
    proc.StartInfo.CreateNoWindow = True
    proc.StartInfo.UseShellExecute = False
    proc.Start()
End Sub 'startProcess

相关内容

  • 没有找到相关文章

最新更新