I'm attempting to print off a file generated in my application using the following code:
var psi = new ProcessStartInfo("Temp.txt");
psi.UseShellExecute = true;
psi.Verb = "print";
psi.CreateNoWindow = true;
var process = System.Diagnostics.Process.Start(psi);
This works, and sends the file to the printer as expected. However, in the process, an instance of notepad opens for naught but a second. This is an application meant to run in the background, so those windows popping up are incredibly distracting.
Adding pi.WindowStyle = ProcessWindowStyle.Hidden; before the final line of the above snippet does help marginally. But still causes a brief, small popup - which drags the user out of any fullscreen application they may be in at the time.
Related
Attempting to run ntdsutil from a C# executable and encountering an error. In case anyone is wondering, this is for a automated auditing process as part of a managed service provider - not trying to create a trojan/malware.
The command is: ntdsutil "ac i ntds" "ifm" "create full c:\audit" q q
This is Windows server specific, am running on Windows 2016.
I am using System.Diagnostics.Process and have tried various combinations of properties but getting same result. The following is an example, there is a standard output redirect so can see results of execution:
Process process = new System.Diagnostics.Process();
ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = #"C:\Windows\System32\ntdsutil.exe";
startInfo.Arguments = "\"ac i ntds\" \"ifm\" \"create full c:\\audit\" q q";
//Set output of program to be written to process output stream
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError= true;
startInfo.UseShellExecute = false;
process.StartInfo = startInfo;
process.Start();
// Get program output
string strOutput = process.StandardOutput.ReadToEnd();
//Wait for process to finish
process.WaitForExit();
File.WriteAllText("out.txt", strOutput);
The output looks like this:
C:\Windows\System32\ntdsutil.exe: ifm
ifm: create full c:\audit
error 0x80042302(A Volume Shadow Copy Service component encountered an unexpected error. Check the Application event log for more information.)
ifm: q
C:\Windows\System32\ntdsutil.exe: q
Have checked event logs as mention (nothing obvious) and done various searches on error but nothing useful appears. Running the command on command line works fine.
It is running a Administrator level user. Is it possible related to app.manifest priveleges?
Any help is appreciated.
I've been using the following piece of code to directly open the Environment variables screen with a single button click:
private void OpenEnvVariables()
{
Process p = new Process();
p.StartInfo.WorkingDirectory = #"C:\Windows\System32";
p.StartInfo.FileName = "rundll32.exe";
p.StartInfo.Arguments = "sysdm.cpl,EditEnvironmentVariables";
p.StartInfo.Verb = "runas";
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
}
It was working just fine up until the moment I ran my tooling application on Windows 10. And now it does nothing.
Run can still handle sysdm.cpl but it seems that I cannot pass correctly the arguments.
Any help would be appreciated.
Update This was auto-resolved somehow, perhaps a Windows Update. It is now working fine.
Considering this code:
Process process = new Process();
process.StartInfo.FileName = "explorer";
process.StartInfo.Arguments = "\\some_network_host\path";
process.Start();
I would like to connect to a shared resource and open the path in Explorer.exe, however, the user might not be authenticated yet. If the user is not authenticated, I would like to open a Windows authentication popup just like the one I see when I run \\some_network_host\path, however, my actual code just opens "My Document" instead (if the user is not already authenticated). If the user is already authenticated, it opens the explorer.exe window showing the shared resource.
Thank you.
This code works fine for me
Process process = new Process();
process.StartInfo.FileName = #"\\existing_network_host\path";
process.StartInfo.UseShellExecute = true;
process.StartInfo.ErrorDialog = true;
process.Start();
The keey difference is true value for StartupInfo.ErrorDialog
I'm trying to start tomcat from my c# wpf app using the startup.bat and after deploying the war files, I want to close it. Here is how I've been doing it and it seemed to work fine.
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = Tomcat_DIR_tbox.Text + #"\bin\startup.bat";
proc.StartInfo.WorkingDirectory = Tomcat_DIR_tbox.Text + #"\bin\";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
// do some bla bla
//Close Tomcat
proc.StartInfo.Filename = Tomcat_DIR_tbox.Text + #"\bin\shutdown.bat";
proc.Start();
proc.WaitForExit();
Now I've been thinking that although it works, it's not quite right ? the Tomcat application started never stops unless I tell it to, it feels wrong to use the same process to also shut it down ?
What I've down now is something like this : Kept the process for starting up tomcat, and created another one which calls for the shutdown:
//Close tomcat
System.Diagnostics.Process proc_shutdown = new System.Diagnostics.Process();
proc_shutdown.StartInfo.WorkingDirectory = Tomcat_DIR_tbox.Text + #"\bin\";
proc_shutdown.StartInfo.FileName = Tomcat_DIR_tbox.Text + #"\bin\shutdown.bat";
proc_shutdown.StartInfo.CreateNoWindow = true;
proc_shutdown.Start();
proc_shutdown.WaitForExit();
The only thing I don't like about this method is that it brings a message which asks me if I allow the shutdown.bat to be called from my application, which I can uncheck "Don't ask me again for this file" but I still don't like the user experience it provides.
I also tried calling directly proc.Close() instead of doing proc.Filename = path_to_shutdown and proc.Start(), but it seemed to hang up my application and never close tomcat.
So what is the best way to start tomcat, do some stuff and then close it up ? Thanks , Razvan.
Based on my observation, what you are doing is fine to start and stop the tomcat server from WPF application. But, if you want to hide the security warning, Then Open Internet Explorer Go to Tools -> Internet Options and then select "security" tab from there select (Custom level..).. In that in the Miscellaneous group there will be option called
"Launching Applications and Unsafe files" -> Select Enable Radio button. Then it won't show you the "allow the shutdown.bat" popup.
Hope, it helps.
I have used
var psi = new ProcessStartInfo();
psi.Arguments = args;
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.FileName = path;
psi.WindowStyle = ProcessWindowStyle.Hidden;
But I am calling an executable which does 2 things. Firstly it opens new child windows, and they become visible. Second, the application also calls another .exe, which becomes visible (I want this second exe to become invisible)
How do I go about making the exe called completely hidden so no child windows become visible or no exe called by the new exe become visible.
Thanks
Thomas