Forenote:
Not a duplicate of: Unable to run vbs file from windows registry
I've just decided to write a VBScript which handles an argument. Before I start writing it, I'm testing out the argument functionality.
Currently, my script is thus:
set arg = WScript.Arguments
msgbox arg(0)
To call my script from the registry, I use:
"%windir%\system32\cscript.exe" "E:\VBScripts\Transcode & Analyse.vbs" "%1"
However, when called from the registry (through a right click context item), I am presented with an error:
I'm not quite sure why this error could occur, so any help would be appreciated!
Additional information:
When called from Command Prompt, it functions as intended - with the argument displayed in the messagebox, and no text on the titlebar.
Described error message occurs in case of misusing RegKey data type declared (REG_SZ
) versus data type saved (REG_EXPAND_SZ
):
==> reg query HKEY_CLASSES_ROOT\*\shell\T-and-A\command
HKEY_CLASSES_ROOT\*\shell\T-and-A\command
(Default) REG_SZ "%windir%\system32\cscript.exe" "E:\VBScripts\Transcode & Analyse.vbs" "%1"
You need to use either expanded path
HKEY_CLASSES_ROOT\*\shell\T-and-A\command
(Default) REG_SZ "C:\Windows\System32\cscript.exe" "E:\VBScripts\Transcode & Analyse.vbs" "%1"
or change RegKey data type to REG_EXPAND_SZ
as follows:
HKEY_CLASSES_ROOT\*\shell\T-and-A\command
(Default) REG_EXPAND_SZ "%windir%\system32\cscript.exe" "E:\VBScripts\Transcode & Analyse.vbs" "%1"
Read in reg add /?
or reg.exe: Read, Set or Delete registry keys and values how to change value of empty name (Default)
for the key to REG_EXPAND_SZ
data type.
Please use your current key name instead of T-and-A
in above examples.