User Tools

Site Tools


windows

Windows

Map directory as drive

subst r: "d:\my path\directory"

Run programs hidden

Run programs without visible console.

:!: Warning: Quick&Dirty, only use in trusted environments.

ShellExecuteHidden.c
#include <windows.h>
 
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow )
{
    if (_argc < 2) {
        MessageBox(0, "You have to specify the file to start as a command-line argument.", "ShellExec",  MB_ICONEXCLAMATION);
        return 1;
    }
 
    LPSTR cmd = _argv[1];
    LPSTR param = NULL;
    LPSTR workdir = NULL;
 
    if (_argc > 2) {
        param = _argv[2];
    }
    if (_argc > 3) {
        workdir = _argv[3];
    }
 
    HINSTANCE hAppInstance = ShellExecute(0, "open", cmd, param, workdir, SW_HIDE);
 
    if ((int)hAppInstance <= 32) {
        MessageBox(0, "Error calling 'ShellExecute'. The document cannot be started.", "ShellExec", MB_ICONEXCLAMATION);
        return 2;
    }   
 
    return 0;
}
gcc -mwindows -o ShellExecuteHidden ShellExecuteHidden.c

Download ShellExecuteHidden.exe

windows.txt · Last modified: 2010-07-27 22:13 CEST by dominik