Registry Manipulation

AutoIt

Q #1: How do you save an uninstall string value in a variable, and run it?
      For example

      ;Check's for the uninstall string of Acrobat 3.01
      RegRead, Acrobat3, REG_DWORD, HKEY_LOCAL_MACHINE, Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Adobe Acrobat 3.01, UninstallString

      ;Runs the Uninstall for Acrobat 3.01
      Run, Acrobat3

      I tried to run with the variable Acrobat3 and %Acrobat3 but none work.

      ---------------------------------------------------------------------

A #1: I think the type of the uninstall entry is REG_SZ

-----------------------------------------------------------------------------

Q #2: How can I read/write default entries to/from the registry?

      ---------------------------------------------------------------------

A #1: To read/write a default entry from/to the registry use      the RegRead
      or RegWrite command and fill in a blank, where the ValueName is
      required.  The following is wrong because the word "(Default)" is
      specified at the end.  Use an empty string ("") or simply nothing at
      all instead of (Default).
     
      RegRead, version, REG_SZ, HKEY_LOCAL_MACHINE,
            SOFTWARE\\Classes\\Classes\\BureauVanDijk\\Promedia\\Version,
            (Default)

      The line should be:
     
      RegRead, version, REG_SZ, HKEY_LOCAL_MACHINE,
            SOFTWARE\\Classes\\Classes\\BureauVanDijk\\Promedia\\Version,
            ""

      - OR -

      RegRead, version, REG_SZ, HKEY_LOCAL_MACHINE,
            SOFTWARE\\Classes\\Classes\\BureauVanDijk\\Promedia\\Version,

----------------------------------------------------------------------

Q #3: How do I delete a registry key?

      ---------------------------------------------------------------------

A #1: To delete a registry Value, use the AutoIt command: RegDelete.
      To delete a registry  Key, use reg.exe from the resource kit.
      For example, mine is in d:\2kreskit:

      Run, D:\\2kreskit\\reg.exe delete
            HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer

      (BTW, please don't execute the above line, it's just an example,
      the 'Explorer' key is pretty useful to keep around)

      The command syntax is:
     
      C:\>reg delete /?

      Registry Console Tool For Windows 2000 - version 2.0
      Copyright (C) Microsoft Corp. 1981-1999.  All rights reserved

      REG DELETE KeyName [/v ValueName | /ve | /va] [/f]

        KeyName    [\\Machine\]FullKey
          Machine  Name of remote machine - omitting defaults to the
             current machine
             Only HKLM and HKU are available on remote machines
          FullKey  ROOTKEY\SubKey
          ROOTKEY  [ HKLM | HKCU | HKCR | HKU | HKCC ]
          SubKey   The full name of a registry key under the selected
             ROOTKEY
        ValueName  The value name, under the selected Key, to delete
                   When omitted, all subkeys and values under the Key
                 are deleted
        /ve        delete the value of empty value name <no name>
        /va        delete all values under this key
        /f         Forces the deletion without propmt

      Examples:

        REG DELETE HKLM\Software\MyCo\MyApp\Timeout
          Deletes the registry key Timeout and all of its subkeys and
          values

      Note: With reg.exe you can delete registry keys remotely. The
      command-line syntax is:

      reg delete [ROOTKEY\]Key[\Value] [\\Machine]

      Parameters in square brackets are optional

        REG DELETE \\ZODIAC\HKLM\Software\MyCo /v MTU
          Deletes the registry value MTU under MyCo on ZODIAC

      ---------------------------------------------------------------------

A #2: this isn't possible without calling an external program from AutoIt.
      i.e. use Kixtart,

      ; ======= Kixtart Scriptlet Starts Here =======

      ...
      delkey("HKEY_LOCAL_MACHINE\Software\Something")
      ...
      ; ======= Kixtart Scriptlet Ends Here =======

      and then call the kixtart script from within AutoIt like this:
     
      runwait,%COMSPEC% /c kix32.exe mykixscript.kix,,

-----------------------------------------------------------------------------

Q #4: I need a way that doesn't need an external executable,  What can I
      write in a .REG file

      ---------------------------------------------------------------------

A #1: I remember that I read that this works:

      ====== Begin .REG-File ======

      REGEDIT4

      [-HKEY_LOCAL_MACHINE\Software\Something]

      ====== End .REG-File ========

      then call

      runwait, %COMSPEC% /c regedit /s MyRegFile.reg,,

      The "-" symbol in front of the key is what tels regedit to delete the
      key.

-----------------------------------------------------------------------------

Q #5: Is there a way from AutoIt to secure a Registry key?

      ---------------------------------------------------------------------

A #1: there's no built-in command in AutoIt, but you can do this with the
      command line utility regini.exe from the NT Resource Kit. At:

      http://www.jsiinc.com/subb/tip0700/rh0723.htm


      The following article can be found.

      0723  A better way to set registry permissions on a key and its'
      sub-keys, in batch. Supplement Two of the NT 4.0 Server Resource Kit
      contains Regini which will allow you to set registry permissions in
      the HKEY_LOCAL_MACHINE and HKEY_USERS hives. Regini reads a script
      file, which for our purposes, contains a single record in the
      \Registry\Key [ACL] syntax:

      \Registry - A constant.

      Key:
            \Machine = HKEY_LOCAL_MACHINE
            \User = HKEY_USERS

      [ACL] - The ACL is a list of numbers, separated by spaces, within
      square brackets. The numbers represent the following permissions:
 
      1.    Administrator Full
      2.    Administrator R
      3.    Administrator RW
      4.    Administrator RWD
      5.    Creator Full
      6.    Creator RW
      7.    World Full
      8.    World R
      9.    World RW
      10.   World RWD
      11.   Power Users Full
      12.   Power Users RW
      13.   Power Users RWD
      14.   System OpFull
      15.   System OpRW
      16.   System OpRWD
      17.   System Full
      18.   System RW
      19.   System R
      20.   Administrator RWX

      Examples:
      \Registry\Machine\System\CurrentControlSet\ENUM [1 8 17]
      will grant:
      1  - Administrator Full Control,
      8  - Everyone Read, and
      17 - System Full Control.

      \Registry\User\S-1-5-21-2053067395-480382929-641664369-1001\
      Software\Strange Software Thingy [1 8 17] - Same as above.

      \Registry\Machine\System\CurrentControlSet\ENUM [8 17] -
      Will remove the Administrator group from the first example.

      REG (from the Resource Kit Supplement, not the freeware at tip 170)
      has a Query option that will allow you to display keys and sub-keys.
      The JSIRegS.bat file will apply the specified ACL to the Key and its'
      sub-keys. The usage is:

      JSIRegS ScriptFile1 [ScriptFile2 ScriptFile3 . . . ScriptFileN]

      JSIRegS.bat contains:

      @echo off
      :check
      PushD <Path to Resource Kit>
      if exist %TEMP%\JSIRegS.log del /q %TEMP%\JSIRegS.log
      if exist %TEMP%\JSIRegS.ini del /q %TEMP%\JSIRegS.ini
      if /i "%1"=="" goto syntax
      if exist %1 goto parse
      :syntax
      @echo INI file %1 not found or contains an invalid entry.
      goto end
      :hku
      set reg=%reg:\Registry\User=HKU%
      set reg=%reg:\registry\user=HKU%
      if /i "%reg%"=="%savekey%" goto Ssyntax
      goto key
      :parse
      for /f "Tokens=1-2* Delims=[]" %%i in (%1) do set reg=%%i!&set sec=%%j
      set reg=%reg: !=%
      set savekey=%reg%
      set reg=%reg:\Registry\Machine=HKLM%
      set reg=%reg:\registry\machine=HKLM%
      if /i "%reg%"=="%savekey%" goto hku
      :key
      regini %1
      set reg="%reg%"
      reg query %reg% /s >> %TEMP%\JSIRegS.log
      for /f "Tokens=*" %%i in ('findstr /b "[" %TEMP%\JSIRegS.log') do call :mkini "%%i"
      POPD
      set reg=
      set savekey=
      set sec=
      set sub=
      if exist %TEMP%\JSIRegS.log del /q %TEMP%\JSIRegS.log
      SHIFT
      if "%1"=="" goto end
      goto chck
      :mkini
      set sub=%1
      set sub=%sub:[=%
      set sub=%sub:]=%
      set sub=%sub:"=%
      @echo %savekey%\%sub% [%sec%] > %TEMP%\JSIRegS.ini
      regini %TEMP%\JSIRegS.ini
      del %TEMP%\JSIRegS.ini
      :end