Results 1 to 5 of 5

Thread: how to read Registry by vb6,vbs?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,937

    how to read Registry by vb6,vbs?

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
    "c:\\1.exe"="~ HIGHDPIAWARE"

    how to write Registry c:\1.exe for run as admin,xp sp3?

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,937

    Re: how to read Registry by vb6,vbs?

    VB6 calls RegSetValueEx this API, writes to the 32-bit registry, right-click properties in the resource manager, found that there is no check "run with administrator rights", compatible with XP SP3 these two items
    How to write to a 64-bit registry location.

    SaveRegStr HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", ExePath, "~ RUNASADMIN WINXPSP3"

    find data in HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,937

    Re: how to read Registry by vb6,vbs?

    VB6 calls RegSetValueEx this API, writes to the 32-bit registry, right-click properties in the resource manager, found that there is no check "run with administrator rights", compatible with XP SP3 these two items
    How to write to a 64-bit registry location.

    SaveRegStr HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers", ExePath, "~ RUNASADMIN WINXPSP3"

    find data in HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers



    File redirection can be turned off by:
    Call Wow64DisableWow64FsRedirection
    Well, what about the registry?
    Looking up a lot of information, there is very little about VB6 operating with 64-bit registries. Only API methods, such as:
    RegCreateKeyEx(lRootkey, sKeyName, 0, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS|KEY_WOW64_64KEY, SecAttr, handle, retVal)
    I don't understand, if there are a large number of registry read, write, build, delete, that also have to specify the authority of each statement?
    Many other programming languages have a more convenient switch that uses the switch instruction for 64-bit registry operations at the beginning and end of the segment.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,937

    Re: how to read Registry by vb6,vbs?

    Code:
    Private Declare Function RegCreateKeyEx Lib "advapi32" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByRef phkResult As Long, ByRef lpdwDisposition As Long) As Long
    
    WinBit = IIf(Bit <= 0, IIf(IsX64, KEY_WOW64_64KEY, KEY_WOW64_32KEY), IIf(Bit = 64, KEY_WOW64_64KEY, KEY_WOW64_32KEY))
    SafetyType.bInheritHandle = True: SafetyType.lpSecurityDescriptor = 0: SafetyType.nLength = 50 'Set security attributes to default values
    
    'Open an entry and create it if it does not exist, 
    RegCreateKeyEx is the key API to support 64-bit registry
    Goback = RegCreateKeyEx(RootType, IIf(SubkeyEvent > 0, Position, Position & "" & SubKeyName), 0&, 1&, 0&, WinBit, SafetyType, Rkey, Unknown)

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,937

    Re: how to read Registry by vb6,vbs?

    by ai chatgpt:
    How does the 32-bit vbs read and write to the 64-bit registry
    On Windows systems, VBScript is 32-bit by default and can only access 32-bit registry keys. If you need to read and write 64-bit registry keys in 32-bit VBScript, you need to use Windows Wow6432Node.

    Here is a VBScript example that demonstrates how to write data to the 64-bit registry:
    Code:
    Set oReg = CreateObject("WScript.Shell")
    sRegPath = "HKLM\SOFTWARE\Wow6432Node\YourSoftwareKey"
    sValueName = "YourValueName"
    sValue = "YourValueData"
    
    oReg.RegWrite(sRegPath & "\" & sValueName, sValue)
    In this example, we use the RegWrite method of the WScript.Shell object to write to the registry. Note the Wow6432Node in the registry path, which allows 32-bit programs to access the 64-bit registry view.

    If you need to read 64-bit registry entries, you can use the RegRead method:
    Code:
    Set oReg = CreateObject("WScript.Shell")
    sRegPath = "HKLM\SOFTWARE\Wow6432Node\YourSoftwareKey\YourValueName"
    
    sValue = oReg.RegRead(sRegPath)
    WScript.Echo sValue
    Make sure your VBScript script has sufficient permissions to access and modify the registry, usually administrator permissions are required.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width