Search code examples
windowscmdautomationregistryprompt

automatically have script input yes at windows cmd yes/no prompt


I am interested in being able to automatically have my cmd input Yes at the Yes/No prompt:

                                       __
                                     .d$$b
                                   .' TO$;\
                                  /  : TP._;
                                 / .;  :Tb/
                                /   /   ;j$j
                            _.-"       d$$$$
                          .' ..       d$$$$;
                         /  /P'      d$$$$P. \\
                        /   "      .d$$$P' \\^"l
                      .'           `T$P"""""  :
                  ._.'      _.'                ;
               `-.-".-'-' ._.       _.-"    .-"
             `.-" _____  ._              .-"
            -(.g$$$$$$$b.              .'
              ""^T$$$P)            .(:
                _/  -"  /.'         /:/;
             ._.'-'`-'  ")/         /;/;
          `-.-"..--""   " /         /  ;
         .-" ..--""        -'          :
         ..--""--.-"         (\      .-(\
           ..--""              `-\(\/;`
             _.                      :
    .................................................__________...
    .... _________________________________________ ./           \\
    .___/             /..I        /_/   _____   I_ I   _______   II
    .__/ ____       //...I   ____/  I  I.....I II..I  /...II...\ II
    ../_____/      //....I   II ....I  I_____I II..I   ___II___  II
    ......./      //.....I   I____..I       ___II..I  I___II___I II
    ....../      //......I    ___/..I   I\   \\ ...I   ...II...  II
    ...../      //.......I   II ....I   I.\   \\ ..I   ...II...  II
    ..../      //_______ I   I______I_  I..\   \\ .I  \___II___/ II
    .../  ____________ /_I           /  I__.\   \\ I             II
    __/_______________/.\___________/_____/..\___\\\____________//

c:\>disablewinremotedesktop
Delete the registry value fDenyTSConnections (Yes/No)?

I have a really long .cmd file containing a large lists of DOSKEYs I have been making to speed up my computer tasks, and I am adding a few commands I know will be useful in the future based off of this registry book I have been reading in my free time.

Here is the command format:

DOSKEY disablewinremotedesktop = REG DELETE "HKLM\SYSTEM\CurrentControlSet\Control\Terminal  Server" /v "fDenyTSConnections" 
$T
REG ADD "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v "fDenyTSConnections" /t REG_DWORD /d 1

In this .cmd file I used @echo off at the beginning and end, in order to make that ASCII art picture I like so very much.

Please help me automate this process!


Solution

  • You could create a Yes.bat file with something like the following:

    @echo off
    for /L %%X in (1,1,77) do echo Yes
    

    (Replace 77 with some sufficiently large number)

    Then just run

    Yes.bat | YourCommand.bat
    

    It seems OK to have the Yes.bat command output more Yes's than required by YourCommand.bat. On Windows 7, they seem to be silently discarded...

    The above only works with batch files, and, as you pointed out, does not address your question.

    Your doskey macro can't be used in a batch file and, it seems, cannot be at the end of a pipe, so

    Yes.bat | yourDOSKeyMacro
    

    just fails.

    For your question, I can't think of a generic answer, but the prompt is coming from the REG DELETE part of the macro. You can get rid of this prompt with a /f (Force) option:

    REG DELETE "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v "fDenyTSConnections" /f

    I think that might get you most of the way there.