Резюме:
- запрос на удаленном компьютере
- вывод для использования в приложении
- должен находиться в 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, будут приветствоваться. Пока ive попытался использовать метод RegistryKey OurKey = Registry.Users, и он отлично работает, но я не могу запросить реестр на удаленной машине.
Пожалуйста, дайте мне знать, если вам нужна дополнительная информация.
РЕШЕНИЕ: (Спасибо @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");
}