processstartinfo

Elevating privileges doesn't work with UseShellExecute=false

时光毁灭记忆、已成空白 提交于 2019-11-26 22:58:27
I want to start a child process (indeed the same, console app) with elevated privileges but with hidden window. I do next: var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location) { UseShellExecute = true, // ! Verb = "runas", }; var process = new Process { StartInfo = info }; process.Start(); and this works: var identity = new WindowsPrincipal(WindowsIdentity.GetCurrent()); identity.IsInRole(WindowsBuiltInRole.Administrator); // returns true But UseShellExecute = true creates a new window and I also I can't redirect output. So when I do next: var info = new ProcessStartInfo

Run process as administrator from a non-admin application

僤鯓⒐⒋嵵緔 提交于 2019-11-26 22:11:14
From an application that is not being run as administrator, I have the following code: ProcessStartInfo proc = new ProcessStartInfo(); proc.WindowStyle = ProcessWindowStyle.Normal; proc.FileName = myExePath; proc.CreateNoWindow = false; proc.UseShellExecute = false; proc.Verb = "runas"; When I call Process.Start(proc), I do not get a pop up asking for permission to run as administrator, and the exe is not run as administrator. I tried adding an app.manifest to the executable found at myExePath, and updated the requestedExecutionLevel to <requestedExecutionLevel level="requireAdministrator"

.NET - WindowStyle = hidden vs. CreateNoWindow = true?

风格不统一 提交于 2019-11-26 21:35:30
When I start a new process, what difference does it make if I use the WindowStyle = hidden or the CreateNoWindow = true property of the ProcessStartInfo class? Liz As Hans said, WindowStyle is a recommendation passed to the process, the application can choose to ignore it. CreateNoWindow controls how the console works for the child process, but it doesn't work alone. CreateNoWindow works in conjunction with UseShellExecute as follows: To run the process without any window: ProcessStartInfo info = new ProcessStartInfo(fileName, arg); info.CreateNoWindow = true; info.UseShellExecute = false;

Sending input/getting output from a console application (C#/WinForms)

落爺英雄遲暮 提交于 2019-11-26 21:04:44
问题 I have a form with 3 controls: A textbox for the user to enter commands to send to a console application, A button to confirm the commands to be sent and A read-only textbox to display the output from the application. What I want is for the user to enter commands in the first textbox, press the button to enter and receive feedback via the second textbox. I know how to use ProcessStartInfo.RedirectStandardOutput but, however, the app hangs when I use StandardOutput.ReadToEnd() . I had a look

How do I use ProcessStartInfo to run a batch file?

十年热恋 提交于 2019-11-26 17:05:45
问题 But it doesn't work -meaning the java code is not executed. Although the batch file runs fine when clicked in Windows explorer or when run in command line .. Since this works fine when the batch file is a single DOS command, I think this is somehow related to the fact that the Java code needs ~20 minutes to run. I'm using the following code var si = new ProcessStartInfo(); si.CreateNoWindow = true; si.FileName = batchFileName; si.UseShellExecute = false; Process.Start(si); What am I doing

Set environment variables for a process

孤者浪人 提交于 2019-11-26 13:09:25
问题 What is the environment variable concept? In a C# program I need to call an executable. The executable will call some other executables that reside in the same folder. The executables rely on the two environment variables \"PATH\" and \"RAYPATH\" to be set correctly. I tried the following two things: I created a process and set the two varables in StartInfo. The variables exist already but are missing the needed information. I tried to set the variables with System.Environment

running msbuild programmatically

*爱你&永不变心* 提交于 2019-11-26 09:29:05
问题 I am trying to execute msbuild programically and cant execute the following command: string command = string.Format(@\"C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe \"\"{0}\\{1}.csproj\"\"\", _args.ProjectPath, _args.ProjectName); the string gets rendered as: C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe \"C:\\...\\TestResults\\Foo 2011-08-31 16_29_40\\Out\\Foo\\solutionName\\projectName\\projectName.csproj\" I then use new ProcessStartInfo(command). The

Elevating privileges doesn&#39;t work with UseShellExecute=false

会有一股神秘感。 提交于 2019-11-26 08:29:49
问题 I want to start a child process (indeed the same, console app) with elevated privileges but with hidden window. I do next: var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location) { UseShellExecute = true, // ! Verb = \"runas\", }; var process = new Process { StartInfo = info }; process.Start(); and this works: var identity = new WindowsPrincipal(WindowsIdentity.GetCurrent()); identity.IsInRole(WindowsBuiltInRole.Administrator); // returns true But UseShellExecute = true creates

Executing Batch File in C#

社会主义新天地 提交于 2019-11-26 03:14:11
问题 I\'m trying to execute a batch file in C#, but I\'m not getting any luck doing it. I\'ve found multiple examples on the Internet doing it, but it is not working for me. public void ExecuteCommand(string command) { int ExitCode; ProcessStartInfo ProcessInfo; Process Process; ProcessInfo = new ProcessStartInfo(\"cmd.exe\", \"/c \" + command); ProcessInfo.CreateNoWindow = true; ProcessInfo.UseShellExecute = false; Process = Process.Start(ProcessInfo); Process.WaitForExit(); ExitCode = Process

ProcessStartInfo hanging on “WaitForExit”? Why?

馋奶兔 提交于 2019-11-26 03:13:32
问题 I have the following code: info = new System.Diagnostics.ProcessStartInfo(\"TheProgram.exe\", String.Join(\" \", args)); info.CreateNoWindow = true; info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; info.RedirectStandardOutput = true; info.UseShellExecute = false; System.Diagnostics.Process p = System.Diagnostics.Process.Start(info); p.WaitForExit(); Console.WriteLine(p.StandardOutput.ReadToEnd()); //need the StandardOutput contents I know that the output from the process I am