Jump to content

Conve this vb code to AUTOT

Recommended Posts

'Option Explicit

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long

Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long

Private Const HKEY_LOCAL_MACHINE = &H80000002

Private Const REG_DWORD = 4

Dim nBufferKey As Long

Dim nVal As Long

Private Sub Form_Load()

' Create a REG_DWORD value

Dim dword As Long

dword = 2

RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey

sValueName = "SandBox"

RegSetValueEx nBufferKey, sValueName, 0, REG_DWORD, dword, Len(dword)

'nVal = 2

'If RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey) = ERROR_SUCCESS Then

' RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)

'End If

'RegOpenKey HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Jet\4.0\Engines", nBufferKey

'RegSetValueEx nBufferKey, "SandBoxMode", 0, REG_DWORD, nVal, Len(nVal)

'MsgBox "Sandbox Mode Changed", vbInformation, "Sandbox"

'RegCloseKey nBufferKey

Unload Me

End Sub

Link to comment
Share on other sites



LONG RegEnumKeyEx(

HKEY hKey,

DWORD dwIndex,

LPWSTR lpName,

LPDWORD lpcName,

LPDWORD lpReserved,

LPWSTR lpClass,

LPDWORD lpcbClass,

PFILETIME lpftLastWriteTime


PFILETIME lpftLastWriteTime is I would like to use.

information about one subkey each time it is called and it retrieves the class name of the subkey and the time it was last modified.

Edited by YOUF
Link to comment
Share on other sites

RegEnumKey() & RegEnumVal()

but the time it was last modified, Can not be read out~~~

I think that the original time of the KEY record,

When necessary, check out this KEY the time it was last modified。

Link to comment
Share on other sites

const $HKEY_LOCAL_MACHINE = 0x80000002;winreg.h








for $dwIndex= 0 to 5


_ArrayDisplay ($tt)

msgbox(0,'',_Date_Time_FileTimeToStr ($Time))


This can use it ?

How to ?

Link to comment
Share on other sites


you needed the $tagFILETIME struct for the time return

declared in StructureConstants.au3, included in Date.au3

example uses console window of SciTE editor for DllCall return and errors

Edit1: RegCloseKey return in Consolewrite was $aRet[0], should have been $aRet

Edit2: removed struct for $lpcName

#include <Date.au3>
Opt('MustDeclareVars', 1)

Local $lpcName, $tFILETIME, $tFILETIME2, $lpftLastWriteTime
Local $tSystem, $aRet, $systime, $localtime, $time, $ret

;winreg.h - see also Gary Frosts 'API constants for AutoIt' in downloads section
Global Const $HKEY_CLASSES_ROOT = 0x80000000
Global Const $HKEY_CURRENT_USER = 0x80000001
Global Const $HKEY_LOCAL_MACHINE = 0x80000002
Global Const $HKEY_USERS = 0x80000003
Global Const $HKEY_CURRENT_CONFIG = 0x80000005

;System error codes: http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx
Global Const $ERROR_NO_MORE_ITEMS = 0x103 ; 259
Global Const $ERROR_INVALID_HANDLE = 0x6

Local $lpcName = 255

$tFILETIME = DllStructCreate($tagFILETIME)
$lpftLastWriteTime = DllStructGetPtr($tFILETIME)

; for lpname the struct is created internally by dll call if str used instead of ptr
; result returned in array

For $dwIndex = 0 To 5
    $aRet = DllCall('Advapi32.dll', 'long', 'RegEnumKeyEx', _
            'long', $hKey, _
            'dword', $dwIndex, _
            'str', "", _
            'dword*', $lpcName, _
            'dword', "", _
            'ptr', "", _
            'dword', "", _
            'ptr', $lpftLastWriteTime)
    If Not IsArray($aRet) Or @error Then
        ConsoleWrite("! DllCall Error: " & @error & @CRLF)
    If $aRet[0] <> 0 Then ConsoleWrite("! System error code: " & $aRet[0] & @CRLF)
    If $aRet[0] = $ERROR_NO_MORE_ITEMS Then
        ConsoleWrite("! ERROR_NO_MORE_ITEMS: " & $aRet[0] & @CRLF)
        ; looping through 0 to 5 (6 keys), only 5 keys in LOCAL_MACHINE
        ; System error codes: http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx
    For $i = 0 To UBound($aRet) - 1
        ConsoleWrite("+> $aRet[" & $i & "]: " & $aRet[$i] & @CRLF)
    $tFILETIME2 = _Date_Time_FileTimeToLocalFileTime($lpftLastWriteTime)
    $tSystem = _Date_Time_FileTimeToSystemTime($lpftLastWriteTime)
    $systime = _Date_Time_SystemTimeToDateTimeStr($tSystem)
    $localtime = _Date_Time_FileTimeToStr($tFILETIME2)
    ConsoleWrite("-> LastWriteTime SystemTime: " & $systime & @CRLF)
    ConsoleWrite("-> LastWriteTime LocalFileTime: " & $localtime & @CRLF)
    $time &= $aRet[3] & @CRLF & "LastWriteTime SystemTime: " & _
            @TAB & $systime & @CRLF & "LastWriteTime LocalFileTime: " & _
            @TAB & $localtime & @CRLF & @CRLF

MsgBox(0, "LastWriteTime", $time)

$ret = _WinAPI_RegCloseKey($hKey)
If $ret <> 0 Then ConsoleWrite(@CRLF & "! System error code: " & $aRet & @CRLF)
If $ret = $ERROR_INVALID_HANDLE Then ConsoleWrite("! $ERROR_INVALID_HANDLE: " & $ret & @CRLF)

;A handle to the open key to be closed.
;The handle must have been opened by the RegCreateKeyEx,
;RegCreateKeyTransacted, RegOpenKeyEx, RegOpenKeyTransacted,
;or RegConnectRegistry function.
;Note: If the key is not one of the predefined registry keys,
;call the RegCloseKey function after you have finished using the handle
Func _WinAPI_RegCloseKey($hKey)
    Local $aResult
    $aResult = DllCall("advapi32.dll", "int", "RegCloseKey", "long", $hKey)
    If IsArray($aResult) Then $aResult = $aResult[0]
    Return $aResult
EndFunc   ;==>_WinAPI_RegCloseKey
Edited by rover

I see fascists...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...