News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Get Last Shutdown Date & Time

Started by mariø, December 22, 2004, 09:56:27 AM

Previous topic - Next topic

mariø

I post the code I have make that works, but I want to know if there are any type of optimitation in te process to convert the date and the time into a string.


.386

.model flat, stdcall

option casemap:none

include windows.inc
include kernel32.inc
include user32.inc
include advapi32.inc
includelib user32.lib
includelib kernel32.lib
includelib advapi32.lib

.data
Caption db "Last Shutdown",0
sKey db "System\CurrentControlSet\Control\Windows",0
sValueName db "ShutdownTime",0
szFormat   db "%d",0
rtype        DWORD REG_BINARY
ftLength   DWORD sizeof FILETIME

.data?
buff      db 255 dup(?)
hKey     DWORD ?
ft    FILETIME <?>

GetFileToSystemDate PROTO       
.code
start:
Invoke RegOpenKeyEx,HKEY_LOCAL_MACHINE, ADDR sKey, NULL, KEY_READ,ADDR hKey
.If (eax== ERROR_SUCCESS )
  .If (hKey != NULL)
      invoke RegQueryValueEx, hKey, ADDR sValueName, NULL, ADDR rtype,ADDR ft,ADDR ftLength
     .If (EAX == ERROR_SUCCESS)
          invoke GetFileToSystemDate
          invoke MessageBox, NULL,addr buff, addr Caption, MB_OK
     .EndIf   
     invoke RegCloseKey, hKey
  .EndIf   
.EndIf

Invoke ExitProcess,NULL


GetFileToSystemDate PROC
   
 LOCAL bst:SYSTEMTIME ;'system (UNC) time
 LOCAL blt:SYSTEMTIME ;'local time
 LOCAL tz:TIME_ZONE_INFORMATION
 
 invoke FileTimeToSystemTime,ADDR ft,ADDR bst
 .If eax
    invoke GetTimeZoneInformation,ADDR tz
    invoke SystemTimeToTzSpecificLocalTime, ADDR tz,ADDR bst, ADDR blt
     
    invoke GetDateFormat, NULL, DATE_LONGDATE, ADDR blt, NULL, ADDR buff, sizeof buff
    mov edx,sizeof buff
    sub edx,eax;avalaible size

    lea eax,[buff+eax-1]
    mov byte ptr [eax]," "
    inc eax
    invoke GetTimeFormat ,NULL,TIME_FORCE24HOURFORMAT,ADDR blt,NULL,eax ,edx   
 .EndIf

Ret
GetFileToSystemDate EndP


end start


Tedd

I don't think there's a general winAPI function for it, although you'd think there should be!
Alternatively, what I tend to do is just use wsprintf and extract the hours, mins, sec, etc.
Unfortunately, you have to take a check on which way around the day/month/year go, so it starts getting messy.
I'm sure there's a C function that does exactly what you want, so you could always try examining the source code for that ;)
No snowflake in an avalanche feels responsible.

Relvinian

Mario,

What you have works well to convert the file timestamp to a displayable string.  I know of no other way to get that information and create a displayable string with it. This is really pretty short code. Just a few API calls.

Relvinian