Sign in to follow this  
Followers 0
blinkdt

Generating Registry Entries Dynamically

3 posts in this topic

#1 ·  Posted (edited)

OK, you must understand, I'm the guy who barely passed that college-level logic course and to this day can't tell you what it was about. So for me, what I have been able to create thus far is nothing short of miraculous. I have been using AutoIt for several years to automate software installations for friends and neighbors. Cool. Manipulating Windows with examples from the Help file and cut-and-paste snippets is one thing, trying to create something original is quite another.

Purpose: I like to install a "dock" program created by the boys and girls at PUNK SOFTWARE. The dock is a convenient and fun way to organize shortcuts to frequently used programs. It has gone a long way toward helping me get over my MacOS envy and my reliance on an otherwise unwieldy Quick Launch toolbar. And everybody I know likes the dock, too, but we all have different software installation requirements. So it occured to me, couldn't the registry entries that comprise the dock, which are merged at the end of a typical install session, be generated dynamically based on the programs I have installed on a given machine?

Original method: The dock files are extracted to the Program Files directory using WinRAR. A shorcut to the app is created and the registry settings merged using AutoIt:

RunWait( @ScriptDir & "\RocketDock.exe")
Sleep(100)
FileCreateShortcut(@ProgramFilesDir & "\RocketDock\RocketDock.exe", @ProgramsCommonDir & "\Accessories\RocketDock.lnk")
Sleep(100)
RunWait ( @Comspec & ' /C regedit /S ' & @ScriptDir & '\settings.reg', '', @SW_HIDE )

New route: But I want to create the registry settings based on the actual programs installed on a given machine and not have to fiddle with post-install dock configuration (add this item, remove those items, etc.). Based on comments found on this board, it appeared to me that the best way to approach this was to create the entries and write them to an .ini file. A partially pre-populated .ini file is placed in the script directory:

Windows Registry Editor Version 5.00

;--------------------------------------------------------------------------------Remove OS-related Desktop Icons
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu]
;Internet Explorer
"{871C5380-42A0-1069-A2EA-08002B30309D}"=dword:00000001
;My Computer
"{20D04FE0-3AEA-1069-A2D8-08002B30309D}"=dword:00000001
;My Documents
"{450D8FBA-AD25-11D0-98A8-0800361B1103}"=dword:00000001
;My Network Places
"{208D2C60-3AEA-1069-A2D7-08002B30309D}"=dword:00000001
;Recycle Bin
"{645FF040-5081-101B-9F08-00AA002F954E}"=dword:00000001

;--------------------------------------------------------------------------------Set Dock to run at Startup
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
"RocketDock"="C:\\Program Files\\RocketDock\\RocketDock.exe"

;--------------------------------------------------------------------------------Merge general preferences
[HKEY_CURRENT_USER\Software\RocketDock-v0.9.4]
"Version"="1.1.2"
"CustomIconFolder"=""
"Theme"="ProtoSky"
"ThemeOpacity"="1"
"FontSize"="-11"
"FontFlags"="1"
"FontName"="Tahoma"
"FontColor"="16777215"
"FontCharSet"="1"
"FontOutlineColor"="0"
"FontOutlineOpacity"="55"
"FontShadowColor"="0"
"FontShadowOpacity"="25"
"IconMin"="32"
"IconMax"="96"
"ZoomWidth"="5"
"ZoomTicks"="200"
"AutoHideTicks"="101"
"AutoHideDelay"="101"
"ZoomFlat"="0"
"IconQuality"="1"
"LangID"="0"
"HideLabels"="0"
"LockIcons"="1"
"AutoHide"="1"
"zOrderMode"="0"
"MouseActivate"="0"
"UberIconFX"="0"
"Monitor"="0"
"Side"="0"
"Offset"="0"
"OptionsTabIndex"="1"

;--------------------------------------------------------------------------------Create the Dock
[HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons]
"0-FileName"="Icons\\Other\\zzMyPNGs\\WindowsExplorer.png"
"0-Title"="Windows Explorer"
"0-Command"="C:\\WINDOWS\\explorer.exe"
"0-Arguments"=""
"0-WorkingDirectory"="%HOMEDRIVE%%HOMEPATH%"
"0-ShowCmd"="0"
"0-IsSeparator"="0"
"0-UseContext"="0"
"0-DockletFile"=""
"1-FileName"="Icons\\Orbs\\XPOrbs1\\Control_Panel_Orb.png"
"1-Title"="Control Panel"
"1-Command"="::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}"
"1-Arguments"=""
"1-WorkingDirectory"=""
"1-ShowCmd"="0"
"1-IsSeparator"="0"
"1-UseContext"="0"
"1-DockletFile"=""

Each dock entry requires nine (9) separate values created in proper sequence. This AutoIt routine fills out the missing picture:

#NoTrayIcon

Dim $quote = '"', $increase1 = 1, $increase2 = 1, $increase3 = 1, $increase4 = 1, $increase5 = 1, $increase6 = 1, $increase7 = 1, $increase8 = 1, $increase9 = 1

;--------------------------------------------------------------------------------Extract Dock files to Program Files directory
Sleep(1500)
RunWait( @ScriptDir & "\RocketDock.exe")
;--------------------------------------------------------------------------------Create shortcut under Accessories on Start Menu
Sleep(1500)
FileCreateShortcut(@ProgramFilesDir & "\RocketDock\RocketDock.exe", @ProgramsCommonDir & "\Accessories\RocketDock.lnk")
;--------------------------------------------------------------------------------Copy data.ini to Temp dir and begin building
DirCreate( @WindowsDir & "\Temp\dock")
Sleep(500)
FileCopy(@ScriptDir & "\data.ini", @WindowsDir & "\Temp\dock\")
Sleep(1500)

If FileExists(@ProgramFilesDir & "\Common Files\AOL\Launch\aollaunch.exe") Then
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value1() & "-FileName" & $quote, '"Icons\\Orbs\\MiscOrbs3\\AIM_Orb_Blue.png"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value2() & "-Title" & $quote, '"AIM Triton"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value3() & "-Command" & $quote, '"C:\\Program Files\\Common Files\\AOL\\Launch\\aollaunch.exe"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value4() & "-Arguments" & $quote, '"/d suiteid=TritonGM /d locale=en-US ee://aol/imApp"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value5() & "-WorkingDirectory" & $quote, '"C:\\Program Files\\Common Files\\AOL\\Launch"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value6() & "-ShowCmd" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value7() & "-IsSeparator" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value8() & "-UseContext" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value9() & "-DockletFile" & $quote, '""')
EndIf

If FileExists(@ProgramFilesDir & "\Windows Media Player\wmplayer.exe") Then
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value1() & "-FileName" & $quote, '"Icons\\Orbs\\MiscOrbs2\\MP10_2.png"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value2() & "-Title" & $quote, '"WMP11"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value3() & "-Command" & $quote, '"C:\\Program Files\\Windows Media Player\\wmplayer.exe"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value4() & "-Arguments" & $quote, '"/prefetch:1"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value5() & "-WorkingDirectory" & $quote, '""')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value6() & "-ShowCmd" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value7() & "-IsSeparator" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value8() & "-UseContext" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value9() & "-DockletFile" & $quote, '""')
EndIf

If FileExists(@ProgramFilesDir & "\Notepad2\Notepad2.exe") Then
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value1() & "-FileName" & $quote, '"Icons\\Orbs\\MiscOrbs3\\Draw12.png"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value2() & "-Title" & $quote, '"Notepad2"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value3() & "-Command" & $quote, '"C:\\Program Files\\Notepad2\\Notepad2.exe"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value4() & "-Arguments" & $quote, '""')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value5() & "-WorkingDirectory" & $quote, '"C:\\Program Files\\Notepad2"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value6() & "-ShowCmd" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value7() & "-IsSeparator" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value8() & "-UseContext" & $quote, '"0"')
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value9() & "-DockletFile" & $quote, '""')
EndIf

;yadayadayada - more entries ending with Recycle Bin

IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value1() & "-FileName" & $quote, '"Icons\\Other\\zzMyPNGs\\Recycle Bin Empty.png"')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value2() & "-Title" & $quote, '"Recycle Bin"')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value3() & "-Command" & $quote, '"::{645FF040-5081-101B-9F08-00AA002F954E}"')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value4() & "-Arguments" & $quote, '""')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value5() & "-WorkingDirectory" & $quote, '""')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value6() & "-ShowCmd" & $quote, '"0"')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value7() & "-IsSeparator" & $quote, '"0"')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value8() & "-UseContext" & $quote, '"1"')
IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value9() & "-DockletFile" & $quote, '""')

IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", '"count"', $quote & _count() & $quote)

Sleep(1500)
;--------------------------------------------------------------------------------Create the Registry file from the .ini file
FileMove(@WindowsDir & "\Temp\dock\data.ini", @WindowsDir & "\Temp\dock\data.reg")
Sleep(1500)
;--------------------------------------------------------------------------------Merge the Registry file
RunWait ( @Comspec & ' /C regedit /S ' & @WindowsDir & "\Temp\dock\data.reg", '', @SW_HIDE )
Sleep(1500)
;--------------------------------------------------------------------------------Remove temporary files
DirRemove( @WindowsDir & "\Temp\dock", 1)
;--------------------------------------------------------------------------------Remove Office 2003 Icons from Desktop if they exist
FileDelete( @DesktopDir & "\Outlook.lnk")
Sleep(500)
FileDelete( @DesktopDir & "\Word.lnk")
Sleep(500)
FileDelete( @DesktopDir & "\Excel.lnk")
Sleep(500)
FileDelete( @DesktopDir & "\PowerPoint.lnk")
Sleep(500)
FileDelete( @DesktopDir & "\Publisher.lnk")
Sleep(500)
FileDelete( @DesktopCommonDir & "\Outlook.lnk")
Sleep(500)
FileDelete( @DesktopCommonDir & "\Word.lnk")
Sleep(500)
FileDelete( @DesktopCommonDir & "\Excel.lnk")
Sleep(500)
FileDelete( @DesktopCommonDir & "\PowerPoint.lnk")
Sleep(500)
FileDelete( @DesktopCommonDir & "\Publisher.lnk")
Sleep(1500)

Exit

Func _value1()
    $increase1 = $increase1 + 1
    Return $increase1
EndFunc

Func _value2()
    $increase2 = $increase2 + 1
    Return $increase2
EndFunc

Func _value3()
    $increase3 = $increase3 + 1
    Return $increase3
EndFunc

Func _value4()
    $increase4 = $increase4 + 1
    Return $increase4
EndFunc

Func _value5()
    $increase5 = $increase5 + 1
    Return $increase5
EndFunc

Func _value6()
    $increase6 = $increase6 + 1
    Return $increase6
EndFunc

Func _value7()
    $increase7 = $increase7 + 1
    Return $increase7
EndFunc

Func _value8()
    $increase8 = $increase8 + 1
    Return $increase8
EndFunc

Func _value9()
    $increase9 = $increase9 + 1
    Return $increase9
EndFunc

Func _count()
    $increase1 = $increase1 + 1
    Return $increase1
EndFunc


;EOF

Great! The entries are appended to the information that already exists in data.ini and the count is correct. In fact, the .ini file looks like a mirror image of an actual registry file ready to be merged as part of the install routine, quote marks and all. So "moving" the .ini file has the effect of renaming it as a .reg file. From there it is merged! If anyone has any comments regarding cleaning up the code, I'm all ears, as my experience with declarations and loops extends only to love of the opposite sex and breakfast cereal. And my many thanks to everyone who has contributed to the AutoIt project and offered comments on this board and other boards (MHz, you are an inspiration).

Edited by blinkdt

"No peace for the wicked, no rest for the good."

Share this post


Link to post
Share on other sites



Hey blinkdt,

Looks like you have been busy with this script. I do not use RocketDock or anything similar. I will point out an idea of making a function to make the script less repetative with the same data. As your IniWrite is repetitve and has most of the data is the same, then a function can help to make it more compact and efficient.

A little clip from your code

If FileExists(@ProgramFilesDir & "\Windows Media Player\wmplayer.exe") Then
    IniWrite(@WindowsDir & "\Temp\dock\data.ini", "HKEY_CURRENT_USER\Software\RocketDock-v0.9.4\Icons", $quote & _value1() & "-FileName" & $quote, '"Icons\\Orbs\\MiscOrbs2\\MP10_2.png"')
oÝ÷ Ù©Ýiû§rبëvÚ"è½è­^~éeÉ«­¢+Ø)%¥±á¥ÍÑÌ¡Aɽɵ¥±Í¥ÈµÀìÅÕ½ÐìÀäÈí]¥¹½ÝÌ5¥A±åÈÀäÈíݵÁ±åȹáÅÕ½Ðì¤Q¡¸(}%¹¥]É¥Ñ%½¹Ì¡}Ù±ÕÄ ¤µÀìÅÕ½Ðìµ¥±9µÅÕ½Ðì°ÌäìÅÕ½Ðí%½¹ÌÀäÈìÀäÈí=ÉÌÀäÈìÀäÈí5¥Í=ÉÌÈÀäÈìÀäÈí5@ÄÁ|ȹÁ¹ÅÕ½ÐìÌäì¤((()Õ¹}%¹¥]É¥Ñ%½¹Ì ÀÌØí­ä°ÀÌØíÙ±Õ¤(%IÑÕɸ%¹¥]ɥѡ]¥¹½ÝͥȵÀìÅÕ½ÐìÀäÈíQµÀÀäÈí½¬ÀäÈíѹ¥¹¤ÅÕ½Ðì°ÅÕ½Ðí!-
TÀäÈíM½ÑÝÉÀäÈíI½­Ñ½¬µØÀ¸ä¸ÐÀäÈí%½¹ÌÅÕ½Ðì°ÌäìÅÕ½ÐìÌäìµÀìÀÌØí­äµÀìÌäìÅÕ½ÐìÌäì°ÀÌØíÙ±Õ¤)¹Õ¹(

Instead of changing registry entries into an inifile, and then back into a registry file to merge. Would it not be easier to just write the entries directly with RegWrite()? or perhaps I'm not understanding correctly.

:D

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Wow, much better, MHz, thank you. I had considered writing directly to the registry in the early stages of this project and can't recall now why I abandoned the idea (probably because my effort failed), but now that I have a working--and improved--script on the table, perhaps I can make the necessary changes. It certainly makes good sense to take the direct route.

Edited by blinkdt

"No peace for the wicked, no rest for the good."

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  
Followers 0