redirecting output of CMD with administrator privileges
Managed C++/CLI
1
Posts
1
Posters
1
Views
1
Watching
-
Hello! I have following problem. I want to create a application, which is using Netsh. I have created following code:
private: System::Void button1_Click( System::Object ^ sender, System::EventArgs ^ e ) {
Process ^ mojProces = gcnew Process(); ProcessStartInfo ^ startInfo = gcnew ProcessStartInfo( "cmd.exe" ); startInfo->Verb = "runas"; startInfo->Arguments =( "Administrator /c \\"netsh wlan start hostednetwork\\" " ); startInfo->UseShellExecute = false; startInfo->CreateNoWindow = true; startInfo->RedirectStandardOutput = true; startInfo->RedirectStandardInput = true; info->Text = "Sieć została uruchomiona."; mojProces->StartInfo = startInfo; mojProces->Start(); StreamReader ^ wynik = mojProces->StandardOutput; String ^ wynik\_konsoli = wynik->ReadToEnd(); wynik\_wysw->Text = wynik\_konsoli; mojProces->WaitForExit(); mojProces->Close();
Now I would like to redirect output of CMD, but there is following problem. When I set UseShellExecute=false, I cannot run CMD with administrator privileges, which is required to use Netsh. But when I set true I cannot redirect output. Could you please help, how can I solve this problem? Thank you in advance!