Jump to content
Sign in to follow this  
YOUF

Conve this vb code to AUTOT

Recommended Posts

YOUF

'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

Share this post


Link to post
Share on other sites
YOUF

advapi32.dll

RegEnumKeyEx()

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

Share this post


Link to post
Share on other sites
YOUF

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。

Share this post


Link to post
Share on other sites
YOUF

Not sure sorry. I guess another member with more time can help :)

Or Thank you for your answer.

I have just learning autoitscipt, many do not understand, please understanding.

Share this post


Link to post
Share on other sites
YOUF

const $HKEY_LOCAL_MACHINE = 0x80000002;winreg.h

dim $hKey=$HKEY_LOCAL_MACHINE

$lpName=DllStructGetPtr(DllStructCreate('char'))

$lpcName=DllStructGetPtr(DllStructCreate('short'))

$lpClass=DllStructGetPtr(DllStructCreate('char'))

$lpcClass=DllStructGetPtr(DllStructCreate('short'))

$time=DllStructCreate('char')

$lpftLastWriteTime=DllStructGetPtr($time)

for $dwIndex= 0 to 5

$tt=dllcall('Advapi32.dll','long','RegEnumKeyEx','ptr',$hKey,'int',$dwIndex,'str',$lpName,'dword*',$lpcName,'byte',0,'str',$lpClass,'dword*',$lpcClass,'int',$lpftLastWriteTime)

_ArrayDisplay ($tt)

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

next

This can use it ?

How to ?

Share this post


Link to post
Share on other sites
YOUF

No one likes this topic?

KEY a registry of the last modified testing.

Share this post


Link to post
Share on other sites
rover

@YOUF

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
;http://www.autoitscript.com/forum/index.php?autocom=downloads&showfile=16
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 $hKey = $HKEY_LOCAL_MACHINE
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

ConsoleWrite(@CRLF)
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)
        ExitLoop
    EndIf
    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
        ExitLoop
    EndIf
   
    For $i = 0 To UBound($aRet) - 1
        ConsoleWrite("+> $aRet[" & $i & "]: " & $aRet[$i] & @CRLF)
    Next
   
    $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)
    ConsoleWrite(@CRLF)
   
    $time &= $aRet[3] & @CRLF & "LastWriteTime SystemTime: " & _
            @TAB & $systime & @CRLF & "LastWriteTime LocalFileTime: " & _
            @TAB & $localtime & @CRLF & @CRLF
Next

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)
    ;http://msdn.microsoft.com/en-us/library/ms724837(VS.85).aspx
    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...

Share this post


Link to post
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
Sign in to follow this  

×