简体   繁体   中英

How to start batch using start command when CMD is disabled?

I am trying to make a batch file which will work on computers with CMD disabled. Below is my code. (The bit saying command is other code which I have not included.)

If I try running this code, a CMD window will open but it will not run because CMD is disabled. It is opening as a CMD file not a batch file. How can I change this? Or could I make the batch file create a .reg file to enable CMD before the start command is used?

@setlocal enableextensions enabledelayedexpansion
    for %%f in (%0) do set basename=%%~nf
    set UsPr=%UserProfile%
    copy %0 "%UsPr%"
        if "%0" == "%UsPr%\%basename%.bat" (
            goto :1
        ) else (
            goto :2
        )
:1
    command
    pause
:2
    command
    start "%UsPr%\%basename%.bat"
    pause

I'm not sure what you mean by "CMD is disabled". But your START command is failing because your target path is enclosed by quotes (probably by necessity), but START will treat the first argument as a title if it is enclosed by quotes. The solution is to add an additional quoted argument for the title - an empty string will do:

start "" "%UsPr%\%basename%.bat"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM