[VB] Laatste defrag datum ophalen

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • baskabas
  • Registratie: December 2000
  • Laatst online: 01-10 15:19
Bij Windows 98 heb je bij je drive properties een tools tablad waarop staat hoeveel dagen geleden het is dat er gedefragementeerd is.

Hoe lees ik dit uit in Visual Basic (6.0)?

google groups: [url="http://"]"vb+defrag+date"[/url]
- Where are the last run scandisk and defrag settings stored?
(de registry key die hierin genoemd zijn bestaan niet op de 98 clients)

msdn: "Visual Basic"+last+defragmentation+date... 1 Result... handig! |:(

Ik heb ook nog op www.vb2themax.com gekeken... zonder resultaat. ;(

Dus als iemand mij een manier (knowledgebase, code, regkey...) kan geven... GRAAG! ;)

Acties:
  • 0 Henk 'm!

  • baskabas
  • Registratie: December 2000
  • Laatst online: 01-10 15:19
Een collega heeft de key inmiddels gevonden! :)
code:
1
2
3
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\explorer\LastOptimize]
"C"=hex:d2,07,03,00,04,00,07,00,0e,00,14,00,39,00,ca,03
"D"=hex:d2,07,03,00,04,00,07,00,0e,00,15,00,37,00,98,03

Maar ik heb geen id hoe ik dat nu weer vertaal naar een datum...

Dit heb ik op Google gevonden:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Check Drive\LastCheck]
 "C"=hex:d0,07,01,00,01,00,03,00,06,00,13,00,1c,00,ca,03,00,00

 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\Check Drive\LastSurfaceAnalysis]
 "C"=hex:cf,07,0a,00,00,00,18,00,13,00,03,00,1b,00,d4,03,00,00

 The first 8 bytes get you the date last run:
 1-2: year
    val("&H07")*256+val("&Hd0")=2000 (first entry above)
    val("&H07")*256+val("&Hcf")=1999 (second entry above)
 3-4: month
    val("&H00")*256+val("&H01")=1
    val("&H00")*256+val("&H0a")=10
 5-6: ??
 7-8: day
    val("&H00")*256+val("&H03")=3
    val("&H00")*256+val("&H18")=24
 The entries above show a standard scandisk check on Jan 3, 2000 and a
 thorough scandisk run on Oct 24, 1999

Andere key's en waarden, maar het princiepe zou iig ook moeten werken... maar hoe krijg ik die hex string uit de registry... ik krijg alleen maar rare tekens terug... kan ik die omrekenen zodat ik weer een hex-code terug krijg?

Acties:
  • 0 Henk 'm!

Verwijderd

Hier is een stukje code te vinden m.b.t. het uitlezen van de registry: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=1881

Ik neem aan dat je daarmee wel verder komt. Zo niet, dan moet je wat duidelijker maken wat het probleem is, wat je al geprobeerd hebt, etc, met jouw code erbij.

Enjoy :)

Acties:
  • 0 Henk 'm!

  • baskabas
  • Registratie: December 2000
  • Laatst online: 01-10 15:19
Tis me al gelukt... ik had al een DLL-etje die allerlij registry zaken kan afhandelen...

Ik zal hier ook ff posten hoe ik het opgelost heb, zodat meer mensen daar gebruik van kunnen maken. :)

1. Registry key uitlezen als Byte String
2. Byte String omzetten in een HEX String
3. HEX String omrekenen naar een datum

Functie om een Byte String om te zetten naar een HEX String
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Private Function Byte2Hex(x As String) As String
  If x > "" Then
    Dim t As String
    Dim i As Integer, n As Integer
    t = ""
    'Loop through each byte
    For i = 1 To Len(x)
    ' Get the high nibble of the byte
    n = (Asc(Mid(x, i, 1)) And &HF0) \ &H10
    ' Add the Hex character
    t = t & Mid("0123456789ABCDEF", n + 1, 1)
    ' Get the low nibble
    n = Asc(Mid(x, i, 1)) And &HF
    ' Add the Hex Character
    t = t & Mid("0123456789ABCDEF", n + 1, 1)
    Next i
    Byte2Hex = t
  Else
    Byte2Hex = "0"
  End If
End Function

Functie om een HEX String te vertalen naar een Datum
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Private Function Hex2Date(strHex As String) As Date
  Dim v1 As Byte, v2 As Byte, v3 As Byte, v4 As Byte, v7 As Byte, v8 As Byte
  Dim iYear As Integer, iMonth As Byte, iDay As Byte
  
  v1 = CLng("&H" & Mid(strHex, 1, 2))
  v2 = CLng("&H" & Mid(strHex, 3, 2))
  v3 = CLng("&H" & Mid(strHex, 5, 2))
  v4 = CLng("&H" & Mid(strHex, 7, 2))
  v7 = CLng("&H" & Mid(strHex, 13, 2))
  v8 = CLng("&H" & Mid(strHex, 15, 2))
   
  iYear = v2 * 256 + v1
  iMonth = v4 * 256 + v3
  iDay = v8 * 256 + v7
  
  Hex2Date = iDay & "-" & iMonth & "-" & iYear

End Function

Et Voila! 8-)