Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. redirecting output of CMD with administrator privileges

redirecting output of CMD with administrator privileges

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    camillo87
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups