How to automatically launch CMD window in batch in Win 10 with ForceV2 set to 0 in the registry?

Discussion in 'Scripting' started by RemixPL1994, Jan 24, 2023.

  1. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #1 RemixPL1994, Jan 24, 2023
    Last edited by a moderator: Jan 26, 2023
    How to start a CMD window in Win 10/11 immediately with the ForceV2 parameter to 0 in the registry in a batch script but so that the initial setting of ForceV2 (which is 1 by default) is immediately reset automatically to the previous original value of 1.

    It's exactly about the HKEY_CURRENT_USER\Console\ForceV2 entry that was added with Windows 10 and is set by default to 1 - enabled.

    Thus:

    1. I would like my batch script to run immediately after starting the CMD window with the ForceV2 value to 0 (old CMD window appearance).

    2. After applying ForceV2 to 0 on my batch script and after launching the CMD window, the original value of ForceV2 should return to the registry settings in the system at 1.

    3. The code should check at the beginning whether the ForceV2 key value already exists in the registry, so that when it detects that it is not there - in this case it will not apply any changes and will simply proceed without any interference.
    It must be so, otherwise it will create a ForceV2 entry in the registry on Windows Vista, Windows 7 and 8.1 systems - where the ForceV2 parameter does not appear at all.

    I found this code here by searching all over the internet:

    https://www.reddit.com/r/Batch/comments/hmhjqc/change_current_font_from_batch_file/

    Code:
    @echo OFF
    IF "%1" == "" (
        >NUL REG ADD HKCU\Console\GameEngine /v FaceName /t reg_sz /d "Lucida Console" /f
        START "GameEngine" "%~0" 1
        EXIT
    ) else ( >NUL REG DELETE HKCU\Console\GameEngine /f )
    
    ECHO Hello, I'm in a different font^!
    PAUSE
    EXIT
    
    But as you can see, it applies specifically to the selection of the font, and not to the selection of the old CMD console window, i.e. ForceV2 set to 0 (where by default in Windows 10 it is with ForceV2 to 1).

    Is anyone able to outline for me how my code should look like so that all my recommendations are implemented and work correctly for me?

    For example, in the code example shown here, there is else ( >NUL REG DELETE HKCU\Console\GameEngine /f ) where you can see that the registry value is permanently deleted.

    I need to find another solution that instead of permanently deleting the ForceV2 entry will reset it to the default value of 1, but at the same time, in systems where it does not occur, it will not make any changes and go to the next part of the script.

    From what I understand, you will need a code that first checks if ForceV2 exists, then checks if its value is 1. And if it is 1, it will change it to 0 and my script will finally run with the appearance of the old CMD console. - but immediately after applying the changes, the value of ForceV2 in the system registry, when my script starts, will switch to the original, default value, i.e. 1

    I've tried to research it myself and do it but I fail all the time. I keep missing something or it just doesn't work at all. E.g.

    [​IMG]

    I tried many times but either my script doesn't run at all due to errors. Either it gets stuck in a continuous loop and opens infinitely many new CMD windows for me, or it just doesn't work the way I want it to work properly. I've tried START, cmd c and k and others but I don't have enough knowledge to construct all the code correctly to make everything right.

    I also tried some other combinations and code variations to do this but I failed and I don't want to paste all the failed examples here but I would like to emphasize that I don't come to the forum for a quick ready solution and I tried trial and error to do it myself before - including I don't know what else to try, so I'm asking for help here.

    @wilenty @abbodi1406 @Windows_Addict

    Does any of you know what I mean and can give me some pointers on how to do it?

    @AveYo

    Hello, I tagged you too because I suspect you might be able to do it. Surely you remember that there was an unpleasant conversation and exchange between us on the forum. I remember that too. I didn't have any bad intentions then, I was just looking for answers because I didn't know what was wrong with me. It wasn't a direct attack on you to accuse you unfairly. Later, thanks to your answers, I was able to explain everything and solve the case. Negative emotions were not needed but I can't undo it now to change it. If you choose to ignore me and not answer anything here, then I understand that that case still makes you resentful or offended at me and you prefer not to talk at all. But I hope that's not the case.
     
  2. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    450
    10
    #2 berr1sfueller, Jan 24, 2023
    Last edited by a moderator: Jan 26, 2023
    It works with:
    Code:
    @echo OFF
    REG ADD HKCU\Console /v FaceName /t reg_sz /d "Lucida Console" /f
    start cmd.exe
    PAUSE
    EXIT
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    @berr1sfueller

    Yes, it works for the selected font. But I want to apply this for parameter new CMD window / old CMD window I don't know how to do it exactly.

    [​IMG]
     
  4. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    450
    10
    When a cmd window opens, it references the registry settings with regard to fonts, size, etc and applies settings to said cmd window. The settings need to altered before opening the cmd window. If it's changing between runs, then something else could be altering those settings.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #5 RemixPL1994, Jan 24, 2023
    Last edited: Jan 24, 2023
    (OP)
    I would like the CMD window to open with ForceV2 set to 1 (as it is by default in windows 10), then add the ForceV2 value to 0 in the registry and either open a new CMD window or refresh my current one so that I see the old CMD window look when I open my file script. I don't know how and how to reload. I tried with start cmd /c and k etc but then it opens a new CMD window but it doesn't display my further part of the code where GOTO menu is entered... I don't know how to do it, but I believe it can be done somehow.

    EDIT:

    I also think maybe it can be done this way?

    I open 1.bat which inside adds value

    reg add HKEY_CURRENT_USER\Console /v ForceV2 /t REG_DWORD /d 0 /f

    and then has the command start 2.bat

    2.bat opens which already has the old CMD console window automatically applied.

    But how to do it to:

    first - the changes were not made permanently ro registry forever?

    I want the changes in ForceV2 to 0 to be only temporary applied only to a specific one of my CMD windows launched to the script

    and not all of them forever.

    So there must be something that will set this value and fire up the CMD window with the old look but also auto-default and reset it back to 1 again.

    In addition, he cannot create the ForceV2 key value or change it in the system, e.g. windows 7, because there is no such parameter.

    I'm still trying but I don't know how to put it together.
     
  6. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    450
    10
    Maybe I don't understand. I would change the fonts instead whatever old console setting you're talking about.
    Run this and press enter:
    Code:
    @ECHO OFF
    FOR /F "TOKENS=3" %%a in ('REG QUERY "HKCU\Console" /v FaceName ^| findstr /r "FaceName"') do (SET "FaceName=%%a")
    IF %FaceName%==Courier REG ADD HKCU\Console /v FaceName /t reg_sz /d "Lucida Console" /f>NUL&GOTO JUMPERS
    IF %FaceName%==Lucida REG ADD HKCU\Console /v FaceName /t reg_sz /d "Courier New" /f>NUL&GOTO JUMPERS
    :JUMPERS
    ECHO %FaceName%&PAUSE
    START CMD /C "%0"
    EXIT 0
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #7 RemixPL1994, Jan 24, 2023
    Last edited: Jan 24, 2023
    (OP)
    I just don't get it, why should I change the font? I only care about the ForceV2 parameter and I want the font to stay as it always is...

    Look here:
    [​IMG]

    On the left is the new CMD window from windows 10, and on the right is the old CMD window from windows 7, etc. Firing the old look and the new look changes the display of my script. I am looking for a solution to make the appearance of the console always look the same on all systems, i.e. XP, Vista, Win7, 8 and 8.1 and also 10 and 11.
     
  8. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    450
    10
    Have no idea what you want. Someone else can handle this
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,760
    5,223
    120
    #9 Dark Dinosaur, Jan 24, 2023
    Last edited: Jan 24, 2023
    do not copy paste something .....
    without understand ... what is does !!!???

    upload_2023-1-24_20-3-25.png

    upload_2023-1-24_20-3-35.png

    anyway.
    this is the key.
    you need to restart the console,
    after make the changes.

    upload_2023-1-24_20-6-5.png
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    @Dark Dinosaur


    Is it possible to create a batch script that will have the code to change the ForceV2 value to 0 inside and automatically restart the console so that the changes are visible without manually closing and reopening? Something like this can be done with obtaining administrator privileges, taking full rights over the registry, etc So I think there is also some way to automate it using a batch script and inside with the appropriate code and commands.
     
  11. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    16,226
    84,913
    340
    ForceV2 seems a global parameter,
    for the change to have effect, all consoles must be restarted externally (not from cmd.exe itself)

    maybe try calling vbs script which relaunch your cmd script (after you change ForceV2)
     
  12. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    450
    10
    #12 berr1sfueller, Jan 25, 2023
    Last edited: Jan 25, 2023
    This seems to work for me:
    Code:
    @ECHO OFF
    FOR /F "TOKENS=3" %%a in ('REG QUERY "HKCU\Console" /v ForceV2 ^| findstr /r "ForceV2"') do (SET "ForceV2=%%a")
    IF %ForceV2%==0x0 REG ADD HKCU\Console /v ForceV2 /t REG_DWORD /d "1" /f>NUL&GOTO JUMPERS
    IF %ForceV2%==0x1 REG ADD HKCU\Console /v ForceV2 /t REG_DWORD /d "0" /f>NUL&GOTO JUMPERS
    :JUMPERS
    ECHO %ForceV2%&PAUSE
    START CMD /C "%0"
    EXIT 0
    
    [​IMG]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #13 RemixPL1994, Jan 25, 2023
    Last edited: Jan 27, 2023
    (OP)
    @abbodi1406 Can you show me how to do it with vbs?

    I remember you once gave me a way to launch a .vbs file so that another launched .vbs will launch and do its job invisible without popups etc

    This works very well for me to this day :D

    If it's possible to bring up the CMD window again / reset it while the script is running with start file.vbs then I could use that - then I could see ForceV2 override changes to 0 (from 1 before)

    But at the moment I have no idea how to get it.


    @berr1sfueller It also seems to work for me as you have shown, but how do I get the script to go on to the GOTO command and display my menu with ForceV2 ready at 0?

    Where should I put the GOTO menu so that I can select my choice and proceed to further commands:

    [​IMG]
     
  14. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    Can I get any more tips and news? Regards.
     
  15. Dark Dinosaur

    Dark Dinosaur X Æ A-12

    Feb 2, 2011
    3,760
    5,223
    120
    write cmd script, which start another PS1 script -
    that check registry, change values, etc. etc.
    and than start another cmd script ..
    ( stupid idea i ever think of .. )
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. berr1sfueller

    berr1sfueller MDL Senior Member

    Nov 17, 2022
    413
    450
    10
    Put this at the start:
    Code:
    FOR /F "TOKENS=3" %%a in ('REG QUERY "HKCU\Console" /v ForceV2 ^| findstr /r "ForceV2"') do (
    IF "%%a"=="0x1" REG ADD HKCU\Console /v ForceV2 /t REG_DWORD /d "0" /f>NUL&START CMD /C "%0"&EXIT)
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  17. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #17 RemixPL1994, Jan 30, 2023
    Last edited: Jan 30, 2023
    (OP)
    When I read that I thought "that's a good idea" but the next thing was "how do I do it, it's blowing my brains out thinking" :eek:


    Hello! It worked 100% as I wanted. For a long time I tried to do it in different ways and there was always something wrong. But it's fine now. I just need a little to make the whole idea come true.

    The most important thing is that when I launch the CMD console with ForceV2 set to 1 in the register, it automatically changes it to 0 and changes in appearance are immediately visible in the launched console of my script.

    I've additionally added a reference to the GOTO main_menu

    And in :main menu before other commands I added:

    Code:
    REG ADD "HKEY_CURRENT_USER\Console" /V "ForceV2" /T REG_DWORD /D "1" /F >NUL 2>&1
    Thanks to this, the CMD console starts automatically with ForceV2 to 0, but when the script itself starts running, ForceV2 returns to its original value of 1.

    In addition, ForceV2 is only in Windows 10 / 11 and is not in XP, Vista, Win7, Win 8.1 so I copied your code and added one command from REG ADD again to 1 only to the Windows 10 / 11 section.

    The script runs and detects what operating system it ran on and if it is Win 10 / 11 it uses your code, and if all other earlier systems it does not include this additional code on ForceV2 because it is unnecessarily and skipped.

    Thank you very much for your help @berr1sfueller .I thought I would never be able to do it again.

    Result: