locked
UAC prompt/elevated permissions on Windows 7? RRS feed

  • Question

  • Hello, currently I'm doing some sort of front-end for the "netsh" console command. My idea is to make a program that stores IP/netmask/gateway profiles and lets the user switch between them so they can reconfigure their wireless adapter easily.

    The problem comes when I execute netsh. I do it with System.Diagnostics.Process.Start, and if I have UAC disabled it works flawlessly. Otherwise, netsh says that it needs elevated administrator privileges to change the adapter's properties.

    Is there any way to force an UAC prompt so the user can give the privileges to the netsh process? Or if I run the front-end as administrator, pass the rights down to netsh...

    Thanks for the help!

    PS: My bad, I forgot to tell that I'm using C# and .NET 3.5.
    Friday, November 13, 2009 12:13 AM

All replies

  • D'oh... just found it, in an older post...

    http://social.msdn.microsoft.com/Forums/en-US/windowssecurity/thread/dd400cb9-d5fc-41b2-ad9d-6b91ce88c766

    I'll search better before posting next time!
    • Proposed as answer by Fisnik Hasani Saturday, January 2, 2010 2:22 PM
    Friday, November 13, 2009 12:31 AM
  • Hello r2d2rigo:

    hahaha, it's my post.

    You can use this:

    try
    {
       ProcessStartInfo proc = new ProcessStartInfo();
                    proc.UseShellExecute = true; //You must set the UseShellExecute to "true" for this to work.
                    proc.WorkingDirectory = @"C:\Something\";
                    proc.FileName = @"netsh.exe"
                    proc.Verb = "runas" //This is the action.
                    Process.Start(proc);
    }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);    
                }

    This code-snippet will FIX it...

    bye...

    Have a nice day...

    Best regards,
    Fisnik


    Coder24.com
    • Proposed as answer by Fisnik Hasani Saturday, January 2, 2010 2:22 PM
    Friday, November 13, 2009 7:12 PM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Sunday, December 27, 2009 10:29 AM
  • Hi again:

    How is the situation on your side?
    Is this thread solved?

    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Sunday, December 27, 2009 10:29 AM
  • Hi again:

    Is this thread solved or NOT?
    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik
    Coder24.com
    Saturday, January 2, 2010 2:21 PM
  • Hi again:

    Is this thread solved or NOT?
    Please tell me!

    Have a nice day...

    Best regards,
    Fisnik

    Coder24.com
    Saturday, January 2, 2010 2:21 PM
  • This works fine for me, thanks for the info.
    Wednesday, January 6, 2010 9:20 PM
  • Is there any way to force the netsh to open from c# with elevated rights, without asking for permission?

    The idea is that i want to execute 2 commands from netsh:

    http delete sslcert .... and http add sslcert ...

    but I need elevated rights for this, and i am stuck at this point:

     ProcessStartInfo proc = new ProcessStartInfo();
                    proc.UseShellExecute = true; //You must set the UseShellExecute to "true" for this to work.
                    proc.FileName = @"runas.exe";
                    proc.Arguments = "/user:elf netsh";
                    Process.Start(proc);

    It then appears the part of asking me for the password, but i can't do it from c#. I tried with a StreamWriter.WriteLine("password"); but it doesn't do anything...

    really appreciate some help on this one.

     

    Friday, April 15, 2011 7:03 AM
  • i found this:

    http://www.icodefactory.com/lab/post/UAC-Revealed-7e-elevation-of-rights-from-NET-as-commonly-misunderstood.aspx

     

    Apparently, there is a bug.

     

    Will run cmd.exe elevated on Vista, because this user is not run as regular user, but as full rights administrator!
    But, if you try to use any other member of administrators group as as new process user it will not work

     

    tested this on windows 7, and it's the same problem.
    Friday, April 15, 2011 9:14 AM