AdrianH
Posts: 11
Joined: Tue Jun 24, 2008 1:10 pm

Date Time formatting

Hi

I need to store the date and time when the application was first installed. I have added a value to my registry key with the value "[Date] [Time]" as a REG_SZ. The installed applicaiton then uses this date and time when running. The issue we have is that we need to set the format of the date and time values when writing it to the registry so that the application can parse the string correctly and get the date and time, because depending on the regional setting of the user that installed the application, the date and time formats differ.

How can I set the formt of the date and time properties when writing to the registry.

Regards
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Date Time formatting

Hello,

I am afraid you can not specify the format in which Date and Time are provided. It will always depend on the system. It would probably be better if you stored a unix time stamp, since that is locale independent. All in all, you will most likely need to create your own custom action to retrieve the date and time, then write a property with that data and format it to your liking.

Let me know if this helps.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
AdrianH
Posts: 11
Joined: Tue Jun 24, 2008 1:10 pm

Re: Date Time formatting

Thanks for the reply, I created a custom action which runs on install that sets the registy key in VB script in the format I require. Below is the VB script i used to set the key or reference.

Code: Select all

Function setInstallDateTime()

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
 
strKeyPath = "SOFTWARE\MyApplication"
strStringName = "InstallDate"
strStringValue = Year(Now()) & "-" & Month(Now()) & "-" & Day(Now()) & " " & Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now())

oReg.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strStringName, strStringValue

End Function
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Date Time formatting

Hi Adrian,

It is best you stored your formatted date inside a property and use the Registry page for creating registries. Creating the registry from your script means it will be left uninstalled when your product is removed from the machine.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
AdrianH
Posts: 11
Joined: Tue Jun 24, 2008 1:10 pm

Re: Date Time formatting

Hi Gabriel

I am trying to implement your suggestions. I have created a property named INSTALLDATE. My property in being shown in the User Defined properties when setting the registry entry to my property. I then try update this property with the following VBScript.

Code: Select all

Function setInstallDateTime()

strStringValue = Year(Now()) & "-" & Month(Now()) & "-" & Day(Now()) & " " & Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now())
Session.Property("INSTALLDATE") = strStringValue

End Function
The installer fails with the following message, "There is a problem with this Windows Installer Package. A script required for this install to complete could not be run. Contact your support personnel or package vendor."

If I remove the line 'Session.Property("INSTALLDATE") = strStringValue', the installer runs through fine. What could the problem be?

Regards
Adrian
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Date Time formatting

Hi Adrian,

I'm sorry, I forgot to remind you that only immediate custom actions are allowed to set/create properties. Please make sure your custom action's execution option is set to "Immediate execution".
Let me know how this worked for you.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
AdrianH
Posts: 11
Joined: Tue Jun 24, 2008 1:10 pm

Re: Date Time formatting

Hi

Yes, that fixed the error from occuring, but the registry value is not being set. It keeps the value of 'NotSet' which is what I defined in the 'Edit Property' dialog as the value. The custom action VBScript execution is current under the 'Install' node of the 'InstallExecuteSequence'.

Secondly, how do I only set the registry entry on the first install? I solved it using the custom action with the '(NOT Installed) AND (NOT OLDPRODUCTS)' execution condition. The VBScript would only fire on first install which created the registry key and stored the datetime to the format I wanted. As per your reply, you said I should rather create the key in the registry page so that the installer will remove it on uninstall. Can I tell the registry value to only be set on first install?

Please advise.

Regards
Adrian
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Date Time formatting

Hello again Adrian,
Yes, that fixed the error from occuring, but the registry value is not being set. It keeps the value of 'NotSet' which is what I defined in the 'Edit Property' dialog as the value. The custom action VBScript execution is current under the 'Install' node of the 'InstallExecuteSequence'.
This is because you are setting the property too late, meaning after the registry has already been created. Try placing your custom action under InstallExecuteSequence->Begin standard action. That should do it.
Secondly, how do I only set the registry entry on the first install? I solved it using the custom action with the '(NOT Installed) AND (NOT OLDPRODUCTS)' execution condition. The VBScript would only fire on first install which created the registry key and stored the datetime to the format I wanted. As per your reply, you said I should rather create the key in the registry page so that the installer will remove it on uninstall. Can I tell the registry value to only be set on first install?
You can condition the installation of the registry value by conditioning its component. Right click the registry value and select "Go to Component". You will be taken to the component to which the registry key belongs. In the right pane, place your condition in the component's condition field. Your component will now only be installed if the condition is true, and thus so will the registry value.

Let me know if this works for you.

Best regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
AdrianH
Posts: 11
Joined: Tue Jun 24, 2008 1:10 pm

Re: Date Time formatting

Hi,
Yes, that fixed the error from occuring, but the registry value is not being set. It keeps the value of 'NotSet' which is what I defined in the 'Edit Property' dialog as the value. The custom action VBScript execution is current under the 'Install' node of the 'InstallExecuteSequence'.

This is because you are setting the property too late, meaning after the registry has already been created. Try placing your custom action under InstallExecuteSequence->Begin standard action. That should do it.
Thanks, that solved the issue.

The only other issue I have now is that on an upgrade, the above registry entry that was created and set on the first install is removed from the registry. I tried setting the condition to '(NOT Installed) AND (NOT OLDPRODUCTS)' but it is still removed on upgrade. Also tried enabling "Never Overwrite" for the registry entry but it was still removed. How can I ensure that the registry entry is only set on first install, not removed/updated on upgrades, but is removed on uninstall.

Thanks for your time in helping with my issue.
Adrian
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: Date Time formatting

Hi Adrian,

Please note that our user guide contains the Preserve registry key at install how-to which may help you.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”