Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start a process as user from an process running as admin

I want to start another program which runs as user from a program running as administrator.

The problem is that the second program needs to use outlook, which is not possible if the program runs as admin. The main program needs to run as admin.

I did already come up with this two solutions:

Process.Start("cmd.exe", @"/C runas.exe /savecred /user:" + Environment.UserDomainName + "\\" + Environment.UserName + " " + "\"SomeProgram.exe" + "\"");

or

Process.Start("explorer.exe", "SomeProgram.exe");

But i have a problem with both solutions. The first one asks the user for the password (only the first time after windows was restarted). The second one probalby won`t work in the future, because as far as i found out it is considered as a bug and probably fixed with an future update.

So I would like to know is there any other solution, where the user does not need to enter his password?

This seems to work for me:

Process.Start("cmd.exe", @"/C runas.exe /TrustLevel:0x20000  " + "\"SomeProgram.exe" + "\"");
like image 956
FKorni Avatar asked Jul 27 '15 07:07

FKorni


People also ask

How do I run a process without a username and password?

If the issue is that you currently have admin rights, but need to run something without those admin rights, then this should be possible using PSExec or similar methods without needing a Username & Password. -l Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group).

How do I run a process as a limited user?

-l Run process as limited user (strips the Administrators group and allows only privileges assigned to the Users group). On Windows Vista the process runs with Low Integrity. It should be possible to call PSExec within PowerShell and have PSExec call the original application.

How do I start a PowerShell process as an administrator?

This example starts PowerShell by using the Run as administrator option. This example shows how to find the verbs that can be used when starting a process. The available verbs are determined by the filename extension of the file that runs in the process.

How do I create a new process in start process?

By default, Start-Process creates a new process that inherits all the environment variables that are defined in the current process. To specify the program that runs in the process, enter an executable file or script file, or a file that can be opened by using a program on the computer.


1 Answers

Process class has StartInfo property that is an instance of ProcessStartInfo class. This class exposes UserName, Domain and Password members to specify the user you want to run the process.

Process myProcess = new Process();
myProcess.StartInfo.FileName = fileName;
myProcess.StartInfo.UserName = userName;
myProcess.StartInfo.Domain = domain;
myProcess.StartInfo.Password = password;
myProcess.Start();
like image 174
Matteo Umili Avatar answered Sep 30 '22 00:09

Matteo Umili