2

I'm trying to run a vb script using process.start() as another user that have admin rights, but i always get the UAC popup with username and password to fill. What i'm i doing wrong?

var scriptProc = new Process
                    {
                        StartInfo =
                            {
                                FileName = @"cscript,
                                WorkingDirectory = @"\\AShare\AFolder",
                                Arguments = "\"" + "Install.vbs" + "\"",
                                UseShellExecute = false,
                                WindowStyle = ProcessWindowStyle.Hidden,
                                Domain = domain,
                                UserName = username, //Admin username
                                Password = MakeSecureString(secureString),
                            }
                    };
scriptProc.Start();

I want the UAC to popup with yes and no options and not with username and password to fillout options.

tried looking at: How to call a VBScript file in a C# application? but that didn't help.

Phu Minh Pham
  • 1,025
  • 7
  • 21
  • 38
  • This smells like a virus. What is this for? – SimpleVar Apr 23 '12 at 07:40
  • I'm developing a little applications so when you click on a icon, it installs a program, depending on which icon you click on, from a local server with username and password provided by my IT Service Team. Not making a virus here :) I did something before where the UAC popup didn't show, then I changed something in the startInfo and now the UAC popup shows x| – Phu Minh Pham Apr 23 '12 at 07:56
  • The UAC will always popup for programs that do things that require elevation. End of story. – SimpleVar Apr 23 '12 at 08:00
  • Sorry, i wasn't clear in my question. It's okay that the UAC always popup and you can click yes or no, but what happens is that the UAC pops up with username and password for the user to fillout. In my code I've added UserName and Password in StartInfo to think that it will avoid that you have to type the username and password but still get the UAC to popup with yes/no options. – Phu Minh Pham Apr 23 '12 at 08:17
  • It will be much easier for you running your application without the prompt if you already know the user's password. – Chibueze Opata Apr 23 '12 at 10:14
  • I know the username and password but i can't figure out how to implement it to my application. Is it possible to make my application startup as a different user instead? – Phu Minh Pham Apr 23 '12 at 10:28

1 Answers1

3

You are doing nothing wrong, in Windows 7 even admin accounts run with standard user rights. Take a look at this TechNet article by Mark Russinovich

From above article.

When UAC is enabled, all user accounts—including administrative accounts—run with standard user rights. This means that application developers must consider the fact that their software won't have administrative rights by default. This should remind them to design their application to work with standard user rights. If the application or parts of its functionality require administrative rights, it can leverage the elevation mechanism to enable the user to unlock that functionality.


Edit: What you are talking about is user impersonation:

You can look at some of these articles

  1. WindowsIndentity Class
  2. http://www.codeproject.com/Articles/10090/A-small-C-Class-for-impersonating-a-User
  3. http://www.codeproject.com/Articles/4051/Windows-Impersonation-using-C
  4. Windows Impersonation from C#
  5. http://support.microsoft.com/default.aspx?scid=kb;en-us;Q306158
  6. http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic62740.aspx
Community
  • 1
  • 1
Mark Hall
  • 53,938
  • 9
  • 94
  • 111