Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to run below code in VS-2017 and Win-10.

What I have tried:

C#
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++)
            {
                ssPwd.AppendChar(password[x]);
            }
            password = "";
            proc.StartInfo.Password = ssPwd;
            proc.Start();
Posted
Updated 27-Jul-20 22:40pm
v2

The documentation explains it:
Quote:
Note

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.
 
Share this answer
 
Comments
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.
[no name] 10-Aug-20 12:01pm    
I hate 1 votes without comments, have a 5.
A quick look around, I learnt that Verb is only recognized when UseShellExecute = true. So, try with option:
C#
UseShellExecute = true
 
Share this answer
 
Comments
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

Quote:
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900