Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How to convert the value stored in Reg_Binary into Date/Time?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,30907
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to convert the value stored in Reg_Binary into Date/Time?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How to convert the value stored in Reg_Binary into Date... - 2/10/2006 4:04:02 AM   
  vetterke

 

Posts: 2
Score: 0
Joined: 2/10/2006
From: Ghent, Belgium
Status: offline
How to convert the value stored in Reg_Binary into Date/Time?

For example the Last ShutDownTime is stored into the registry:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Windows]
"ShutdownTime"=hex:44,a5,0f,47,c9,2c,c6,01
This should be converted into YYYY-MM-DD HH:MM:SS
I did found a function in VB 6.0. but didn't succeed to make a script that return the preferred value.
Things I think are related, but can't succeed put them into a bvscript:
- A file time is a 64-bit value that represents the number of 100-nanosecond intervals that have elapsed since 12:00 A.M. January 1, 1601 Coordinated Universal Time (UTC).
- http://www.rlmueller.net/Last%20Logon.htm
Does anyone knows about this issue and has a solution?
Tnx,
kris
 
 
Post #: 1
 
 RE: How to convert the value stored in Reg_Binary into ... - 2/10/2006 4:16:29 AM   
  ebgreen


Posts: 5070
Score: 31
Joined: 7/12/2005
Status: online
Could you post the VB code you found?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to vetterke)
 
 
Post #: 2
 
 RE: How to convert the value stored in Reg_Binary into ... - 2/10/2006 5:00:32 PM   
  Cybex


Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
What exactly is your goal?  A few things to think about:

The registry is only updated if the system is shutdown properly. If the power plug is pulled, the time will show the last time stamp that the system was properly shutdown. So this may not be the best way to do whatever it is you are trying to do. 

If you can live with last boot time you can do something like this:

      

I tried to convert the registry but couldn't figure out how to convert the value.  Here is what I tried.

      

The strValue(i) for my system is: "196148971052192301971".

Hope some of this helps.

Cybex

_____________________________

Common sense is not so common.

(in reply to vetterke)
 
 
Post #: 3
 
 RE: How to convert the value stored in Reg_Binary into ... - 2/13/2006 5:51:27 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
vetterke, I tried a few things and the next code works for me


      

Good luck !

_____________________________

Regular Expression ? I (L+o{1,}v{1,3}e\s)+[iI]t!$

(in reply to Cybex)
 
 
Post #: 4
 
 RE: How to convert the value stored in Reg_Binary into ... - 2/20/2006 1:15:21 AM   
  vetterke

 

Posts: 2
Score: 0
Joined: 2/10/2006
From: Ghent, Belgium
Status: offline
Tnx all for replying...

I received an solution from someone...
Function dtmDate(RegParam)

'read from the registry using getbinaryvalue
Const HKEY_CLASSES_ROOT  = &H80000000
Const HKEY_CURRENT_USER  = &H80000001
Const HKEY_LOCAL_MACHINE  = &H80000002
Const HKEY_USERS   = &H80000003
Const HKEY_CURRENT_CONFIG  = &H80000005
Dim a(7), oRegistry, oMethod, oInParam, oOutParam, objShell

Select Case RegParam
 Case 1
  sComputer = "."
  sMethod  = "GetBinaryValue"
  hTree  = HKEY_CURRENT_USER
  sKey  = "Software\Microsoft\Windows\CurrentVersion\NetCache\Shares\//vcn/vce-bebruroot\"
  sValue  = "LastSyncTime"
 Case 2
  sComputer = "."
  sMethod  = "GetBinaryValue"
  hTree  = HKEY_CURRENT_USER
  sKey  = "SOFTWARE\MICROSOFT\OFFICE\9.0\Outlook\Options\Backup\"
  sValue  = "last_backup"
 Case 3
   sComputer = "."
  sMethod  = "GetBinaryValue"
  hTree  = HKEY_LOCAL_MACHINE
  sKey  = "system\ControlSet001\Control\Windows"
  sValue  = "ShutdownTime"
End Select

Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
  sComputer & "/root/default:StdRegProv")
Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = hTree
oInParam.sSubKeyName = sKey
oInParam.sValueName = sValue
 
Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
For iCount = 0 To UBound(oOutParam.Properties_("uValue"))
 'WScript.Echo oOutParam.Properties_("uValue")(iCount)
 a(iCount)=oOutParam.Properties_("uValue")(iCount)
Next

' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
  & "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
  lngBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
  lngBias = 0
  For k = 0 To UBound(lngBiasKey)
    lngBias = lngBias + (lngBiasKey(k) * 256^k)
  Next
End If

'here after blend into rmueller's demonstration
on error resume next
lngHigh=0
lngLow=0
for i=7 to 4 step -1
    lngHigh=lngHigh*256+a(i)
next
for i=3 to 0 step -1
    lngLow=lngLow*256+a(i)
next

if err.number<>0 then
    dtmDate = #1/1/1601#
    err.clear
else
    If lngLow < 0 Then
        lngHigh = lngHigh + 1
    End If
    If (lngHigh = 0) And (lngLow = 0 ) Then
        dtmDate = #1/1/1601#
    Else
        dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
            + lngLow)/600000000 - lngBias)/1440
    End If
End If
on error goto 0
End Function


This wat i needed to use the dates that some programs use to save date/time in the registry

(in reply to didorno)
 
 
Post #: 5
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> How to convert the value stored in Reg_Binary into Date/Time? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts