Hobbyist Posted July 16, 2018 Share Posted July 16, 2018 Hello Here is my script attempt to edit an INI file for the uninstall INI file. I want to run a routine before the uninstall begins, so I am inserting its call before the registry key since uninstall is the reverse of install. It worked, but I am asking if its the best approach or efficient approach. Or any suggestion by the pros here. Thanks much. ;read INI file into array local $myINI = FileReadToArray ( "L:\Uninstall.ini") ;increase array size ReDim $myINI [UBound($myINI) + 5] ;second array to find position of registry key Local $aiResult = _ArrayFindAll($myINI, "[RegistryKeys]") ;move registry key and section down and put blanks in original position $myINI [$aiResult[0] + 3] = $myINI[$aiResult[0]] $myINI [$aiResult[0] + 4] = $myINI[($aiResult[0] + 1)] $myINI [$aiResult[0] ]= " " $myINI [$aiResult[0] +1] = " " ;insert desired key and section $myINI [$aiResult[0]]= "[ExecBeforeUninstall]" $myINI [$aiResult[0]+1] = "0=C:\Dash Board\Backup Before Deletion\Backup Before Deletion.exe*?*?NORMAL*?YES*?NO" ;write array to original INI file $sFilePath = "L:\Uninstall.ini" _FileWriteFromArray($sFilePath, $myINI, 0) Link to comment Share on other sites More sharing options...
Subz Posted July 17, 2018 Share Posted July 17, 2018 Don't understand the logic, if you're using Ini functions for example: IniReadSection or IniRead it doesn't matter about the order of the section names. For example: [Uninstall] [Install] [ExecBeforeUninstall] You can call the sections in your predefined order. IniRead("IniFile", "ExecBeforeUninstall", "0", "") IniRead("IniFile", "Uninstall", "0", "") IniRead("IniFile", "Install", "0", "") Rather than using FileWrite you can use IniWrite for example: nb: Section Name is created if it doesn't already exist. IniWrite("IniFile", "ExecuteBeforeUninstall", "0", "C:\Dash Board\Backup Before Deletion\Backup Before Deletion.exe*?*?NORMAL*?YES*?NO") KickStarter15 and FrancescoDiMuro 2 Link to comment Share on other sites More sharing options...
Hobbyist Posted July 17, 2018 Author Share Posted July 17, 2018 @Subz Thanks for taking a look at this and your comment. I am new at this, so going around the world to cross the street sometimes shows up in my approach - HA. I had checked out the ini functions, but thought , in the write function, I had no control over "where" it was written in the ini file, if it was not originally in the file - thus finding it at the end when I would write(add) it. In this case the "ExecuteBefore Uninstall" would show up after the RegistryKey which is the last line in the original ini file. My Uninstall.ini file comes from a third party software and is created at its setup time. The ExecuteBefore Uninstall is NOT part of the original Uninstal.ini file and I want to add it into (edit) the original so as to include it if the Uninstall takes place. It is my understanding the Uninstall third party executes in the reverse order of the Install part of the setup program. So now you have me thinking (enlightened) the Uninstall part of the third party software would "call" each section name, no matter its sequential place in the Uninstall.ini file. And the reverse order is actually in the Uninstall code itself. If this is true, then my approach is way off base and what you present makes sense. Do I understand you correctly? And my whole objective in "ExecuteBeforeUninstall" is to backup all the data and prevent its loss since the third party program does not offer that. When the EXecuteBeforeUninstall is called my own script backs up my data and then the Uninstall proceeds. Thanks so much for helping me. And any other useful tips are appreciated. Hobbyist. Link to comment Share on other sites More sharing options...
Bert Posted July 17, 2018 Share Posted July 17, 2018 look at the Vollatran Project. For what you are doing it may help. Link is in my signature. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Subz Posted July 17, 2018 Share Posted July 17, 2018 @Hobbyist A lot depends on the software that created the "Uninstall.ini", does it understand the "ExecuteBeforeUninstall" section of the Ini? If it does than it shouldn't matter which order the sections are in, as the software should know the order to run, i.e. "ExecuteBeforeUninstall" section than the "Uninstall" section. Link to comment Share on other sites More sharing options...
Hobbyist Posted July 17, 2018 Author Share Posted July 17, 2018 @Subz You have cleared up much for me, thank you. The software installs a Uninstall executable, for purposes of uninstalling the software, The Uninstall.ini file has the "ExecuteBefore Uninstall" section as an option when doing the original install. If you choose it, it is part of the install, if you don't you won't see it in the Uninstall.ini. But if you add the ExecuteBefore Uninstall to the Uninstall.ini file that does NOT have it, you can get the same results as if you set it up to include it. So yes it knows what to do with it. I thought it had to be in a specific location in the ini file, thus my script attempt to make it show up before the RegistryKeys section which was the last record(section). Now, as I understand you - a section can be called out of it sequential location within the ini file if you use the inWrite/Read functions, thus I only need to write the "ExecuteBeforeUninstall" to the ini file and it be added as the last record(in my case). I was confusing its appearance in the ini file with the fact the Uninstall executable does the uninstall in reverse order of the original setup. Thank You so much for your time, patience and guidance. Hobbyist 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