0

I need to create File EXE when clicked by restricted user, it will execute command as administrator (Local Administrator )

I used this code:

System.Diagnostics.Process.Start(@"C:\Test.bat", ".\\Administrator", Password,".\\");

Is there any way to run a command like:

netsh int ip set address "local area connection" static 192.168.1.16 255.255.255.0 192.168.1.1 1

without using batch file?

also I have a problem with the same code when I use .msi Files. It doesn't work

System.Diagnostics.Process.Start(@"C:\Test.msi", ".\\Administrator", Password,".\\");

Any way to execute the msi files as administrator?

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
Peter
  • 162
  • 3
  • 11
  • 2
    Right click on file and `Run as administrator`. – Over Killer Jun 18 '14 at 07:55
  • I need the restricted user to do this without telling him the password – Peter Jun 18 '14 at 07:57
  • related to "msi": You'd better find another way of installing the stuff you need - either directly copying the files?, use group policy? or maybe use click once install into user profile? – rudolf_franek Jun 18 '14 at 08:16
  • possible duplicate of [Elevating process privilege programatically?](http://stackoverflow.com/questions/133379/elevating-process-privilege-programatically) – Xaruth Jun 18 '14 at 09:53

3 Answers3

0

Find your exe under HKEY_CLASSES_ROOT and then add this shell extension to your registry.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\forcerunasinvoker] @="Run without admin rights (UAC)"

[HKEY_CLASSES_ROOT\*\shell\forcerunasinvoker\command] @="cmd /min /C \"set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"%1\"\""

Hopefully you find this useful

Oneberg
  • 11
  • 1
  • 1
  • 4
  • Sorry but I can't understand , could you give an example ?? – Peter Jun 18 '14 at 08:38
  • Like I need to change the IP for a machine, while i'm using a restricted user on this machine using the administrator pass word that I know , without sign in using the administrator – Peter Jan 31 '20 at 14:00
0

Run as:

set __COMPAT_LAYER=RunAsInvoker
start App Name

Write in a notepad, then save as a .bat.

"App Name" should be replaced with the installer.

Remember to save the .bat file in the same location as the installer. If you dont, the command can’t recognize the app name.

Alternatively, you can download UniExtract and run as an Administrative Installer, with a restricted user. Download Uniextract as portable version, you find it on portableapps, and so on.

dakab
  • 5,379
  • 9
  • 43
  • 67
0
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            System.Security.SecureString ssPwd = new System.Security.SecureString();
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.FileName = @"cmd.exe";
            proc.StartInfo.Arguments = "/c netsh interface ip set address \"Ethernet\" static 192.168.1.16 255.255.255.0 192.168.1.1";
            proc.StartInfo.Domain = "";
            proc.StartInfo.Verb = "runas";
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.UserName = sysAdminUser;
            string password = sysAdminPass;
            for (int x = 0; x < password.Length; x++)
            {
                ssPwd.AppendChar(password[x]);
            }
            password = "";
            proc.StartInfo.Password = ssPwd;

            proc.Start();
Peter
  • 162
  • 3
  • 11