meier3283 Posted September 22, 2009 Posted September 22, 2009 Hello all, I'm brand spanking new to AutoIt, and need to hammer out a quick script, that I think has been done already by someone. I need to find where a notes.ini file is located on a windows system. (sample pulled from other posts, thanks!) and then I need to remove text from two entries in the INI. AddInMenus=NCMenu (need to remove the NCMenu) EXTMGR_ADDINS=NCExtMgr (need to remove the NCExtMgr) This is the script I've already highjacked: $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") If FileExists($NotesReg & "\notes.ini") then EndIf I mainly need help navigating to the specific section of the notes.ini, (only one section called "[Notes]" and then removing the specific text. Anyone willing to get me on track? I really appreciate it. - David
99ojo Posted September 22, 2009 Posted September 22, 2009 Hello all, I'm brand spanking new to AutoIt, and need to hammer out a quick script, that I think has been done already by someone. I need to find where a notes.ini file is located on a windows system. (sample pulled from other posts, thanks!) and then I need to remove text from two entries in the INI. AddInMenus=NCMenu (need to remove the NCMenu) EXTMGR_ADDINS=NCExtMgr (need to remove the NCExtMgr) This is the script I've already highjacked: $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") If FileExists($NotesReg & "\notes.ini") then EndIf I mainly need help navigating to the specific section of the notes.ini, (only one section called "[Notes]" and then removing the specific text. Anyone willing to get me on track? I really appreciate it. - David Hi, that's it: #include <file.au3> $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") If FileExists($NotesReg & "\notes.ini") Then _ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenus=NCMenu", "AddInMenus=") _ReplaceStringInFile ($NotesReg & "\notes.ini", "EXTMGR_ADDINS=NCExtMgr", "EXTMGR_ADDINS=") EndIf ;-)) Stefan
water Posted September 22, 2009 Posted September 22, 2009 You know the section and you know the keys, so simply do an InIRead, change the value and do an IniWrite. $IniFile = $NotesReg & "\notes.ini" $IniValue = InIRead ($IniFile,"Notes","AddInMenus","Not found") If $IniValue <> "Not found" And $IniValue = "NCMenu" Then IniWrite($IniFile,"Notes","AddInMenus","") EndIf My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
TurionAltec Posted September 22, 2009 Posted September 22, 2009 This might work too: $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") If FileExists($NotesReg & "\notes.ini") Then IniWrite($NotesReg & "\notes.ini","Notes","AddInMenus","") IniWrite($NotesReg & "\notes.ini","Notes","EXTMGR_ADDINS","") EndIf
meier3283 Posted September 22, 2009 Author Posted September 22, 2009 This might work too: $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") If FileExists($NotesReg & "\notes.ini") Then IniWrite($NotesReg & "\notes.ini","Notes","AddInMenus","") IniWrite($NotesReg & "\notes.ini","Notes","EXTMGR_ADDINS","") EndIf Thanks all, for the quick reply. I'll digest these a bit, and get a script compiled. I didn't mention it, so I'm sorry, but if there was other text in those lines, such as "AddInMenues=NCMenu, Example2, Example3" could we just removed the specific text "NCMenu" ?
meier3283 Posted September 22, 2009 Author Posted September 22, 2009 You know the section and you know the keys, so simply do an InIRead, change the value and do an IniWrite. $IniFile = $NotesReg & "\notes.ini" $IniValue = InIRead ($IniFile,"Notes","AddInMenus","Not found") If $IniValue <> "Not found" And $IniValue = "NCMenu" Then IniWrite($IniFile,"Notes","AddInMenus","") EndIf Hey water, You did it a bit different than the other guys/gals, so I'm curious about your use of Not Found. If you have a moment, can you explain this line a bit? I'm just trying to better understand the calls made. "If $IniValue <> "Not found" And $IniValue = "NCMenu" Then IniWrite($IniFile,"Notes","AddInMenus","")"
99ojo Posted September 22, 2009 Posted September 22, 2009 Thanks all, for the quick reply. I'll digest these a bit, and get a script compiled. I didn't mention it, so I'm sorry, but if there was other text in those lines, such as "AddInMenues=NCMenu, Example2, Example3"could we just removed the specific text "NCMenu" ?Hi,my example does it. You may change:1) _ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=NCMenu,", "AddInMenus=")or add2)_ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=,", "AddInMenus=");-))Stefan
meier3283 Posted September 22, 2009 Author Posted September 22, 2009 Hi,my example does it. You may change:1) _ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=NCMenu,", "AddInMenus=")or add2)_ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=,", "AddInMenus=");-))StefanOk, I see what you are doing. You pull out the entire string, and place only what I want back in. Now.... let me throw you one more curve ball...I can't ensure my text is always in the same location... it could be "AddInMenus=Example1, NCMenu, Example2"Is there a way to search the line for my text, and remove only that text? - David
TurionAltec Posted September 22, 2009 Posted September 22, 2009 Hi,my example does it. You may change:1) _ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=NCMenu,", "AddInMenus=")or add2)_ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=,", "AddInMenus=");-))StefanIt will do it if it's always the first parameter on the line, in which case it may be the easiest.
meier3283 Posted September 22, 2009 Author Posted September 22, 2009 It will do it if it's always the first parameter on the line, in which case it may be the easiest.unfortunately, I need to be able to accomodate that text being anywhere in that line. Do you think it's possible with AutoIt? - David
99ojo Posted September 22, 2009 Posted September 22, 2009 unfortunately, I need to be able to accomodate that text being anywhere in that line. Do you think it's possible with AutoIt? - David Hi, hopefully NCMenu is only once in notes.ini. #include <file.au3> #include <Date.au3> Local $notesini $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") $time = Stringreplace (_NowTime (), ":", "") If FileExists($NotesReg & "\notes.ini") Then $file = FileOpen ($NotesReg & "\notes.ini", 0) $notesini = FileRead ($file) If StringInStr ($notesini, "NCMenu") > 0 Then If StringInStr ($notesini, "NCMenu,") > 0 Then $notesini = StringReplace ($notesini, "NCMenu,", "") Else $notesini = StringReplace ($notesini, "NCMenu", "") EndIf FileClose ($file) FileCopy ($NotesReg & "\notes.ini", $NotesReg & "\notes_" & $time & ".bak", 1) $file = FileOpen ($NotesReg & "\notes.ini", 2) FileWrite ($file, $notesini) FileClose ($file) EndIf EndIf Otherwise you have to read file into an array (see function _ReadFileToArray), loop over array and find a solution with StringInStr as i do in my code. Then save notes.ini and do a _FileWriteFromArray. ;-)) Stefan
meier3283 Posted September 22, 2009 Author Posted September 22, 2009 Hi, hopefully NCMenu is only once in notes.ini. #include <file.au3> #include <Date.au3> Local $notesini $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") $time = Stringreplace (_NowTime (), ":", "") If FileExists($NotesReg & "\notes.ini") Then $file = FileOpen ($NotesReg & "\notes.ini", 0) $notesini = FileRead ($file) If StringInStr ($notesini, "NCMenu") > 0 Then If StringInStr ($notesini, "NCMenu,") > 0 Then $notesini = StringReplace ($notesini, "NCMenu,", "") Else $notesini = StringReplace ($notesini, "NCMenu", "") EndIf FileClose ($file) FileCopy ($NotesReg & "\notes.ini", $NotesReg & "\notes_" & $time & ".bak", 1) $file = FileOpen ($NotesReg & "\notes.ini", 2) FileWrite ($file, $notesini) FileClose ($file) EndIf EndIf Otherwise you have to read file into an array (see function _ReadFileToArray), loop over array and find a solution with StringInStr as i do in my code. Then save notes.ini and do a _FileWriteFromArray. ;-)) Stefan Stefan, that looks like it will suit my needs exactly. That entry will only show up once, and I can duplicate the code to search for NCExtMgr. (or is there an easier way to just look for that at the same time? ) As a newbie, I'm curious what the file includes are for. "#include <file.au3> #include <Date.au3>" Thank you very much for your help. - David
TurionAltec Posted September 22, 2009 Posted September 22, 2009 unfortunately, I need to be able to accomodate that text being anywhere in that line. Do you think it's possible with AutoIt? - DavidIt should be. I would use IniRead () to read the value from the file, use StringSplit () with a comma as a delimiter._ArraySearch() to find the desired value_ArrayDelete() to delete the value_ArrayToString() to merge the values, using "," as the delimiterand write the line back with IniRead()
99ojo Posted September 22, 2009 Posted September 22, 2009 (edited) Stefan, that looks like it will suit my needs exactly. That entry will only show up once, and I can duplicate the code to search for NCExtMgr. (or is there an easier way to just look for that at the same time? ) As a newbie, I'm curious what the file includes are for. "#include <file.au3> #include <Date.au3>" Thank you very much for your help. - David Hi, you don't need #include <file.au3>. I forget to delete it, because i 1st was heading for a _ReadFileToArray solution. This function is in file.au3 I use function _NowTime to save notes.ini with a time stamp before rewriting it. This function is in Date.au3. See code: $time = Stringreplace (_NowTime (), ":", "") and FileCopy ($NotesReg & "\notes.ini", $NotesReg & "\notes_" & $time & ".bak", 1) ;-)) Stefan [edit] P.S: I can't watch football on tv because my wife is watching something else: #include <Date.au3> Local $notesini $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") $time = Stringreplace (_NowTime (), ":", "") If FileExists($NotesReg & "\notes.ini") Then $file = FileOpen ($NotesReg & "\notes.ini", 0) $notesini = FileRead ($file) FileClose ($file) If StringInStr ($notesini, "NCMenu") > 0 Or StringInStr ($notesini, "NCExtMgr") > 0 Then If StringInStr ($notesini, "NCMenu,") > 0 Then $notesini = StringReplace ($notesini, "NCMenu,", "") ElseIf StringInStr ($notesini, "NCMenu") > 0 Then $notesini = StringReplace ($notesini, "NCMenu", "") EndIf If StringInStr ($notesini, "NCExtMgr,") > 0 Then $notesini = StringReplace ($notesini, "NCExtMgr,", "") ElseIf StringInStr ($notesini, "NCExtMgr") > 0 Then $notesini = StringReplace ($notesini, "NCExtMgr", "") EndIf FileCopy ($NotesReg & "\notes.ini", $NotesReg & "\notes_" & $time & ".bak", 1) $file = FileOpen ($NotesReg & "\notes.ini", 2) FileWrite ($file, $notesini) FileClose ($file) EndIf EndIf If there are further problems we have to code like TurionAltec would do it. Or you try to code it. Look in helpfile. He shows the steps. It shouldn't be so hard, even for a beginner and as you see, there are a lot of people helping. ;-)) Stefan Edited September 22, 2009 by 99ojo
TurionAltec Posted September 22, 2009 Posted September 22, 2009 Rather than Reinvent the wheel I used the built in IniRead and Iniwrite commands. #Include <Array.au3> $AddInMenus=StringSplit (IniRead ("ini.ini","Notes","AddInMenus",""),",") For $i=1 to $AddInMenus[0] $AddInMenus[$i]=StringStripWS($AddInMenus[$i],3) ;strip leading and trailing spaces from each element Next $i= _ArraySearch($AddInMenus,"NCMenu") _ArrayDelete($AddInMenus,$i) _ArrayDelete($AddInMenus,0) $AddInMenus2=_ArrayToString($AddInMenus," , ") ConsoleWrite($AddInMenus2&@CRLF) IniWrite("ini.ini","Notes","AddInMenus",$AddInMenus2)
meier3283 Posted September 22, 2009 Author Posted September 22, 2009 Thanks All, I apprciate all the help. I am happy to write it myself, just needed some framework, and understanding of functions. I'll keep reading up, and this will allow me to close a case at work, which was a bit urgent. - David
TurionAltec Posted September 22, 2009 Posted September 22, 2009 Put together it's something like this: #Include <Array.au3> $Notesini = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path")& "\notes.ini" If FileExists($Notesini) then ;AddInMenus=NCMenu $AddInMenus=StringSplit (IniRead ($Notesini,"Notes","AddInMenus",""),",") For $i=1 to $AddInMenus[0] $AddInMenus[$i]=StringStripWS($AddInMenus[$i],3) ;strip leading and trailing spaces from each element Next $i= _ArraySearch($AddInMenus,"NCMenu") _ArrayDelete($AddInMenus,$i) _ArrayDelete($AddInMenus,0) $AddInMenus2=_ArrayToString($AddInMenus," , ") IniWrite($Notesini,"Notes","AddInMenus",$AddInMenus2) ;EXTMGR_ADDINS=NCExtMgr $EXTMGR_ADDINS=StringSplit (IniRead ($Notesini,"Notes","EXTMGR_ADDINS",""),",") For $i=1 to $EXTMGR_ADDINS[0] $EXTMGR_ADDINS[$i]=StringStripWS($EXTMGR_ADDINS[$i],3) ;strip leading and trailing spaces from each element Next $i= _ArraySearch($EXTMGR_ADDINS,"NCExtMgr") _ArrayDelete($EXTMGR_ADDINS,$i) _ArrayDelete($EXTMGR_ADDINS,0) $EXTMGR_ADDINS2=_ArrayToString($EXTMGR_ADDINS," , ") IniWrite($Notesini,"Notes","EXTMGR_ADDINS",$EXTMGR_ADDINS2) EndIf
99ojo Posted September 22, 2009 Posted September 22, 2009 (edited) Put together it's something like this: #Include <Array.au3> $Notesini = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path")& "\notes.ini" If FileExists($Notesini) then ;AddInMenus=NCMenu $AddInMenus=StringSplit (IniRead ($Notesini,"Notes","AddInMenus",""),",") For $i=1 to $AddInMenus[0] $AddInMenus[$i]=StringStripWS($AddInMenus[$i],3) ;strip leading and trailing spaces from each element Next $i= _ArraySearch($AddInMenus,"NCMenu") _ArrayDelete($AddInMenus,$i) _ArrayDelete($AddInMenus,0) $AddInMenus2=_ArrayToString($AddInMenus," , ") IniWrite($Notesini,"Notes","AddInMenus",$AddInMenus2) ;EXTMGR_ADDINS=NCExtMgr $EXTMGR_ADDINS=StringSplit (IniRead ($Notesini,"Notes","EXTMGR_ADDINS",""),",") For $i=1 to $EXTMGR_ADDINS[0] $EXTMGR_ADDINS[$i]=StringStripWS($EXTMGR_ADDINS[$i],3) ;strip leading and trailing spaces from each element Next $i= _ArraySearch($EXTMGR_ADDINS,"NCExtMgr") _ArrayDelete($EXTMGR_ADDINS,$i) _ArrayDelete($EXTMGR_ADDINS,0) $EXTMGR_ADDINS2=_ArrayToString($EXTMGR_ADDINS," , ") IniWrite($Notesini,"Notes","EXTMGR_ADDINS",$EXTMGR_ADDINS2) EndIf Hi, now i'm going to bed, but i have to jump the horse as well (hahaha): #include <array.au3> #include <date.au3> $time = StringReplace (_NowTime (), ":", "") $IniFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") & "\notes.ini" $IniValue1 = _replacemystring (InIRead ($IniFile,"Notes","AddInMenus","Not found"), "NCMenu") $IniValue2 = _replacemystring (InIRead ($IniFile,"Notes","EXTMGR_ADDINS","Not found"), "NCExtMgr") If $IniValue1 <> "Not Found" Or $IniValue2 <> "Not Found" Then FileCopy ($NotesReg & "\notes.ini", $NotesReg & "\notes_" & $time & ".bak") If $IniValue1 <> "Not Found" Then IniWrite($IniFile,"Notes","AddInMenus",$IniValue1) If $IniValue2 <> "Not Found" Then IniWrite($IniFile,"Notes","EXTMGR_ADDINS",$IniValue2) EndIf Func Func _replacemystring ($string, $replace) $string = StringReplace ($string, " ", "") $temp = StringSplit ($string, ",") $index = _ArraySearch ($temp, $replace) _ArrayDelete ($temp, $index) $strtemp = _ArrayToString ($temp, ",", 1) Return $strtemp EndFunc Edited September 22, 2009 by 99ojo
meier3283 Posted September 23, 2009 Author Posted September 23, 2009 Hi, hopefully NCMenu is only once in notes.ini. #include <file.au3> #include <Date.au3> Local $notesini $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") $time = Stringreplace (_NowTime (), ":", "") If FileExists($NotesReg & "\notes.ini") Then $file = FileOpen ($NotesReg & "\notes.ini", 0) $notesini = FileRead ($file) If StringInStr ($notesini, "NCMenu") > 0 Then If StringInStr ($notesini, "NCMenu,") > 0 Then $notesini = StringReplace ($notesini, "NCMenu,", "") Else $notesini = StringReplace ($notesini, "NCMenu", "") EndIf FileClose ($file) FileCopy ($NotesReg & "\notes.ini", $NotesReg & "\notes_" & $time & ".bak", 1) $file = FileOpen ($NotesReg & "\notes.ini", 2) FileWrite ($file, $notesini) FileClose ($file) EndIf EndIf Otherwise you have to read file into an array (see function _ReadFileToArray), loop over array and find a solution with StringInStr as i do in my code. Then save notes.ini and do a _FileWriteFromArray. ;-)) Stefan Unfortnately, I've found that these entries are duplicated on most systems... So i'll need to find a way to loop over the code twice in one execution. AddInMenus=NCMenu EXTMGR_ADDINS=NCExtMgr AddInMenus=NCMenu EXTMGR_ADDINS=NCExtMgr I'll see if I can decipher what you mentioned about _ReadFileToArray.
99ojo Posted September 23, 2009 Posted September 23, 2009 (edited) Unfortnately, I've found that these entries are duplicated on most systems... So i'll need to find a way to loop over the code twice in one execution. AddInMenus=NCMenu EXTMGR_ADDINS=NCExtMgr AddInMenus=NCMenu EXTMGR_ADDINS=NCExtMgr I'll see if I can decipher what you mentioned about _ReadFileToArray. Hi, that doesn't matter. My code with the file read replaces every NCMenu and NCExtMgr entry. What i meant was something like this: AddInMenus=NCMenu EXTMGR_ADDINS=NCExtMgr Entry=NCMenu -> and you have to keep this value. This would replace as well So, this code should work: #include <Date.au3> Local $notesini $NotesReg = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") $time = Stringreplace (_NowTime (), ":", "") If FileExists($NotesReg & "\notes.ini") Then $file = FileOpen ($NotesReg & "\notes.ini", 0) $notesini = FileRead ($file) FileClose ($file) If StringInStr ($notesini, "NCMenu") > 0 Or StringInStr ($notesini, "NCExtMgr") > 0 Then If StringInStr ($notesini, "NCMenu,") > 0 Then $notesini = StringReplace ($notesini, "NCMenu,", "") ElseIf StringInStr ($notesini, "NCMenu") > 0 Then $notesini = StringReplace ($notesini, "NCMenu", "") EndIf If StringInStr ($notesini, "NCExtMgr,") > 0 Then $notesini = StringReplace ($notesini, "NCExtMgr,", "") ElseIf StringInStr ($notesini, "NCExtMgr") > 0 Then $notesini = StringReplace ($notesini, "NCExtMgr", "") EndIf FileCopy ($NotesReg & "\notes.ini", $NotesReg & "\notes_" & $time & ".bak", 1) $file = FileOpen ($NotesReg & "\notes.ini", 2) FileWrite ($file, $notesini) FileClose ($file) EndIf EndIf ;-)) Stefan P.S: Just copy a notes.ini to c:\temp and set a $NotesReg = "c:\temp" after $time = See what happens and if it works. Edited September 23, 2009 by 99ojo
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