Jump to content

Edit data in notes.ini


meier3283
 Share

Recommended Posts

You are correct, the code above, does remove it from all locations, and also creates the backup file. If I needed to check a second location, is it easy to merge into the code?

That will do the trick. Thanks a million, for your help (everyone's), I'm excited to get up to speed on AutoIT.

Any good resources you know of, to ramp up? the help file is good as well.

thanks guys

- David

Link to comment
Share on other sites

You are correct, the code above, does remove it from all locations, and also creates the backup file. If I needed to check a second location, is it easy to merge into the code?

That will do the trick. Thanks a million, for your help (everyone's), I'm excited to get up to speed on AutoIT.

Any good resources you know of, to ramp up? the help file is good as well.

thanks guys

- David

Sadly, this will give you an idea about how much I understand AutoIT scripts at this point.

I have another location where the notes.ini will reside, so I want to make sure I edit both.

here's my attempt to duplicate/modify what you had provided, and unfortunately it's not working. I suspect my usage of @AppDataDir is not correct... spot anything obvious?

#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

$NotesLoc = (@AppDataDir & "Lotus\Notes\Data\")
If FileExists($NotesLoc & "\notes.ini") Then
    $file = FileOpen($NotesLoc & "\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($NotesLoc & "\notes.ini", $NotesLoc & "\notes_" & $time & ".bak", 1)
        $file = FileOpen($NotesLoc & "\notes.ini", 2)
        FileWrite($file, $notesini)
        FileClose($file)
    EndIf
EndIf
Link to comment
Share on other sites

@AppDataDir doesn't include a trailing backslash so you have to put it in the string afterwards. It would look like this:

$NotesLoc = @AppDataDir & "\Lotus\Notes\Data\"

Hi,

new version with array solution a more flexible:

#include <array.au3>
#include <file.au3>
#include <date.au3>
Global $notesini

;Get time for saving old ini hhmmss
Global $time = StringReplace (_NowTime (), ":", "")

;1st notes.ini path
$notespath1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") & "\notes.ini"

;2nd notes.ini path
$notespath2 = @AppDataDir & "\Lotus\Notes\Data" & "\notes.ini"

_readnotesinitoarray ($notespath1)
;reset array
$notesini = ""
_readnotesinitoarray ($notespath2)


Func _readnotesinitoarray ($notespath)
    If FileExists ($notespath) Then
        ;reading notes.ini into array
        _FileReadToArray ($notespath, $notesini)
        ;search strings in array
        _searchstring ()
        ;save ini before changing
        FileCopy ($notespath , StringTrimRight ($notespath, 4) & "_" & $time & ".bak")
        ;write file from array
        _FileWriteFromArray ($notespath, $notesini, 1)
    EndIf
EndFunc

;searching AddInMenus And EXTMGR_ADDINS in Array; if found split into key and value (key: AddInMenus, value: Allbehind =)
;call function _replacestring to replace NCMenu and NCExtMgr in array and save new value in Array
Func _searchstring ()
    For $i = 1 To UBound ($notesini) - 1
        $tempstring = StringSplit ($notesini [$i], "=")
        If StringInStr ($tempstring [1], "AddInMenus") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCMenu")
        ElseIf StringInStr ($tempstring [1], "EXTMGR_ADDINS") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCExtMgr")
        EndIf
    Next
EndFunc

;see above
Func _replacemystring ($string, $replace)
    $string = StringReplace ($string, " ", "")
    $temp = StringSplit ($string, ",")
    $index = _ArraySearch ($temp, $replace) 
    _ArrayDelete ($temp, $index)
    $strtemp = _ArrayToString ($temp, ", ", 1)
    Return $strtemp
EndFunc

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi,

new version with array solution a more flexible:

#include <array.au3>
#include <file.au3>
#include <date.au3>
Global $notesini

;Get time for saving old ini hhmmss
Global $time = StringReplace (_NowTime (), ":", "")

;1st notes.ini path
$notespath1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") & "\notes.ini"

;2nd notes.ini path
$notespath2 = @AppDataDir & "\Lotus\Notes\Data" & "\notes.ini"

_readnotesinitoarray ($notespath1)
;reset array
$notesini = ""
_readnotesinitoarray ($notespath2)


Func _readnotesinitoarray ($notespath)
    If FileExists ($notespath) Then
        ;reading notes.ini into array
        _FileReadToArray ($notespath, $notesini)
        ;search strings in array
        _searchstring ()
        ;save ini before changing
        FileCopy ($notespath , StringTrimRight ($notespath, 4) & "_" & $time & ".bak")
        ;write file from array
        _FileWriteFromArray ($notespath, $notesini, 1)
    EndIf
EndFunc

;searching AddInMenus And EXTMGR_ADDINS in Array; if found split into key and value (key: AddInMenus, value: Allbehind =)
;call function _replacestring to replace NCMenu and NCExtMgr in array and save new value in Array
Func _searchstring ()
    For $i = 1 To UBound ($notesini) - 1
        $tempstring = StringSplit ($notesini [$i], "=")
        If StringInStr ($tempstring [1], "AddInMenus") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCMenu")
        ElseIf StringInStr ($tempstring [1], "EXTMGR_ADDINS") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCExtMgr")
        EndIf
    Next
EndFunc

;see above
Func _replacemystring ($string, $replace)
    $string = StringReplace ($string, " ", "")
    $temp = StringSplit ($string, ",")
    $index = _ArraySearch ($temp, $replace) 
    _ArrayDelete ($temp, $index)
    $strtemp = _ArrayToString ($temp, ", ", 1)
    Return $strtemp
EndFunc

;-))

Stefan

Looks fantastic, I'll compile it and make sure it works out. But thank you VERY much for taking the time to update it. Also, thanks for commenting the code, it really helps me learn the functions better.

Do you have an archive of scripts you have created in the past? I ask, because for stuff like this, I learn best by stepping through code, to see how it all works.

either way, thanks a million.

Update - It works like a charm. And, should I need to add another location of the notes.ini, it would be easy.

- David

Edited by meier3283
Link to comment
Share on other sites

Instead of:

$time = Stringreplace (_NowTime (), ":", "")

Couldn't one be more direct with:

$time=@HOUR&@MIN&@SEC

Saving the need for an unnecessary include, and code execution, unless regional settings were so crucial?

Heck you could even make it pretty:

$time=@HOUR&"-"&@MIN&"-"&@SEC

The recode was involved inwith the ideas of TurionAltec as well.

Pretty good hint with the $time variable. meier3283 should put in the code.

I sometimes forget the easy things.....

Should drink vinegar, it helps with my coffee machine

:D

Edited by 99ojo
Link to comment
Share on other sites

  • 3 weeks later...

I have an additional challenge for you guys :)

I've found that my deployment mechanism runs as the System account, and therefore the script doesn't have access to all the users profiles.

;2nd notes.ini path

$notespath2 = @AppDataDir & "\Lotus\Notes\Data" & "\notes.ini"

Is there a way I could search for most any notes.ini on the system, and make the necessary changes from there? Or at least search through all user profiles?

Is this possible?

I really appreciate any thoughts you might have.

- David

Link to comment
Share on other sites

This will search through user profiles simply by using cmd's "dir /s" functionality though it may be slow

#include <constants.au3>
#include <array.au3>
$profilelocation=Regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") ;XP default is %SystemDrive%\Documents and Settings, vista might return %SystemDrive%\users

$Command=@comspec & ' /c dir "'&$profilelocation&'\notes.ini" /s/b' 
$pid=Run($command,@SystemDir,@SW_HIDE,$STDERR_MERGED)
ProcessWaitClose($pid)
$output=StdoutRead($pid)
$output=StringSplit($output,@CRLF,1)
_ArrayDisplay($output)

Another option is I believe all logged in users have their "HKcU" registry hives mounted under HKEY_users according to their SID (big long string of gibberish)

If the target user is logged in when your script runs, their hive could be read for the value.

Link to comment
Share on other sites

This will search through user profiles simply by using cmd's "dir /s" functionality though it may be slow

#include <constants.au3>
#include <array.au3>
$profilelocation=Regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") ;XP default is %SystemDrive%\Documents and Settings, vista might return %SystemDrive%\users

$Command=@comspec & ' /c dir "'&$profilelocation&'\notes.ini" /s/b' 
$pid=Run($command,@SystemDir,@SW_HIDE,$STDERR_MERGED)
ProcessWaitClose($pid)
$output=StdoutRead($pid)
$output=StringSplit($output,@CRLF,1)
_ArrayDisplay($output)

Another option is I believe all logged in users have their "HKcU" registry hives mounted under HKEY_users according to their SID (big long string of gibberish)

If the target user is logged in when your script runs, their hive could be read for the value.

would I simply add a third path entry to my existing code?

;1st notes.ini path

$notespath1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") & "\notes.ini"

;2nd notes.ini path

$notespath2 = @AppDataDir & "\Lotus\Notes\Data" & "\notes.ini"

;3rd notes.ini path

$notespath2 = $output

Or something similar?

Link to comment
Share on other sites

would I simply add a third path entry to my existing code?

;1st notes.ini path

$notespath1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") & "\notes.ini"

;2nd notes.ini path

$notespath2 = @AppDataDir & "\Lotus\Notes\Data" & "\notes.ini"

;3rd notes.ini path

$notespath2 = $output

Or something similar?

$output is an array, so you'll need to cycle through all possibilities.

For $i = 0 to Ubound($output) -1
   _readnotesinitoarray ($output[$i])
Next

This should be the entire code:

#include <array.au3>
#include <file.au3>
#include <constants.au3>

Global $notesini, $profilelist

;Get time for saving old ini hhmmss
Global $time = @YDAY&"-"&@hour&"-"&@MIN&"-"&@SEC

;1st notes.ini path
$notespath1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") & "\notes.ini"

;2nd notes.ini path
$notespath2 = @AppDataDir & "\Lotus\Notes\Data\notes.ini"

_SearchProfiledir()

_readnotesinitoarray ($notespath1)
_readnotesinitoarray ($notespath2)

For $i=0 to Ubound($profilelist)
    _readnotesinitoarray ($profilelist[$i])
Next


Func _readnotesinitoarray ($notespath)

    If FileExists ($notespath) Then
        $notesini = "" ;reset array
        ;reading notes.ini into array
        _FileReadToArray ($notespath, $notesini)
        ;search strings in array
        _searchstring ()
        ;save ini before changing
        FileCopy ($notespath , StringTrimRight ($notespath, 4) & "_" & $time & ".bak")
        ;write file from array
        _FileWriteFromArray ($notespath, $notesini, 1)
    EndIf
EndFunc

;searching AddInMenus And EXTMGR_ADDINS in Array; if found split into key and value (key: AddInMenus, value: Allbehind =)
;call function _replacestring to replace NCMenu and NCExtMgr in array and save new value in Array
Func _searchstring ()
    For $i = 1 To UBound ($notesini) - 1
        $tempstring = StringSplit ($notesini [$i], "=")
        If StringInStr ($tempstring [1], "AddInMenus") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCMenu")
        ElseIf StringInStr ($tempstring [1], "EXTMGR_ADDINS") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCExtMgr")
        EndIf
    Next
EndFunc

;see above
Func _replacemystring ($string, $replace)
    $string = StringReplace ($string, " ", "")
    $temp = StringSplit ($string, ",")
    $index = _ArraySearch ($temp, $replace) 
    _ArrayDelete ($temp, $index)
    $strtemp = _ArrayToString ($temp, ", ", 1)
    Return $strtemp
EndFunc

Func _SearchProfiledir()
    $profilelocation=Regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") ;XP default is %SystemDrive%\Documents and Settings, vista might return %SystemDrive%\users
    $Command=@comspec & ' /c dir "'&$profilelocation&'\notes.ini" /s/b' 
    $pid=Run($command,@SystemDir,@SW_HIDE,$STDERR_MERGED)
    ProcessWaitClose($pid)
    $profilelist=StdoutRead($pid)
    $profilelist=StringSplit($profilelist,@CRLF,1)
    ;_ArrayDisplay($profilelist)
EndFunc

EDIT: modified this line:

For $i = 0 to Ubound($output) -1

to solve "Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded"

Edited by TurionAltec
Link to comment
Share on other sites

$output is an array, so you'll need to cycle through all possibilities.

For $i = 0 to Ubound($output)
   _readnotesinitoarray ($output[$i])
Next

With this new code, I guess it would be best to remove my previous two hard coded paths, and just search them out with your latest code.

I'm still trying to figure out how to get your code into the previous script...

Link to comment
Share on other sites

$output is an array, so you'll need to cycle through all possibilities.

For $i = 0 to Ubound($output)
   _readnotesinitoarray ($output[$i])
Next

This should be the entire code:

#include <array.au3>
#include <file.au3>
#include <constants.au3>

Global $notesini, $profilelist

;Get time for saving old ini hhmmss
Global $time = @YDAY&"-"&@hour&"-"&@MIN&"-"&@SEC

;1st notes.ini path
$notespath1 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Notes", "Path") & "\notes.ini"

;2nd notes.ini path
$notespath2 = @AppDataDir & "\Lotus\Notes\Data\notes.ini"

_SearchProfiledir()

_readnotesinitoarray ($notespath1)
_readnotesinitoarray ($notespath2)

For $i=0 to Ubound($profilelist)
    _readnotesinitoarray ($profilelist[$i])
Next


Func _readnotesinitoarray ($notespath)

    If FileExists ($notespath) Then
        $notesini = "" ;reset array
        ;reading notes.ini into array
        _FileReadToArray ($notespath, $notesini)
        ;search strings in array
        _searchstring ()
        ;save ini before changing
        FileCopy ($notespath , StringTrimRight ($notespath, 4) & "_" & $time & ".bak")
        ;write file from array
        _FileWriteFromArray ($notespath, $notesini, 1)
    EndIf
EndFunc

;searching AddInMenus And EXTMGR_ADDINS in Array; if found split into key and value (key: AddInMenus, value: Allbehind =)
;call function _replacestring to replace NCMenu and NCExtMgr in array and save new value in Array
Func _searchstring ()
    For $i = 1 To UBound ($notesini) - 1
        $tempstring = StringSplit ($notesini [$i], "=")
        If StringInStr ($tempstring [1], "AddInMenus") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCMenu")
        ElseIf StringInStr ($tempstring [1], "EXTMGR_ADDINS") > 0 Then
            $notesini [$i] = $tempstring [1] & "=" & _replacemystring ($tempstring [2], "NCExtMgr")
        EndIf
    Next
EndFunc

;see above
Func _replacemystring ($string, $replace)
    $string = StringReplace ($string, " ", "")
    $temp = StringSplit ($string, ",")
    $index = _ArraySearch ($temp, $replace) 
    _ArrayDelete ($temp, $index)
    $strtemp = _ArrayToString ($temp, ", ", 1)
    Return $strtemp
EndFunc

Func _SearchProfiledir()
    $profilelocation=Regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList","ProfilesDirectory") ;XP default is %SystemDrive%\Documents and Settings, vista might return %SystemDrive%\users
    $Command=@comspec & ' /c dir "'&$profilelocation&'\notes.ini" /s/b' 
    $pid=Run($command,@SystemDir,@SW_HIDE,$STDERR_MERGED)
    ProcessWaitClose($pid)
    $profilelist=StdoutRead($pid)
    $profilelist=StringSplit($profilelist,@CRLF,1)
    ;_ArrayDisplay($profilelist)
EndFunc

compiled it, and I'm seeing an error "Line -1:" "Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded"

sorry to be such a dumb ass on this stuff.

Link to comment
Share on other sites

That error is on the $ProfileList variable. You declared it as a global variable instead of an array. You should use Dim and declare an array.

Been reading up on Dim and Ubound, and are you saying I just need to change "Global $notesini, $profilelist" to "Dim $notesini, $profilelist" ?

I doubt it's that simple :)

Link to comment
Share on other sites

"Dim" won't solve the problem. Also the variable starts life as a single variable, and changes to an array.

The problem is this line:

For $i=0 to Ubound($profilelist) -1

It needs the "-1" or else it will exceed the size of the array. I'll modify my earlier post to reflect this.

Rock on, thanks man!
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...