Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 13, 2019 4:27 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Registry read installdate problem
PostPosted: Fri Sep 02, 2011 12:31 pm 
Offline

Joined: Sun Jul 17, 2011 7:14 am
Posts: 8
[I posted this earlier but in the general-general topics; I should have posted it here instead ... oh well...]


Trying to read the Windows Registry value for the InstallDate at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
No problem with most values, except for the InstallDate - and I don't know what I'm doing wrong here.

I can read similar var types from the registry with the following code:

// REG_DWORD from this call work ok
Dim cpuSpeed As String
dim platformid As string
dim ProcessorNumber As Integer = 0
'
dim areg as new RegistryItem( "HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\" + CStr( ProcessorNumber ) )
'
if areg <> Nil then
cpuSpeed = areg.Value( "~MHZ" )
platformid = areg.Value("Platform ID")
end if


But when I try the following code for the OS InstallDate using the following code:

dim instdate As string
dim sysInfo As string
dim cv As String
dim reg as new RegistryItem("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion")

if reg <> Nil then
sysInfo = reg.Value("ProductName")
cv = reg.Value( "CurrentVersion" )
// dim mb As MemoryBlock = reg.Value("InstallDate") ' IllegalCastException
instdate = reg.Value("InstallDate") ' Get '0'
end if


I get the illegalcastexception if I try the memoryblock, and I get nothing but '0' for the value in instdate? Everyone has an InstallDate entry, and I did check (it's a REG_DWORD type) - with a hex on the left and number on the right (no different than other similar types I can read successfully as in the first code sample).

I'm hoping it's something obvious ... :|


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Sat Sep 03, 2011 2:20 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
If you're running on a 64 bit version of Windows, then RB apps (which are 32 bit) automatically have a number of registry and filesystem calls redirected by Windows. For example, the particular key you're interested in is redirected to HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\InstallDate

For whatever reason, this key is set to zero.

RealStudio, as far as I know, doesn't provide a way to signal Windows that it should turn off this redirection. You'll have to do it yourself. It looks like you'd have to call directly into the Registy API using the KEY_WOW64_32KEY flag; RB's RegistryItem class isn't going to cut it.



That is, of course, assuming that you're on a 64 bit Windows.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Sat Sep 03, 2011 2:21 am 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Edit button is gone...


Here's the link to the page about KEY_WOW64_32KEY.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Sun Sep 04, 2011 10:53 am 
Offline

Joined: Sun Jul 17, 2011 7:14 am
Posts: 8
Thanks for the wow information; works great. However, the data is in a compressed format;

Using Regedit.exe you don't really see a date in the InstallDate in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\InstallDate; you see a hex number followed by a long number:

Example: InstallDate 0x4DF0FBC9 (1307638729)

Of course the number is the converted hex number; I read the install date and got 4 bytes. Using AscB, they are: 201, 251, 240,77, which in hex are C9, FB, F0, 4D (byte for byte flip).

How do I convert that to a date? Is there some code out there?


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Sun Sep 04, 2011 12:06 pm 
Offline

Joined: Sat Dec 20, 2008 5:09 am
Posts: 32
Location: Austria, Vienna
Hello,

this is a UNIX timestamp, the installation date in seconds since 1.1.1970.

Dim DateInstall As New Date(1970,1,1)
DateInstall.TotalSeconds = DateInstall.TotalSeconds + 1307638729
MsgBox DateInstall.LongDate

For correct date you must add timezone.

Peter


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Mon Sep 05, 2011 7:07 am 
Offline

Joined: Sun Jul 17, 2011 7:14 am
Posts: 8
Thanks.

Since I read the bytes, I can convert each byte using hex("77") to get 4D; build a full string with each byte to 4DF0FBC9.

I can use Hex(1307638729) to get 4DF0FBC9, but I can't find a function to read 4DF0FBC9 into 1307638729. It might be in there, but I haven't found it.


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Mon Sep 05, 2011 9:15 am 
Offline

Joined: Sun Jul 17, 2011 7:14 am
Posts: 8
It's probably in there somewhere, but it's faster to make my own hex to integer

Here my function for it:

Function HexToNumber(HexNumber as String) as Int32
'
' Hex to integer
'
HexNumber = Uppercase(HexNumber)
dim L as integer = len(HexNumber)
dim i, c As integer
dim retval As int32
dim hexarray() As string = array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F")

for i = L-1 downto 0
c=c+1
retval = retval + (16^i) * hexarray.IndexOf(mid(HexNumber,c,1))
next

return retval


Thanks again,


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Mon Sep 05, 2011 11:52 am 
Offline

Joined: Sat Dec 20, 2008 5:09 am
Posts: 32
Location: Austria, Vienna
Hello,

here's another possibility:
Dim iDecimal As Int32
iDecimal = CType(Val("&h" + "4DF0FBC9"), Int32)
MsgBox Str(iDecimal) + " = 1307638729"

Peter


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Mon Sep 05, 2011 4:45 pm 
Offline

Joined: Sun Jul 17, 2011 7:14 am
Posts: 8
That's much simpler - thanks - didn't think about using ctype


Top
 Profile  
Reply with quote  
 Post subject: Re: Registry read installdate problem
PostPosted: Mon Sep 05, 2011 5:51 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Ctype isn't the part that makes it work. That just suppresses a compiler warning. The important part is Val() with &h.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group