Sommario:Come acquisire l'output del comando Shell in C#?
- interrogazione registro sul computer remoto uscita
- cattura da utilizzare per l'applicazione
- necessità di essere in csharp
- finora tutti i metodi utilizzati possono interrogare solo sulla macchina locale
- ogni speranza è molto apprezzata
Numero intero:
Ho bisogno di trovare un modo per eseguire un comando commandline in csharp e catturarne l'output. So come farlo in Perl, sotto c'è il codice che userei in 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`;
Qualsiasi suggerimento su come farlo in csharp sarebbe il benvenuto. Finora ho provato a utilizzare il metodo RegistryKey OurKey = Registry.Users e funziona benissimo ma non posso interrogare il registro su una macchina remota.
Per favore fatemi sapere se avete bisogno di ulteriori informazioni.
SOLUZIONE: (Grazie a @Robaticus)
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");
}
possibile duplicato del [Catturare uscita shell nslookup con C#] (http://stackoverflow.com/questions/353601/capturing-nslookup-shell-output-with-c) –
Hai provato 'RegistryKey.OpenRemoteBaseKey '? http://msdn.microsoft.com/en-us/library/8zha3xws.aspx –
PowerShell sarebbe una scelta molto migliore. – TrueWill