I have Console Application written in C# that is scheduled to run every 15 min. or so using the Built in Windows Task Scheduler. Every time it runs the black console box pops up for the duration of it's execution and then closes. I am not writing anything to the console. Is there a way to make this run in the background?
If it doesn't write anything to the console you could make it a service. http://msdn.microsoft.com/en-us/library/9k985bc9%28VS.80%29.aspx
What about implementing the app into a windows service? You can set the interval to 15 mins and run the operation in the timer_tick.
Dirty as anything out there but: (From here)
the process take 3 files. one launch.bat one invis.vbs and one (your program) in launch.bat(this files runs your program silently) put in... wscript.exe "C:\yourpath\invis.vbs" "your file.bat" in invis.vbs put...
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
and finaly in your file put whatever u want...
echo off erase c:\junk.txt well your done just open up launch.bat
Works like a charm though. What it does is launch the first bat (launch.bat), which in turn launches your service/executable in stealth. So, it's a quick blip for the original launch, then gone.
You can use windows API to minimize the console box. Otherwise you can make it a Windows exe that does not actually load a form and call System.Windows.Forms.Application.Run()
Code to minimize the console
[DllImport( "user32.dll" )]
public static extern bool ShowWindow( IntPtr hWnd, int nCmdShow );
public const int SW_SHOWMINIMIZED = 2;
IntPtr winHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
ShowWindow( winHandle, SW_MINIMIZE );
Easy!
It seems hard to believe, but works as a charm. I have used this for some setup projects, when you want to perform custom tasks with no signs of it.
- Create the project as a Windows application Project (this is the hard part).
Never calls to any form, just keep on in exactly as in your console application
class Program { static void Main(string[] args) { // just dont Application.Run(new frmMain(args)); //... your code } }
This is because windows application projects are no really different than console, excepts because of the first form and references. Totally hidden execution Try it! HTH
It will only show up if it's scheduled to run as the same user that's currently logged in. Create another user on the machine with a ridiculously long password, set it to be an Administrator (only if needed) and schedule the task to run as that user.
This is easy. Set the task to run under an account that is not your login account.
Project + Properties, Application tab, change Output type to "Windows application". No more console window.