Portalman66
Posts: 10
Joined: Thu Jan 23, 2025 9:55 am

Password with special characters as command-line argument

Hello,

I'm having trouble passing a password. The password is entered in a dialog box during installation and then verified using an inline PowerShell script before starting the installation process. The password is passed to the script as a command-line argument: -User [USER_PROP] -Password [PASSWORD_PROP]
USER_PROP and PASSWORD_PROP are values taken straight from the dialog textfields.
PASSWORD_PROP may contain special characters such as " or ' or &. How can I pass the password if I don’t know which special characters it contains? If it starts with ", I get an error as soon as I pass it.

ERROR: At line:1 char:121
+ ... ogram Files `(x86`)\Common Files\" -User test -Password "Qwert123`&ÖÄ
+ ~~~~~~~~~~~~~
The string is missing the terminator: ".

I know it's the " in the password, but it could be a ' as well. How can I avoid the error?

Thank you for your help,

Portalman66
Catalin
Posts: 7717
Joined: Wed Jun 13, 2018 7:49 am

Re: Password with special characters as command-line argument

Hello Portalman66,

Is your custom action immediate or deferred?

If the custom action is immediate, we can try retrieving the properties via the built in cmdlets that we offer, AI_GetMsiProperty.

Here is how it looks like:

Code: Select all

$password = AI_GetMsiProperty PASSWORD_PROP
Also, such a string is hard to be passed via command line due to the double quotes as well:

Code: Select all

"Qwert123`&ÖÄ
The first quotes must be escaped or the entire string enclosed in quotes, so adding another " at the end.
Screenshot_125.png
Screenshot_125.png (133 KiB) Viewed 7591 times
Screenshot_126.png
Screenshot_126.png (10.04 KiB) Viewed 7591 times

The property is retrieved just fine via the AI_GetMsiProperty cmdlet.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Portalman66
Posts: 10
Joined: Thu Jan 23, 2025 9:55 am

Re: Password with special characters as command-line argument

Hi Catalin,

thank you for your answer. The trick was indeed to use the AI_GetMsiProperty PASSWORD_PROP because the " is no problem there and I can process the password in the following.

Thank you again for your help.

Best regards,
Portalman66
Catalin
Posts: 7717
Joined: Wed Jun 13, 2018 7:49 am

Re: Password with special characters as command-line argument

You are always welcome! :)

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”