Discussion:
Reading registry key date and time
(too old to reply)
Tometa
2004-12-22 10:10:04 UTC
Permalink
Hi!
I need to read and convert date and time stored in registry key
LastSyncTime:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\NetCache
\Shares\ShareName]
"LastSyncTime"=hex:30,3f,6e,13,99,e6,c4,01 (It is 20.12.2004 14:37)
in readable string.
Anyone knows how to do that?

Thanks for any help!
--
"domena" = "sfsb" for e-mail
Dr John Stockton
2004-12-22 22:34:18 UTC
Permalink
JRS: In article <***@news.carnet.hr>, dated Wed,
22 Dec 2004 11:10:04, seen in news:microsoft.public.scripting.wsh,
Post by Tometa
Hi!
I need to read and convert date and time stored in registry key
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\NetCache
\Shares\ShareName]
"LastSyncTime"=hex:30,3f,6e,13,99,e6,c4,01 (It is 20.12.2004 14:37)
in readable string.
Anyone knows how to do that?
Dates & times always need to be given a time zone indication.

Reverse the characters, convert to decimal which is in 100 ns units, and
add that to 1601-01-01 00:00:00 GMT.

Stick the following in
<URL:http://www.merlyn.demon.co.uk/js-quick.htm#Ev>,
press Eval, and read the local version of the date/time represented.

Answer = new Date(0x01c4e699136e3f30/1E4 + +new Date(1601,0,1,0,0,0))

I see Mon Dec 20 13:37:40 UTC 2004 - but I'm in England and you are,
presumably, in Croatia where, if you follow EU rules, the time is always
an hour later.

That's javascript. The same basic method should work in VBS, but I do
not know how to do conversion from Hex to number. Well, searching News,
I don't know about long Hex, but, using the VBS button,

Days = (&H01c4e699*&H10000*&H10000 + &H136e3f30)/(1E7*86400)
document.write CDate(DateSerial(1601, 1, 1) + Days)

gives me 2004-12-20 13:37:40 ; I guess that, since zone is disregarded,
you'd get the same GMT time.

There may, of course, be a routine in the WSH language library to do it.

HTH,
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Tometa
2004-12-23 07:56:52 UTC
Permalink
Post by Dr John Stockton
Stick the following in
<URL:http://www.merlyn.demon.co.uk/js-quick.htm#Ev>,
press Eval, and read the local version of the date/time represented.
Answer = new Date(0x01c4e699136e3f30/1E4 + +new Date(1601,0,1,0,0,0))
Thank you very much, John!
Tometa
2004-12-23 09:49:07 UTC
Permalink
U <***@merlyn.demon.co.uk>, ***@merlyn.demon.co.uk
napisa...
Post by Dr John Stockton
Answer = new Date(0x01c4e699136e3f30/1E4 + +new Date(1601,0,1,0,0,0))
I am not sure how to read and convert. Tried this way:
-----
var WshShell = WScript.CreateObject ("WScript.Shell"), bkey, str;
var bkey = new VBArray (WshShell.RegRead("HKCU\\Software\\Microsoft
\\Windows\\CurrentVersion\\NetCache\\AdminPinStartTime"));
//"AdminPinStartTime"=hex:65,e3,ed,ff,67,e6,c4,01
str = new String ();
for (i=6; i>0; i--)
{
str=str+bkey.getItem(i);
}
var db = str.valueOf()/1e4
var dat = new Date(db+ +new Date(1601,0,1,0,0,0));
WScript.Echo (dat);
-----
It gives me
"Thu Oct 31 04:12:05 UTC+0100 2222". But should be "Mon Dec 20 07:46:22
UTC+0100 2004" buy http://www.merlyn.demon.co.uk/js-quick.htm#Ev.
Can you perhaps help me in reading?

Many thanks!
Tometa
2004-12-23 17:55:59 UTC
Permalink
Post by Tometa
Can you perhaps help me in reading?
Well, help yourself and... here it is:
----------
// Reading binary date/time key
// Reaplace !!ShareName!! with actual
var WshShell = WScript.CreateObject ("WScript.Shell");
var binkey = new VBArray (WshShell.RegRead("HKCU\\Software
\\Microsoft\\Windows\\CurrentVersion\\NetCache\\Shares
\\//gal/PODACI\\LastSyncTime"));
var singleElement = new Number;
var regString = new String ("0x");
//merging array in one string backward
for (i=7; i>=0; i--)
{
singleElement=binkey.getItem(i);
regString=regString+singleElement.toString(16);
}
//testing line, should be like registry value backward
//WScript.Echo (regString);
var LastSync = new Date(regString.valueOf()/1E4 + +new Date
(1601,0,1,1,0,0));
WScript.Echo (LastSync);
--------------
--
"domena" = "sfsb" for e-mail
Dr John Stockton
2004-12-23 19:52:14 UTC
Permalink
JRS: In article <***@merlyn.demon.co.uk>, dated Wed, 22
Dec 2004 22:34:18, seen in news:microsoft.public.scripting.wsh, Dr John
Post by Dr John Stockton
22 Dec 2004 11:10:04, seen in news:microsoft.public.scripting.wsh,
Post by Tometa
Hi!
I need to read and convert date and time stored in registry key
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\NetCache
\Shares\ShareName]
"LastSyncTime"=hex:30,3f,6e,13,99,e6,c4,01 (It is 20.12.2004 14:37)
in readable string.
Anyone knows how to do that?
Dates & times always need to be given a time zone indication.
Reverse the characters, convert to decimal which is in 100 ns units, and
add that to 1601-01-01 00:00:00 GMT.
There is, now (assuming a successful upload), a general Gregorian GMT
Timescale Interconverter at the end of section
<URL:http://www.merlyn.demon.co.uk/dayscale.htm#Zero>, using
javascript.

Time units : 100 ns 1 us 1 ms 1 s 1 day 1 week

Anyone needing it frequently, please take a copy of the page to run on
your own machine. Someone could maybe do it in VBS.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Loading...