Archive: Getting the current date at install time


Getting the current date at install time
:confused:
I am trying to write a shareware application and I need to get the current date on installation and record it. I have written a small C++ program that does this but I would prefer to get the installer to do it. Is there anyway to get the current date on installation? or is it possible to write a C++ program that can be run using ExecWait that returns the date?


At the moment you can't get the current date from NSIS. But it's possible to write your own little NSIS extension dll for that. There is an example in Contrib/ExDLL, in Contrib/NSISdl and my extension for executing mci commands stays here :).

~ Florian


How about this (requires NSIS 1.90+, though with a little modification you can make it work in earlier versions):


GetTempFileName $R0 ; creates a file, assigns name to $R0
GetFileTime $R0 $R1 $R2
Delete $R0
; $R1 is high dword of current time
; $R2 is low dword of current time


-Justin

thanks Justin - my first thought was to get the creation time for the .exe file but that wasn't working because I stuffed my C++ code up. I thought that there was something wrong with the way I was using the NSIS GetFileTime function but when I saw that you used it in your post I went back over it and realised my application's code was stuffed.

I tried your solution too F. Heidenreich but it wouldn't compile - it came up with the dreaded "LNK2001: unresolved external symbol _main" error. I did it as a Win32 Dynamic Link Library project in Visual C++ 6 so I don't understand why it wouldn't accept _DLLMainCRTStartup instead. I also found that exdll didn't compile either - it had the same link error.However your extension (nsisext_mci) compiled and linked perfectly. Has anyone else encountered this error using Visual C++ 6 to compile exdll or any extension of their own making?


The solution for the linker prob is to enable the checkbox 'Project->Settings->Linker->General->Ignore all default libraries'.

If you get the 'error LNK2001: unresolved external symbol __chkesp', remove the /GZ from the compiler switches.

~ Florian


To Help anyone else who has a similar problem: :)
Here's the code I used with NSIS version 1.81. The date is stored in $R1 and $R2 and these values can be written to the registry or a file or whatever. The 2 variables $R1 and $R2 form the 2 variables of a win32 FILETIME structure.Create a FILETIME structure in your C++ program and initialize it with the values of these 2 variables (wherever you stored them). The FILETIME struct can then be manipulated to turn it into a SYSTEMTIME structure or a CTime object.

;get current time by creating a temp file and reading it's time stamp
;make a new file in the temp directory
SetOutPath "$TEMP"
File "new file"
SetOutPath "$INSTDIR"
;get it's time stamp
GetFileTime "$TEMP\new file" $R1 $R2
; $R1 is high dword of current time
; $R2 is low dword of current time
;delete our new file (it's purpose has been served)
Delete "$TEMP\new file"


New Extension
I've written a dll extension that will handle this. See the other thread.

Rob