3

How to hide the console from within this code? Currently the cmd console is shown everytime I run this code.

protected override void OnStart(string[] args)
{            
    String applicationName = "cmd.exe";
    // launch the application
    ApplicationLoader.PROCESS_INFORMATION procInfo;
    ApplicationLoader.StartProcessAndBypassUAC(applicationName, out procInfo);

}

How can I execute a *.bat file from here? Can I simply can substitute the "cmd.exe" with "xxx.bat"?

Jalal Said
  • 15,906
  • 7
  • 45
  • 68
karikari
  • 6,627
  • 16
  • 64
  • 79

2 Answers2

4

Add a System Reference to the code;

using System Diagnostics;

Then use this code to Hide the CMD Window and run.

Process cmd = new Process();
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
cmd.StartInfo.Arguments = "Your arguments";
cmd.Start();
Community
  • 1
  • 1
Jalal Said
  • 15,906
  • 7
  • 45
  • 68
  • 1
    the variable `cmd` is a process variable that we created `Process cmd = new Process`. try to add `using System.Diagnostics` to your solution. note also that you have to change `"Your arguments"` to the arguments that you want to pass to that process – Jalal Said Jul 27 '11 at 09:39
  • but I need to use the StartProcessAndBypassUAC function. how? – karikari Jul 27 '11 at 10:06
  • 1
    I don't own that function, and the function code is hidden from me! however you should check the properties of the `ApplicationLoader.PROCESS_INFORMATION` since your `StartProcessAndBypassUAC` method returning it "`out procInfo`". – Jalal Said Jul 27 '11 at 10:14
0

Try it with the Process Class instead of the ApplicationLoader (I´ve never heard of that class, is it a custom class?)

Code Example:

 using System.Diagnostics;

 Process pr = new Process();
 pr.StartInfo.FileName = "cmd.exe";
 pr.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
 pr.Arguments = "xxx.bat";
 pr.Start();
Andre Gross
  • 263
  • 2
  • 8