lolipop Posted February 14, 2013 Posted February 14, 2013 Hi members, I'm trying to use a FOR loop to delete some registry key base on certain condition but somehow it's not working correctly. Basically, inside registry key test1 there's a couple of other keys nested. What I want is to delete all the other keys and leave the keys I want intact. The code below seems to read and delete every alternate keys instead. TIA. Below is an example of the code. For $count = 1 To 1000 $var = RegEnumKey("HKEY_CURRENT_USER\test\test1\", $count) If @error <> 0 Then ExitLoop If $var <> "S-1-1-1-1" Or "S-1-1-1-2" Or "S-1-1-1-3" Then $var1 = ("HKEY_CURRENT_USER\test\test1\" & $var) RegDelete($var1) EndIf Next
BrewManNH Posted February 14, 2013 Posted February 14, 2013 This line is wrong. If $var <> "S-1-1-1-1" Or "S-1-1-1-2" Or "S-1-1-1-3" Then It needs to be written like this. If $var <> "S-1-1-1-1" Or $var <> "S-1-1-1-2" Or $var <> "S-1-1-1-3" Then You have to test the comparison against something every time, you can't specify it once like you were doing. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
lolipop Posted February 14, 2013 Author Posted February 14, 2013 Hi BrewMan,I have tried that as well but the code doesn't execute correctly as well. It doesn't seems to be checking the condition properly. I try changing the code as per your advise, now it delete the registry key "S-1-1-1-2" as well. The code seems to be deleting in the alternate pattern.Read key 1Read key 2Delete key 2Read key 3Read key 4Delete key 4Read key 5Read key 6Delete key 6etc......
lolipop Posted February 14, 2013 Author Posted February 14, 2013 Hi guys, Thanks. I have resolved the problem. Please close the thread. Thank you.
JohnOne Posted February 14, 2013 Posted February 14, 2013 Hi guys,Thanks. I have resolved the problem. Please close the thread. Thank you. Just for your information:Threads such as this are not usually closed on demand, remember, you might have started the thread but it does not belong to you.Also, it customary, to post solutions to problems you have asked for help with, even if you solve it yourself, as other people read this too. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
lolipop Posted February 14, 2013 Author Posted February 14, 2013 Well, I'm not gd with explaination. Basically the for loop is giving the wrong registry key instance everytime I delete 1 of the key so I nested the for loop within a while loop and everytime I delete 1 registry key, I restart the for loop process again. Perhaps the amended code below can self explain better. $counter = 1 While $counter For $count = 1 To 100 $list = RegEnumKey("HKEY_CURRENT_USER\TEST\TEST1\List\", $count) If @error <> 0 Then $counter = 0 ExitLoop EndIf If $list = "S-1-5-18" Then ElseIf $list = "S-1-5-19" Then ElseIf $list = "S-1-5-20" Then Else RegDelete("HKEY_CURRENT_USER\TEST\TEST1\List\" & $list ) ExitLoop EndIf Next WEnd There's one thing I still can't figure out and that's the OR operators. Can't seems to get that to work properly. So instead I use If and elseif. Code not optimized but it get the job done.
BrewManNH Posted February 14, 2013 Posted February 14, 2013 You should probably loop through the registry keys in reverse if you're deleting them. As soon as you delete one, the count is wrong. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
lolipop Posted February 15, 2013 Author Posted February 15, 2013 You should probably loop through the registry keys in reverse if you're deleting them. As soon as you delete one, the count is wrong.How do you loop in reverse?
BrewManNH Posted February 15, 2013 Posted February 15, 2013 Here's one way, using two loops, the first one gets the count of the keys, the second does the deleting. ; this loop finds out how many subkeys there are For $i = 1 To 1000 $var = RegEnumKey("HKEY_CURRENT_USER\test\test1\", $i) If @error <> 0 Then $Count = $i - 1 ExitLoop EndIf Next ; This loops through the keys in reverse For $i = $Count To 1 Step -1 If $var <> "S-1-1-1-1" Or $var <> "S-1-1-1-2" Or $var <> "S-1-1-1-3" Then $var1 = ("HKEY_CURRENT_USER\test\test1\" & $var) ConsoleWrite($var1 & @crlf) EndIf Next I changed the RegDelete to a consolewrite so you don't accidently delete anything before getting it to work right. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AHRIMANSEFID Posted March 16, 2013 Posted March 16, 2013 Hi Plz Help For Delete Error dele--1.au3(6,120) : ERROR: RegDelete() [built-in] called with wrong number of args. RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run','test.exe','REG_SZ',@WindowsDir & "\test.exe") RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers','C:\Windows\test.exe','REG_SZ','~ RUNASADMIN')
Moderators Melba23 Posted March 16, 2013 Moderators Posted March 16, 2013 AHRIMANSEFID,And how many arguments does the Help file tell you that RegDelete should have? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
AHRIMANSEFID Posted March 16, 2013 Posted March 16, 2013 (edited) I read the document you had mentioned but still I have the same problem. Just try the code below: RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run','test.exe','REG_SZ',@WindowsDir & "\test.exe") RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers','C:\Windows\test.exe','REG_SZ','~ RUNASADMIN') when I use and trying these codes I am getting this error: dele--1.au3(6,120) : ERROR: RegDelete() [built-in] now can you helping me without getting angry! I appreciate any help suggestion or solution. OR RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run','test.exe','REG_SZ','C:\Windows\test.exe') RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers','C:\Windows\test.exe','REG_SZ','~ RUNASADMIN') RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run','test.exe','REG_SZ','C:\Windows\test.exe') Edited March 16, 2013 by AHRIMANSEFID
Moderators Melba23 Posted March 16, 2013 Moderators Posted March 16, 2013 AHRIMANSEFID,can you helping me without getting angry!There was no anger expressed in my previous post - so why suggest that there was? I read the document you had mentionedAnd so what is the answer to the question I asked? How many arguments does RegDelete take? Once you have that answer then the solution to your problem becomes obvious. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted March 16, 2013 Moderators Posted March 16, 2013 AHRIMANSEFID,No - you answer the question I asked and then you can then fix all the lines yourself. So, for the third time, how many arguments does the Help file say that you need for RegDelete? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
AHRIMANSEFID Posted March 16, 2013 Posted March 16, 2013 #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Beta #AutoIt3Wrapper_Compile_Both=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run','Test.exe','REG_SZ','C:\Windows\Test.exe') RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers','C:\Windows\Test.exe','REG_SZ','~ RUNASADMIN') RegDelete('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run','Test.exe','REG_SZ','C:\Windows\Test.exe') FileDelete(@WindowsDir & "\Test.exe")
AHRIMANSEFID Posted March 16, 2013 Posted March 16, 2013 You Help Me For Fix Line Error. Thanks A lot. Me Read Page And Help Autoit. Not Found Help. You Help Me.
JohnOne Posted March 16, 2013 Posted March 16, 2013 RegDelete('HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun','Test.exe','REG_SZ','C:WindowsTest.exe')There are 4 arguments there. RegDelete does not take 4 arguments, as shown by M23. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Moderators Melba23 Posted March 16, 2013 Moderators Posted March 16, 2013 AHRIMANSEFID,Not Found HelpAnd to what does the link I posted lead you if not the Help file page for RegDelete? I am out of here - even my patience has been exhausted. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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