-2

I've done some Googling but haven't found what I need yet.

I set up the default program for .bat files to call an editor, so when I double click on a .bat file I want to edit it. But when I right click on it, I want to choose a menu item to run it. After I made this change, then I right click the .bat file and choose "Open", apparently the default action is "Edit", so the file is edited again.

How do I right click the .bat file to get it to run? It sets some path and other vars and opens a cmd window. (It's for Strawberry Perl Portable on a flash drive.)

When I renamed the file to end with .cmd, and did right click, Open, the file ran but the cmd window did not stay open, it closed immediately. The batch file line with command is cmd /K.

Summary: I want the right click menu to be able to run any batch file, even though the default program sends the .bat file to an editor.

Thank you. I very much appreciate your help. The problem started 24 hours ago with 2, yes 2, bad flash drives (same Sandisk model), and my development on this flash drive has been stopped ever since, trying various fixes and reinstalls.

Bulrush
  • 548
  • 2
  • 4
  • 19

1 Answers1

1

Please read Customizing a Shortcut Menu Using Static Verbs:

Optionally, you can define a default verb for the file type by making it the default value of the Shell subkey.

The Shell uses the first available verb in the following order:

  1. The default verb.
  2. The first verb in the registry, if the verb order is specified
  3. The Open verb
  4. The Open With verb

If none of the verbs listed is available, the operation fails.

For instance, in next scenario, the default verb for .bat file type is open:

==> assoc .bat
.bat=batfile

==> ftype batfile
batfile="%1" %*

==> reg query HKEY_CLASSES_ROOT\batfile\shell /s

HKEY_CLASSES_ROOT\batfile\shell
    (Default)    REG_SZ    (value not set)

HKEY_CLASSES_ROOT\batfile\shell\edit

HKEY_CLASSES_ROOT\batfile\shell\edit\command
    (Default)    REG_EXPAND_SZ    %SystemRoot%\System32\NOTEPAD.EXE %1

HKEY_CLASSES_ROOT\batfile\shell\open
    EditFlags    REG_BINARY    00000000

HKEY_CLASSES_ROOT\batfile\shell\open\command
    (Default)    REG_SZ    "%1" %*

HKEY_CLASSES_ROOT\batfile\shell\print

HKEY_CLASSES_ROOT\batfile\shell\print\command
    (Default)    REG_EXPAND_SZ    %SystemRoot%\System32\NOTEPAD.EXE /p %1

HKEY_CLASSES_ROOT\batfile\shell\runas
    HasLUAShield    REG_SZ

HKEY_CLASSES_ROOT\batfile\shell\runas\command
    (Default)    REG_EXPAND_SZ    %SystemRoot%\System32\cmd.exe /C "%1" %*

HKEY_CLASSES_ROOT\batfile\shell\runasuser
    (Default)    REG_SZ    @shell32.dll,-50944
    SuppressionPolicyEx    REG_SZ    {F211AA05-D4DF-4370-A2A0-9F19C09756A7}
    Extended    REG_SZ

HKEY_CLASSES_ROOT\batfile\shell\runasuser\command
    DelegateExecute    REG_SZ    {ea72d00e-4960-42fa-ba92-7792a7944c1d}

When changed only shell subkey default value, the default verb for .bat file type becomes edit:

==> reg query HKEY_CLASSES_ROOT\batfile\shell /ve

HKEY_CLASSES_ROOT\batfile\shell
    (Default)    REG_SZ    edit

This change does not affect current instance of file explorer; you need to restart file explorer (or even the Shell?) to take it in effect.

JosefZ
  • 28,460
  • 5
  • 44
  • 83