mehrdad39 Posted July 29, 2009 Share Posted July 29, 2009 Hello, I am working on a system permissions policy menu that has 4 checkboxes and an Apply button. Hide My Computer Hide Control Panel Hide Drives in the system disable right click I have found checkbox scripts from past posts that write the result of the checkboxes into and .INI file and loads it back up upon clicking onthe Load button. I have a couple of questions: 1. I need help trying to figure out how to go about adding RegWrite and RegRead to the gui so when the user selects the options they wnat and when they click on apply, those options write the changes to the registry as well as doing the current ini update. 2. Is there a way to automatically read the ini file and populate the previously selected boxes with checkmarks the next time the app is launched and if there are changes being made, to update the registry and the ini? the iniWrite functions are listed. I also know how to write to the registry, but I don't know where to put it in the script or do the other things. Any instructions, help or even pointing to a simillar script is appreciated. Thanks Mehrdad Func ApplyClick() IniWrite(@ScriptDir&"\permission.ini","optionbox","Hide My Computer",IsChecked($HideMyComp)) IniWrite(@ScriptDir&"\permission.ini","optionbox","Hide Control Panel",IsChecked($HideControl)) IniWrite(@ScriptDir&"\permission.ini","optionbox","Hide Drives",IsChecked($HideDrives)) IniWrite(@ScriptDir&"\permission.ini","optionbox","Disable Right Click",IsChecked($HideRClick)) EndFunc Link to comment Share on other sites More sharing options...
enaiman Posted July 29, 2009 Share Posted July 29, 2009 You don't need an ini file to do this:Func ApplyClick() If BitAND(GUICtrlRead($HideMyComp), $GUI_CHECKED) Then RegWrite("reg key name1" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideControl), $GUI_CHECKED) Then RegWrite("reg key name2" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideDrives), $GUI_CHECKED) Then RegWrite("reg key name3" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideRClick), $GUI_CHECKED) Then RegWrite("reg key name4" ,"value name", "type", "value") EndFuncThis code is checking the status of the checkbox, if checked then it will write to registry.You will have to replace "reg key nameX" ,"value name", "type", "value" with the appropriate values for each checkbox.Have a look at RegWrite function in the help file. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
mehrdad39 Posted July 29, 2009 Author Share Posted July 29, 2009 You don't need an ini file to do this: Func ApplyClick() If BitAND(GUICtrlRead($HideMyComp), $GUI_CHECKED) Then RegWrite("reg key name1" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideControl), $GUI_CHECKED) Then RegWrite("reg key name2" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideDrives), $GUI_CHECKED) Then RegWrite("reg key name3" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideRClick), $GUI_CHECKED) Then RegWrite("reg key name4" ,"value name", "type", "value") EndFunc This code is checking the status of the checkbox, if checked then it will write to registry. You will have to replace "reg key nameX" ,"value name", "type", "value" with the appropriate values for each checkbox. Have a look at RegWrite function in the help file. Thanks Enaiman for the suggestion. If I understand it correctly, your code only writes to the registry if the option is checked. How will the script know if the options was previously checked and the registry already edited when the script is launched again at a later time? The ini file was so it would remember what option(s) were aleady active from prior sessions. Am I correct or am I missing the point here? Thanks Mehrdad Link to comment Share on other sites More sharing options...
enaiman Posted July 29, 2009 Share Posted July 29, 2009 It will be better for your script to check these registry keys at startup and check the boxes accordingly. Something like: If RegRead("reg key name1" ,"value name") = "value" Then GUICtrlSetState($HideMyComp, $GUI_CHECKED) Else GUICtrlSetState($HideMyComp, $GUI_UNCHECKED) EndIf If RegRead("reg key name2" ,"value name") = "value" Then GUICtrlSetState($HideControl, $GUI_CHECKED) Else GUICtrlSetState($HideControl, $GUI_UNCHECKED) EndIf If RegRead("reg key name3" ,"value name") = "value" Then GUICtrlSetState($HideDrives, $GUI_CHECKED) Else GUICtrlSetState($HideDrives, $GUI_UNCHECKED) EndIf If RegRead("reg key name4" ,"value name") = "value" Then GUICtrlSetState($HideRClick, $GUI_CHECKED) Else GUICtrlSetState($HideRClick, $GUI_UNCHECKED) EndIf (see the my previous post where from I've got the "reg key nameX" ...) This way your script will give you accurate info about how these options are. If something (or somebody) has modified these keys manually (not using your script), your ini file will have wrong info. The above method will efeectively read the registry. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
mehrdad39 Posted July 30, 2009 Author Share Posted July 30, 2009 It will be better for your script to check these registry keys at startup and check the boxes accordingly. Something like: If RegRead("reg key name1" ,"value name") = "value" Then GUICtrlSetState($HideMyComp, $GUI_CHECKED) Else GUICtrlSetState($HideMyComp, $GUI_UNCHECKED) EndIf If RegRead("reg key name2" ,"value name") = "value" Then GUICtrlSetState($HideControl, $GUI_CHECKED) Else GUICtrlSetState($HideControl, $GUI_UNCHECKED) EndIf If RegRead("reg key name3" ,"value name") = "value" Then GUICtrlSetState($HideDrives, $GUI_CHECKED) Else GUICtrlSetState($HideDrives, $GUI_UNCHECKED) EndIf If RegRead("reg key name4" ,"value name") = "value" Then GUICtrlSetState($HideRClick, $GUI_CHECKED) Else GUICtrlSetState($HideRClick, $GUI_UNCHECKED) EndIf (see the my previous post where from I've got the "reg key nameX" ...) This way your script will give you accurate info about how these options are. If something (or somebody) has modified these keys manually (not using your script), your ini file will have wrong info. The above method will efeectively read the registry. Enaiman, that was great. It worked perfectly for reading the registry entries. I have to mention that I am very new to this but I pickup quickly. I need to ask you another favor and that is where to put the function for the apply button, so when the user selects all of their choices and click on apply, then all the registry writes will happen. I have attached the entire script and I am confused about what I am doing wrong. Thank you in advance. Mehrdad expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Permissions() Func Permissions() Local $HideMyComp, $HideDrive, $HideControl, $HideRClick, $msg, $widthCell, $Apply GUICreate("Access Policies", 220, 180, -1, -1) $widthCell =210 $HideMyComp = GUICtrlCreateCheckbox("Disale Access to My Computer", 15, 20, $widthCell, 20) $HideControl = GUICtrlCreateCheckbox("Disale Access to Control Panel", -1, 50, $widthCell, 20) $HideDrive = GUICtrlCreateCheckbox("Hide all drives in the DVR", -1, 80, $widthCell, 20) $HideRClick = GUICtrlCreateCheckbox("Disale mouse Right-Click option", -1, 110, $widthCell, 20) $Apply = GUICtrlCreateButton("Apply", 70, 150, 80, 20) GUICtrlSetOnEvent(-1, "ApplyClick") GUISetState() While 1 $msg = GUIGetMsg() Select If $msg = $GUI_EVENT_CLOSE Then ExitLoop Case $msg = $HideMyComp MsgBox(4096, "", "This will disable access to my computer") Case $msg = $HideControl MsgBox(4096, "", "This will disable access to Control panel") Case $msg = $HideDrive MsgBox(4096, "", "This will hide all drives") Case $msg = $HideRClick MsgBox(4096, "", "This will disable Right Click") EndSelect ; If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoDrives") = "16" Then ; GUICtrlSetState($HideMyComp, $GUI_CHECKED) ; Else ; GUICtrlSetState($HideMyComp, $GUI_UNCHECKED) ; EndIf If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoControlPanel") = "1" Then GUICtrlSetState($HideControl, $GUI_CHECKED) Else GUICtrlSetState($HideControl, $GUI_UNCHECKED) EndIf If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoDrives") = "16" Then GUICtrlSetState($HideDrive, $GUI_CHECKED) Else GUICtrlSetState($HideDrive, $GUI_UNCHECKED) EndIf If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoViewContextMenu") = "1" Then GUICtrlSetState($HideRClick, $GUI_CHECKED) Else GUICtrlSetState($HideRClick, $GUI_UNCHECKED) EndIf WEnd EndFunc Func ApplyClick() ; If BitAND(GUICtrlRead($HideMyComp), $GUI_CHECKED) Then RegWrite("reg key name1" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideControl), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoControlPanel", "REG_DWORD", "1") If BitAND(GUICtrlRead($HideDrive), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoDrives", "REG_DWORD", "16") If BitAND(GUICtrlRead($HideRClick), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoViewContextMenu", "REG_DWORD", "1") EndFunc Link to comment Share on other sites More sharing options...
enaiman Posted July 30, 2009 Share Posted July 30, 2009 (edited) Well, I can see you're fairly new into this but you're on the good way >_< Modified code: expandcollapse popup#include <GUIConstantsEx.au3> Global $HideMyComp, $HideDrive, $HideControl, $HideRClick Opt('MustDeclareVars', 1) Permissions() Func Permissions() Local $widthCell, $Apply, $msg GUICreate("Access Policies", 220, 180, -1, -1) $widthCell =210 $HideMyComp = GUICtrlCreateCheckbox("Disable Access to My Computer", 15, 20, $widthCell, 20) $HideControl = GUICtrlCreateCheckbox("Disable Access to Control Panel", -1, 50, $widthCell, 20) $HideDrive = GUICtrlCreateCheckbox("Hide all drives in the DVR", -1, 80, $widthCell, 20) $HideRClick = GUICtrlCreateCheckbox("Disable mouse Right-Click option", -1, 110, $widthCell, 20) $Apply = GUICtrlCreateButton("Apply", 70, 150, 80, 20) _ReadREGValues() GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Select Case $msg = $HideMyComp If BitAND(GUICtrlRead($HideMyComp), $GUI_CHECKED) Then MsgBox(4096, "", "This will disable access to my computer") Else MsgBox(4096, "", "This will enable access to my computer") EndIf Case $msg = $HideControl If BitAND(GUICtrlRead($HideControl), $GUI_CHECKED) Then MsgBox(4096, "", "This will disable access to Control panel") Else MsgBox(4096, "", "This will enable access to Control panel") EndIf Case $msg = $HideDrive If BitAND(GUICtrlRead($HideDrive), $GUI_CHECKED) Then MsgBox(4096, "", "This will hide all drives") Else MsgBox(4096, "", "This will show all drives") EndIf Case $msg = $HideRClick If BitAND(GUICtrlRead($HideRClick), $GUI_CHECKED) Then MsgBox(4096, "", "This will disable Right Click") Else MsgBox(4096, "", "This will enable Right Click") EndIf Case $msg = $HideRClick ApplyClick() EndSelect WEnd EndFunc Func _ReadREGValues() If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoControlPanel") = "1" Then GUICtrlSetState($HideControl, $GUI_CHECKED) Else GUICtrlSetState($HideControl, $GUI_UNCHECKED) EndIf If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoDrives") = "16" Then GUICtrlSetState($HideDrive, $GUI_CHECKED) Else GUICtrlSetState($HideDrive, $GUI_UNCHECKED) EndIf If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoViewContextMenu") = "1" Then GUICtrlSetState($HideRClick, $GUI_CHECKED) Else GUICtrlSetState($HideRClick, $GUI_UNCHECKED) EndIf EndFunc Func ApplyClick() ; If BitAND(GUICtrlRead($HideMyComp), $GUI_CHECKED) Then RegWrite("reg key name1" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideControl), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoControlPanel", "REG_DWORD", "1") If BitAND(GUICtrlRead($HideDrive), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoDrives", "REG_DWORD", "16") If BitAND(GUICtrlRead($HideRClick), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoViewContextMenu", "REG_DWORD", "1") EndFunc You had some errors in your code: - GUICtrlSetOnEvent(-1, "ApplyClick") => OnEventMode is set at the beginig of the script and the whole script (usually) has a form specific to this mode; you weren't using OnEvent so that line had to be removed - The registry value check was placed inside the While loop => it was checked/applied every time so the checkboxes couldn't be checked/unchecked; The registry check was moved inside a function and the function ran (once) before showing the GUI. - because your checkbox's handles were used inside another function they had to be declared Global not "Local" Other than that it was pretty good. I have changed also the message you get whenever you check/uncheck a checkbox in order to reflect the appropriate action. Have a look at the modified code and try to understand what I did - that will help you in the future. I remember an old chinese proverb: "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." That's what I'm trying to do Edited July 30, 2009 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
mehrdad39 Posted August 7, 2009 Author Share Posted August 7, 2009 Well, I can see you're fairly new into this but you're on the good way >_< Modified code: expandcollapse popup#include <GUIConstantsEx.au3> Global $HideMyComp, $HideDrive, $HideControl, $HideRClick Opt('MustDeclareVars', 1) Permissions() Func Permissions() Local $widthCell, $Apply, $msg GUICreate("Access Policies", 220, 180, -1, -1) $widthCell =210 $HideMyComp = GUICtrlCreateCheckbox("Disable Access to My Computer", 15, 20, $widthCell, 20) $HideControl = GUICtrlCreateCheckbox("Disable Access to Control Panel", -1, 50, $widthCell, 20) $HideDrive = GUICtrlCreateCheckbox("Hide all drives in the DVR", -1, 80, $widthCell, 20) $HideRClick = GUICtrlCreateCheckbox("Disable mouse Right-Click option", -1, 110, $widthCell, 20) $Apply = GUICtrlCreateButton("Apply", 70, 150, 80, 20) _ReadREGValues() GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Select Case $msg = $HideMyComp If BitAND(GUICtrlRead($HideMyComp), $GUI_CHECKED) Then MsgBox(4096, "", "This will disable access to my computer") Else MsgBox(4096, "", "This will enable access to my computer") EndIf Case $msg = $HideControl If BitAND(GUICtrlRead($HideControl), $GUI_CHECKED) Then MsgBox(4096, "", "This will disable access to Control panel") Else MsgBox(4096, "", "This will enable access to Control panel") EndIf Case $msg = $HideDrive If BitAND(GUICtrlRead($HideDrive), $GUI_CHECKED) Then MsgBox(4096, "", "This will hide all drives") Else MsgBox(4096, "", "This will show all drives") EndIf Case $msg = $HideRClick If BitAND(GUICtrlRead($HideRClick), $GUI_CHECKED) Then MsgBox(4096, "", "This will disable Right Click") Else MsgBox(4096, "", "This will enable Right Click") EndIf Case $msg = $HideRClick ApplyClick() EndSelect WEnd EndFunc Func _ReadREGValues() If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoControlPanel") = "1" Then GUICtrlSetState($HideControl, $GUI_CHECKED) Else GUICtrlSetState($HideControl, $GUI_UNCHECKED) EndIf If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoDrives") = "16" Then GUICtrlSetState($HideDrive, $GUI_CHECKED) Else GUICtrlSetState($HideDrive, $GUI_UNCHECKED) EndIf If RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer","NoViewContextMenu") = "1" Then GUICtrlSetState($HideRClick, $GUI_CHECKED) Else GUICtrlSetState($HideRClick, $GUI_UNCHECKED) EndIf EndFunc Func ApplyClick() ; If BitAND(GUICtrlRead($HideMyComp), $GUI_CHECKED) Then RegWrite("reg key name1" ,"value name", "type", "value") If BitAND(GUICtrlRead($HideControl), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoControlPanel", "REG_DWORD", "1") If BitAND(GUICtrlRead($HideDrive), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoDrives", "REG_DWORD", "16") If BitAND(GUICtrlRead($HideRClick), $GUI_CHECKED) Then RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer" ,"NoViewContextMenu", "REG_DWORD", "1") EndFunc You had some errors in your code: - GUICtrlSetOnEvent(-1, "ApplyClick") => OnEventMode is set at the beginig of the script and the whole script (usually) has a form specific to this mode; you weren't using OnEvent so that line had to be removed - The registry value check was placed inside the While loop => it was checked/applied every time so the checkboxes couldn't be checked/unchecked; The registry check was moved inside a function and the function ran (once) before showing the GUI. - because your checkbox's handles were used inside another function they had to be declared Global not "Local" Other than that it was pretty good. I have changed also the message you get whenever you check/uncheck a checkbox in order to reflect the appropriate action. Have a look at the modified code and try to understand what I did - that will help you in the future. I remember an old chinese proverb: "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." That's what I'm trying to do Thank you so much enaiman. I had to leave the project for a few days. I got back on it today and I had to add a OK button to get it to close properly since I removed the X tool option. I also added the reverse function so it will reset the registry back to original if an option is unchecked at the same time. Although this is only a part of a bigger project, I could not have done this without your help. Thanks again, Mehrdad Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now