'Cannot return value of "%~n1" from %1 argument (filename from path)

I'm trying to add a rule (name) to the firewall by this command in the registry (context menu):

[HKEY_CLASSES_ROOT\exefile\shell\Firewall\shell\Block\command]
@="netsh advfirewall firewall add rule name=\"%~n1\" dir=out action=block program=\"%1\""

%1 is the path name of the program which is returned just fine.

For some reason, I cannot get the "%~n1" part right. It just returns "%~n1" instead of filename without extension.

What is wrong?

Thanks,



Solution 1:[1]

@Squashman thanks, I ended up using cmd.exe which actually gives access to the %~n part, like this

[HKEY_CLASSES_ROOT\exefile\shell\Firewall\shell\Block\command]
@="cmd.exe /s /c for %%a in (\"%1\") do netsh advfirewall firewall add rule name=\"%%~na\" dir=out action=block program=\"%1\""

With the benefit of being able to return more than one element with "for"...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 a15995