Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute =true;
myProcess.StartInfo.Verb = "runas";
myProcess.StartInfo.FileName = @"cmd.exe";

myProcess.EnableRaisingEvents = true;
myProcess.Start();
string ramana = "instsrv.exe" + " "+"YourServiceName" + " " + @"D:\WindowsService1.exe";
Thread.Sleep(8000);
System.Windows.Forms.SendKeys.SendWait(ramana + "{ENTER}");

Thread.Sleep(3000);
// myProcess.Kill();
MessageBox.Show("done...");

What I have tried:

The cmd is opening as administation but sendkeys event not working ,if cmd open normally means(without administration ) it will work

can any one one help me out from this

thanks in advance
Posted
Updated 26-Sep-16 1:33am
Comments
Mehdi Gholam 26-Sep-16 6:33am    
Why are you using SendKey() ?

What are you trying to accomplish with sendKeys.SendWait? If you just want to pass arguments to your process start, use arguments property of StartInfo
ProcessStartInfo.Arguments Property (System.Diagnostics)[^]
 
Share this answer
 
SendKeys will not work in the security contexts for your target window is higher from the one sending the keys. Think about what a massive security risk it would be if a normal user could just send and keystrokes they wanted to a admin CMD prompt.

This is a massive security risk and is therefore denied.
 
Share this answer
 

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