一旦我的程序安装在客户端计算机上,如何强制我的程序在Windows 7上以管理员身份运行?
我正在尝试使用InstallUtil.exe安装服务但通过调用Process.Start.这是代码:
ProcessStartInfo startInfo = new ProcessStartInfo (m_strInstallUtil, strExePath);
System.Diagnostics.Process.Start (startInfo);
Run Code Online (Sandbox Code Playgroud)
其中m_strInstallUtil是完全限定的路径和exe"InstallUtil.exe",并且strExePath是我的服务的完全限定路径/名称.
从提升的命令提示符运行命令行语法有效; 从我的应用程序运行(使用上面的代码)没有.我假设我正在处理一些进程提升问题,那么我如何在高架状态下运行我的进程?我需要看一下ShellExecute吗?
这一切都在Windows Vista上.我正在VS2008调试器中运行升级到管理员权限的进程.
我也试过设置,startInfo.Verb = "runas";但似乎没有解决问题.
奇怪,但也许我处理它的方式不正确 - 我需要非常简单地检查 explorer.exe 是否正在运行,如果是,则将其杀死。但是,按照我目前实现这一目标的方式,explorer.exe 在我杀死它后只是重新启动。
虽然通过批处理正常 taskkill 工作正常,但 C# 做一些不同的事情吗?
private void Form1_Load(object sender, EventArgs e)
{
Process[] prcChecker = Process.GetProcessesByName("explorer");
if (prcChecker.Length > 0)
{
MessageBox.Show("Explorer running");
foreach (Process p in prcChecker)
{
p.Kill();
}
}
else
{
MessageBox.Show("Explorer is not running");
}
}
Run Code Online (Sandbox Code Playgroud) 我写了这个小函数,按名称搜索进程并将其杀死:请参阅下面的代码
Process[] procList = Process.GetProcesses();
RegistryKey expKey = Registry.LocalMachine;
expKey = expKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
expKey.SetValue("AutoRestartShell", 0);
using (StreamWriter writer = new StreamWriter(@"C:\test\progtemp\Procs1.Txt", true))
{
int i = 0;
foreach (Process procs in procList)
{
writer.WriteLine(string.Format("Process Name {0} -- Process ID {1} -- Session ID {2}", procs.ProcessName, procs.Id, procs.SessionId));
if (procs.ProcessName == "explorer")
{
procList[i].Kill();
}
i++;
}
}
expKey.SetValue("AutoRestartShell", 1);
Run Code Online (Sandbox Code Playgroud)
我很好奇为什么当我告诉它杀死资源管理器时它会自动重启.我怎样才能使它不重新启动而你必须进入任务管理器并手动重新启动它?