2016-10-10 5 views
0

NETSH 명령을 (창없이) 자동으로 실행하고 싶습니다. 이 코드를 작성했지만 작동하지 않습니다.창없이 배경에서 자동으로 프로세스를 실행하십시오.

public static bool ExecuteApplication(string Address, string workingDir, string arguments, bool showWindow) 
{ 
    Process proc = new Process(); 
    proc.StartInfo.FileName = Address; 
    proc.StartInfo.WorkingDirectory = workingDir; 
    proc.StartInfo.Arguments = arguments; 
    proc.StartInfo.CreateNoWindow = showWindow; 
    return proc.Start(); 
} 

string cmd= "interface set interface name=\"" + InterfaceName+"\" admin=enable"; 
ExecuteApplication("netsh.exe","",cmd, false); 
+5

글쎄,'CreateNoWindow'에 대해'false'를 넘겨 주므로 ... 창을 만들 것을 요청했습니다. –

답변

0

사용자 쉘 실행 false

proc.StartInfo.UseShellExecute = false; 

showWindow 매개 변수에 true를 전달이

ExecuteApplication("netsh.exe","",cmd, true); 
1

이것은 내가 내 프로젝트에서 그것을 어떻게되어 있는지 확인합니다 :

ProcessStartInfo psi = new ProcessStartInfo();    
psi.FileName = "netsh";    
psi.UseShellExecute = false; 
psi.RedirectStandardError = true; 
psi.RedirectStandardOutput = true; 
psi.Arguments = "SOME_ARGUMENTS"; 

Process proc = Process.Start(psi);     
proc.WaitForExit(); 
string errorOutput = proc.StandardError.ReadToEnd(); 
string standardOutput = proc.StandardOutput.ReadToEnd(); 
if (proc.ExitCode != 0) 
    throw new Exception("netsh exit code: " + proc.ExitCode.ToString() + " " + (!string.IsNullOrEmpty(errorOutput) ? " " + errorOutput : "") + " " + (!string.IsNullOrEmpty(standardOutput) ? " " + standardOutput : "")); 

또한 명령의 출력을 설명합니다.

+0

감사합니다. 그 작품. – user3859999

관련 문제