Sign in to follow this  
Followers 0
meier3283

Edit data in notes.ini

39 posts in this topic

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

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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" ?

Share this post


Link to post
Share on other sites

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","")"

Share this post


Link to post
Share on other sites

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 add

2)_ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=,", "AddInMenus=")

;-))

Stefan

Share this post


Link to post
Share on other sites

Hi,

my example does it.

You may change:

1) _ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=NCMenu,", "AddInMenus=")

or add

2)_ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=,", "AddInMenus=")

;-))

Stefan

Ok, 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

Share this post


Link to post
Share on other sites

Hi,

my example does it.

You may change:

1) _ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=NCMenu,", "AddInMenus=")

or add

2)_ReplaceStringInFile ($NotesReg & "\notes.ini", "AddInMenues=,", "AddInMenus=")

;-))

Stefan

It will do it if it's always the first parameter on the line, in which case it may be the easiest.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

unfortunately, I need to be able to accomodate that text being anywhere in that line. Do you think it's possible with AutoIt?

- David

It 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 delimiter

and write the line back with IniRead()

Share this post


Link to post
Share on other sites

#14 ·  Posted (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 by 99ojo

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#18 ·  Posted (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 :D(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 by 99ojo

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#20 ·  Posted (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 by 99ojo

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