我只想打开cmd提示作为管理,之后我必须传递一些东西来创建服务,我的代码在下面 [英] I just want to open cmd prompt as administration, after that I have to pass something to create service my code is below
问题描述
处理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;
线程。睡眠(8000);
System.Windows.Forms.SendKeys.SendWait(ramana +{ENTER});
Thread.Sleep(3000);
// myProcess.Kill();
MessageBox.Show(完成......);
我尝试了什么:
cmd作为管理员打开但是如果cmd打开正常意味着sendkeys事件无效)它会工作
任何人都可以帮我解决这个问题
提前感谢
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
推荐答案
你想用sendKeys.SendWait完成什么?如果您只想将参数传递给进程启动,请使用StartInfo的arguments属性
ProcessStartInfo.Arguments属性(System.Diagnostics) [ ^ ]
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)[^]
SendKeys无效目标窗口的安全上下文比发送密钥的安全上下文要高。想想如果普通用户可以发送他们想要管理员CMD提示的按键,那将是一个巨大的安全风险。
这是一个巨大的安全风险,因此被拒绝。
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.
这篇关于我只想打开cmd提示作为管理,之后我必须传递一些东西来创建服务,我的代码在下面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!