110,534
社区成员
发帖
与我相关
我的任务
分享
System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
//判断当前登录用户是否为管理员
if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
{
string logFileName = @"c:\aa\cmd.bat";
//string logFileName = Path.Combine(base.Context.Parameters["targetdir"].Replace(@"\\", @"\"), "cmd.bat");
if (!File.Exists(logFileName))
File.Create(logFileName).Close();
StreamWriter sw = new StreamWriter(logFileName);
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_T0 /f");
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_T3 /f");
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_T5 /f");
sb.AppendLine(@"reg delete HKEY_LOCAL_MACHINE\SOFTWARE\test /v BatchJob_InputPath_AccountCode /f");
sw.Write(sb.ToString());
sw.Close();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WorkingDirectory = Path.GetDirectoryName(logFileName);
startInfo.FileName = Path.GetFileName(logFileName);
//startInfo.Arguments = "/c C:\\Windows\\System32\\cmd.exe";
startInfo.UseShellExecute = true;
startInfo.Verb = "RunAs";
startInfo.CreateNoWindow = false;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
}
else
{
Console.Write("123123");
Console.ReadLine();
}