Example #1
0
        private static void RunElevated()
        {
            try
            {
                var applicationDir = Directory.GetCurrentDirectory();

                var applicatonFullName = Path.Combine(applicationDir, "Test.DeskMan.exe");
                var commandLine        = "-norestart";

                //var applicatonFullName = Path.Combine(@"C:\Windows", "regedit.exe");

                var pid = ProcessTool.StartProcessWithSystemToken(applicatonFullName, commandLine);

                if (pid > 0)
                {
                    var process = Process.GetProcessById(pid);
                    if (process != null)
                    {
                        Console.WriteLine("New process started: " + process.ProcessName);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            //Process process = new Process();
            //var _args = new string[]
            //{
            //	"-s",
            //	"-i",
            //	"\"" + curFile + "\"",

            //	//"\""  + "\"" + curFile + "\"" + " -test" + "\"",

            //};
            //ProcessStartInfo pi = new ProcessStartInfo
            //{
            //	FileName = "PsExec.exe",
            //	Arguments = string.Join(" ", _args), //"-s -i Test.DeskMan.exe -test",
            //	Verb = "runas",
            //};

            //process.StartInfo = pi;

            //process.Start();
        }