views:

102

answers:

4

Possible Duplicate:
Elevating process privilege programatically?

I'd like to build a console application in .NET that simply runs another program with elevated rights. That way I can point it to, say, an install exe for Flash, send a shortcut to the user pointing to my 'runasadmin' exe, and the user can update Flash.

The credentials and the file name to run will be hidden from the user (within the compiled exe)

Is this secure, of course not. But the thought of hitting hundreds of users' workstations is making us look at alternatives :)

Is this feasible? Anyone have experience in this area?

+1  A: 

It sounds like you're in an corporate IT department, in which case I imagine you can create AD accounts that have admin privileges on users' machines. Once you've done that you can create a .NET app that P/Invokes to CreateProcessAsUser to launch the required install process under an admin account.

Some info on how to P/Invoke this method from .NET can be found here

Having said that, rolling out software to multiple users machines is a common requirement and there are a number of products available that will do this for you.

d4nt
+2  A: 

Try the Windows API call "CreateProcessWithLogonW" - I've used this from .Net with much success.

Will A
+3  A: 

Just so you know, Microsoft already provides a command line utility to run programs as a different user, including administrator: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true

You could create a shortcut that executes RunAs, with the appropriate command line parameters and your program would execute, in one click.

icemanind
I'd be happy to work with that, but it doesn't appear that you can include the password in the command. The point is for me to grant admin access to run a program without an administrator's involvement, and without giving away the admin password (just kidding - that's not a consideration!)
Ken Pespisa
A: 
            System.Diagnostics.ProcessStartInfo processStartInfo = new System.Diagnostics.ProcessStartInfo("path", "args");
        processStartInfo.Verb = "runas";

        using (System.Diagnostics.Process process = new System.Diagnostics.Process())
        {
            process.StartInfo = processStartInfo;
            process.Start();
            process.WaitForExit();
        }
Pandacoon