Reputation:
I would like to launch one of my apps inside a .bat file but it is visible and taking up space in my taskbar. How do i launch the app and not have it visible?
Upvotes: 2
Views: 678
Reputation: 57262
Here I've compiled all ways that I know to start a hidden process with batch without external tools.With a ready to use scripts (some of them rich on options) , and all of them form command line.Where is possible also the PID is returned .Used tools are IEXPRESS,SCHTASKS,WScript.Shell,Win32_Process and JScript.Net - but all of them wrapped in a .bat
files.
Upvotes: 0
Reputation: 5613
If your not afraid to use Perl then this will do the trick
use Win32::GUI;
Win32::GUI::Hide(scalar(Win32::GUI::GetPerlWindow()));
Upvotes: 0
Reputation: 993223
Here's a utility I wrote years ago to do this:
#include <windows.h>
#pragma comment(lib, "user32.lib")
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
const char *p = GetCommandLine();
if (*p == '"') {
p++;
while (*p && *p != '"') {
p++;
}
p++;
} else {
while (*p && *p != ' ') {
p++;
}
}
while (*p == ' ') {
p++;
}
if (*p == 0) {
MessageBox(NULL, "Usage: nocli <command>\nExecute <command> without a command prompt window.", "nocli Usage", MB_OK);
return 1;
}
//if (MessageBox(NULL, p, "nocli debug", MB_OKCANCEL) != IDOK) return 1;
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
if (CreateProcess(NULL, const_cast<char *>(p), NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi)) {
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD exitcode;
GetExitCodeProcess(pi.hProcess, &exitcode);
CloseHandle(pi.hProcess);
return exitcode;
} else {
MessageBox(NULL, "Error executing command line", "nocli", MB_OK);
return 1;
}
return 0;
}
No guarantees, but it worked for me in one situation at one time. :)
Upvotes: 2
Reputation: 1012
Assuming you want to open an application and have the DOS prompt go away immediately, use start <command>
in your .bat file instead of just <command>
Upvotes: 1