Click here to Skip to main content
14,668,823 members
Rate this:
Please Sign up or sign in to vote.
See more:
I tried to run below code in VS-2017 and Win-10.

What I have tried:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
            System.Security.SecureString ssPwd = new System.Security.SecureString();
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.Verb = "runas";
            proc.StartInfo.FileName = Path.Combine(Path.GetDirectoryName(@"C:\Users\ABC\Downloads\"), "ccsetup567.exe"); ;
            proc.StartInfo.UserName = "Admin";
            string password = "admin";
            for (int x = 0; x < password.Length; x++)
            password = "";
            proc.StartInfo.Password = ssPwd;
Updated 27-Jul-20 22:40pm

Rate this:
Please Sign up or sign in to vote.

Solution 3

The documentation explains it:

This class contains a link demand and an inheritance demand at the class level that applies to all members. A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission. For details about security demands, see Link Demands.

So you need to run with admin privilege.
SunnyGajjar14 28-Jul-20 4:44am
I run that with Admin user name and password. But still it is not working.
Richard MacCutchan 28-Jul-20 5:24am
I think the program may need to have elevated privilege set in its manifest.
SunnyGajjar14 28-Jul-20 5:38am
That's also I applied but when I run for stand user at that time I need to run as admin that I don't want to do
Richard MacCutchan 28-Jul-20 5:49am
Well you have no choice, that is how Windows works.
0x01AA 10-Aug-20 12:01pm
I hate 1 votes without comments, have a 5.
Richard MacCutchan 10-Aug-20 12:40pm
Thank you.
Rate this:
Please Sign up or sign in to vote.

Solution 1

A quick look around, I learnt that Verb is only recognized when UseShellExecute = true. So, try with option:
UseShellExecute = true
SunnyGajjar14 28-Jul-20 1:44am
The Process object must have the UseShellExecute property set to false in order to start a process as a user.'
Sandeep Mewara 28-Jul-20 3:42am
What does that mean? Your code is to start it as admin.
Sandeep Mewara 28-Jul-20 3:46am
Elevated priviledges doesnt work with UseShellExecute=false

ProcessStartInfo.Verb will only have an effect if the process is started by ShellExecuteEx(). Which requires UseShellExecute = true.
SunnyGajjar14 28-Jul-20 3:49am
No, it is not start as admin. I need that when Stander user run this code Admin username and password set from code and run that exe without any admin rights. Is it possible?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100