How can I run a windows batch file but hide the command window?

前端 未结 10 1832
情深已故
情深已故 2020-11-30 01:40

How can I run a windows batch file but hiding the command window? I dont want cmd.exe to be visible on screen when the file is being executed. Is this possible?

相关标签:
10条回答
  • 2020-11-30 02:32

    1,Download the bat to exe converter and install it 2,Run the bat to exe application 3,Download .pco images if you want to make good looking exe 4,specify the bat file location(c:\my.bat) 5,Specify the location for saving the exe(ex:c:/my.exe) 6,Select Version Information Tab 7,Choose the icon file (downloaded .pco image) 8,if you want fill the information like version,comapny name etc 9,change the tab to option 10,Select the invisible application(This will hide the command prompt while running the application) 11,Choose 32 bit(if you select 64 bit exe will work only in 32 bit OS) 12,Compile 13,Copy the exe to the location where bat file executed properly 14,Run the exe

    0 讨论(0)
  • 2020-11-30 02:33

    Native C++ codified version of Oleg's answer -- this is copy/pasted from a project I work on under the Boost Software License.

    BOOL noError;
    STARTUPINFO startupInfo;
    PROCESS_INFORMATION processInformation;
    ZeroMemory(&startupInfo, sizeof(startupInfo));
    startupInfo.cb = sizeof(startupInfo);
    startupInfo.dwFlags = STARTF_USESHOWWINDOW;
    startupInfo.wShowWindow = SW_HIDE;
    noError = CreateProcess(
        NULL,                                           //lpApplicationName
        //Okay the const_cast is bad -- this code was written a while ago.
        //should probably be &commandLine[0] instead. Oh, and commandLine is
        //a std::wstring
        const_cast<LPWSTR>(commandLine.c_str()),        //lpCommandLine
        NULL,                                           //lpProcessAttributes
        NULL,                                           //lpThreadAttributes
        FALSE,                                          //bInheritHandles
        CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT,  //dwCreationFlags
        //This is for passing in a custom environment block -- you can probably
        //just use NULL here.
        options.e ? environment : NULL,                 //lpEnvironment
        NULL,                                           //lpCurrentDirectory
        &startupInfo,                                   //lpStartupInfo
        &processInformation                             //lpProcessInformation
    );
    
    if(!noError)
    {
        return GetLastError();
    }
    
    DWORD exitCode = 0;
    
    if (options.w) //Wait
    {
        WaitForSingleObject(processInformation.hProcess, INFINITE);
        if (GetExitCodeProcess(processInformation.hProcess, &exitCode) == 0)
        {
            exitCode = (DWORD)-1;
        }
    }
    
    CloseHandle( processInformation.hProcess );
    CloseHandle( processInformation.hThread );
    
    0 讨论(0)
  • 2020-11-30 02:34

    Use Bat To Exe Converter and compile the Bat file as an executable.

    Steps:

    1. Open Bat to Exe Converter
    2. Select your Bat file
    3. In the options select "Invisible Application"
    4. Finish by pressing the compile button
    0 讨论(0)
  • 2020-11-30 02:38

    To self-hide already running script you'll need getCmdPid.bat and windowoMode.bat

    @echo off
    
    echo self minimizing
    call getCmdPid.bat
    call windowMode.bat -pid %errorlevel% -mode hidden
    
    echo --other commands--
    pause
    

    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.

    0 讨论(0)
提交回复
热议问题