njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Read file text into installer property

Hi,

I need to do the following steps within my installer:

1) Get a text string from the user (done within a custom dialog), store in a user-defined property, say [unenc_pass];
2) Run an application [embedded in the installer - not to be installed with the other files, should only be used for this stage), passing [unenc_pass] as a parameter;
- The application creates a file, say test.dat, in the [APPDIR], which is an encrypted form of [unenc_pass];
3) Read the new test.dat file into a user-defined property, let's say called [enc_pass];
4) Write that [enc_pass] string to a registry key;
5) Delete the test.dat file;

I can do each step individually like this:
1) Set password edit box property to my user-defined property [unenc_pass];
2) Custom action - run file attached to installation (run as Published Event for Next button in my custom dialog);
3) "Search" section - File Search - reading into property [ENC_PASS];
4) "Registry" section - add registry value based on [ENC_PASS];
5) "Files and Folders" section - delete test.dat;

But apart from #1 and #2, these steps run at different times during the install, so I don't think it'll work. Is there any way to do this other than writing a VBScript to do it instead? How would I do this in VBScript (i.e. launch a file attached to installation, add registry entry, etc)?

Thanks,
Nick.
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Read file text into installer property

Hi Nick and welcome to Advanced Installer forums.

Thank you for your interest in Advanced Installer.

The steps you described above are the right steps, except for the 3rd one ("Search" section - File Search - reading into property [ENC_PASS]). The "File Search" does not read the content of a file, it only search if a file exist on the machine and, if returns the path to it.

So, you need to create your own custom action (i.e. VBScript) only for this step. The custom action will read the content of the "test.dat" file, and will store it in the "ENC_PASS" property. Then you can add a "Launch attached file" custom action with sequence (which will run the VBScript file you created) and place it after "Wizard Dialogs Stage -> User Selection" action group.

This is an example of how your VBScript can look:

Code: Select all

readFile= "test.dat"
Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject") 
Set srcFile  = fso.OpenTextFile(readFile, ForReading, False)

Session.Property("ENC_PASS") = srcFile.ReadLine
Let us know if this helped, otherwise give us more details about your scenario.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
njshaw2
Posts: 26
Joined: Fri Apr 19, 2013 10:36 am

Re: Read file text into installer property

Thanks Eusebiu, that's helpful. I think I'll add the file read in as a custom action just after the file is written, and delete the file just after reading too within the VBScript to keep the number of steps to a minimum.

Thanks for the help.
Nick.
Eusebiu
Posts: 4959
Joined: Wed Nov 14, 2012 2:04 pm

Re: Read file text into installer property

You're welcome Nick. Glad to help.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”