I want to start an application from console, using a specific user account, but without a window being shown. I have gone through multiple Stack Overflow articles on this subject, but none of the suggested solutions seem to work for me. I can start the application, but I cannot prevent a window from popping up when passing username/password.
I managed to get the following code to run on my computer (Windows 10), but it fails to work on the target machine (Windows 7).
Target framework: .NET 4.5.2
Code is executed in a windowless WPF application using output type Console Application, as normal console applications failed to work.
private void StartProcess(string appPath, string user, SecureString password, string domain)
{
var processStartInfo = new ProcessStartInfo
{
FileName = appPath,
WorkingDirectory = Path.GetDirectoryName(appPath),
CreateNoWindow = true,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
Password = password,
UserName = user,
Domain = domain,
RedirectStandardError = false,
RedirectStandardOutput = false
};
Process.Start(processStartInfo);
}
My application will be started from console and the target is also a console app.
How can I ensure that the process is run in the background without a window appearing under Windows 7?
Some of the articles:
- Hide console window from Process.Start C#
- C# I can't get CreateNoWindow to work - not even the msdn.com example
- .NET - WindowStyle = hidden vs. CreateNoWindow = true?
- When do we need to set UseShellExecute to True? (some info on UseShellExecute)
- C# New process window does not hide (doesn't quite apply as I am not executing a script)