2014-10-21 5 views
-1

일부 변수를 전달하여 "psexec"명령을 실행하려고합니다. 실행 방법은 다양하지만 시도 할 수는 없습니다.C# 코드에서 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"); 


    } 
+2

탈출 @ "/ c \\ 10 ...' –

+0

이미 시도했지만 차이는 없습니다. –

+0

차이가 나는 세상을 만들어야합니다. 문자열의 첫 번째 부분은 컴파일 후에 만 ​​발생합니다. 그러나 세 번째 백 슬래시는 "도메인"+ [탭 문자] + "est1"을 전송한다는 의미입니다. 전화가 달라진다고 가정합니다. – DonBoitnott

답변

0

내가 아니라 C 번호를 모르는, 그러나 여기에서 일하고 코드는 내가 VB.NET에서 매우 비슷한 일을하는 데 사용 : 당신은`.Arguments 또는 전달할 것을

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 
관련 문제