요약 : 원격 시스템에C#에서 쉘 명령 출력을 캡처하는 방법?
- 쿼리 레지스트리 CSHARP에 있어야 응용 프로그램에서
- 요구를 사용하는
- 캡처 출력
- 지금까지 로컬 컴퓨터에서 조회 할 수 있습니다 사용되는 모든 방법
- 어떤 희망이라도 대단히 감사합니다.
전체 호 :
csharp에서 명령 줄 명령을 실행하고 출력을 캡처하는 방법을 찾아야합니다. Perl에서이 작업을 수행하는 방법을 알고 있습니다. 아래 코드는 Perl에서 사용하는 코드입니다.
#machine to check
my $pc = $_[0];
#create location of registry query
my $machine = "\\\\".$pc."\\HKEY_USERS";
#run registry query
my @regQuery= `REG QUERY $machine`;
csharp에서이 작업을 수행하는 방법에 대한 제안을 환영합니다. 지금까지 필자는 RegistryKey OurKey = Registry.Users 메소드를 사용해 보았지만 훌륭하게 작동하지만 원격 컴퓨터의 레지스트리를 쿼리 할 수는 없습니다.
더 자세한 정보가 필요하면 알려주십시오.
해결책 :
private void reg(string host)
{
string build = "QUERY \\\\" + host + "\\HKEY_USERS";
string parms = @build;
string output = "";
string error = string.Empty;
ProcessStartInfo psi = new ProcessStartInfo("reg.exe", parms);
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
psi.UseShellExecute = false;
System.Diagnostics.Process reg;
reg = System.Diagnostics.Process.Start(psi);
using (System.IO.StreamReader myOutput = reg.StandardOutput)
{
output = myOutput.ReadToEnd();
}
using (System.IO.StreamReader myError = reg.StandardError)
{
error = myError.ReadToEnd();
}
Output.AppendText(output + "\n");
}
가능한 중복 (http://stackoverflow.com/questions/353601/capturing-nslookup-shell-output-with-c가) –
당신이 시도해 봤어'RegistryKey.OpenRemoteBaseKey '? http://msdn.microsoft.com/en-us/library/8zha3xws.aspx –
PowerShell이 훨씬 더 나은 선택입니다. – TrueWill