Search code examples
windowsregistryright-clickwindows-installer

remove extension from a filename variable


I have a script which adds an 'extract' option to the right click menu for when I right click on a windows installer package. im using a variable for where the name of the file is however when it extracts it it is still adding the extention to the folder and gives an error that a file with that name already exists so, how do I have it so it does not use the file extension in the extracted folder name.

Here's my Script:

REG ADD HKCU\software\classes\msi.package\shell\extract\command
@="msiexec.exe /a \"%1\" /qb targetdir=\"%1\""

Maybe there's some char to go back 4 chars (.msi is 4 chars long) Regards, Snipe


Solution

  • Instead of writing the "msiexec.exe" command directly in the registry, just use a batch file:

    e.g.

    @="D:\stickybatches\msiextract.cmd \"%1\"
    

    (IMO not necessary but possible to prefix it with "cmd.exe /c ..")

    In the batchfile it is possible to get the filename without extension. For the first parameter as needed here it is "%~n1".

    @echo off
    @msiexec /a "%1" /a /qb TARGETDIR="%~n1"
    

    Comments:

    • TARGETDIR is not the same as targetdir for MSI ! Case sensitive !!

    • As you can see in the reference, the "~" letter removes the quotes from outer call from the parameters, you can experiment, if removing it is possible. But I would recommend it like this.

    • If interested: With "&~0" and it's relatives you get the path/filename of the batch file itself. Sometimes very useful, especially for handling batch files called with admin rights. (No direct relation in this usecase you asked for, though).

    For reference for the special syntax for path/filenames in batches, see for example:

    https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true