Command line utility to edit ini files?

Microsoft Windows
Post Reply
Simon_Weel
Posts: 34
Joined: 2021-Dec-13, 3:53 pm

Command line utility to edit ini files?

Post by Simon_Weel »

NirCMD has the ability to modify ini files. However, it doesn't offer a way to check for existing values. So I went out to search for a command line utility with that capability. 'Initool' popped up but it doesn't work - at least not with Windows cmd. Couldn't find anything else?
Rekrul
Posts: 51
Joined: 2021-Aug-15, 11:29 pm

Re: Command line utility to edit ini files?

Post by Rekrul »

Simon_Weel wrote: 2023-Sep-14, 2:32 pm NirCMD has the ability to modify ini files. However, it doesn't offer a way to check for existing values. So I went out to search for a command line utility with that capability. 'Initool' popped up but it doesn't work - at least not with Windows cmd. Couldn't find anything else?
I just tested Initool and it works for me, however you have to be EXACT in what you tell it to look for. That means that the capitalization has to match what's in the INI file exactly. If even one letter's case is different, it won't match. Also, if a value is under a subsection, you MUST include the name of that subsection (capitalized perfectly) or it won't find it.

For example, consider this (partial) INI file;

Code: Select all

[MIXING]
Interpolation=4
Disable_Effects=FALSE
DealiasFilter=FALSE
FinalVolume=100
AdvancedVolumeControl=FALSE
The following commands will work;

initool get example.ini MIXING FinalVolume
initool get example.ini MIXING FinalVolume --value-only
initool exists example.ini MIXING FinalVolume (no message, errorlevel set)
initool set test.ini MIXING FinalVolume 200
initool delete test.ini MIXING FinalVolume

However the following commands will not work;

initool get example.ini "" FinalVolume (fails because key is in a subsection, which isn't specified)
initool get example.ini Mixing FinalVolume (fails because "MIXING" is not properly capitalized)
initool get example.ini MIXING finalvolume (fails because "FinalVolume" is not properly capitalized)

So it works, it's just REALLY picky.

It would be nice if the author added an option for case-insensitive matching, and an option to search the whole INI file, regardless of what section a key is under.
JoeC4281
Posts: 8
Joined: 2021-Jul-26, 12:51 pm

Re: Command line utility to edit ini files?

Post by JoeC4281 »

https://www.horstmuc.de/wbat32.htm#inifile

Code: Select all

E:\Utils>inifile.exe
INIfile.exe, ver. 1.92 /x64 (c) 2006-2017, Horst Schaeffer
Syntax:
   IniFile.exe IniFilePath [section] parameters
Parameters:     Function:
   item=string  assign
   item=        remove item
   item==       clear item
   item         read assignment *)
   /remove      remove section
   (none)       read all assignments of section *)
                *) sends SET statement(s) to STDOUT

TCC-RT https://jpsoft.com/all-downloads.html

@INIREAD https://jpsoft.com/help/index.htm?f_iniread.htm
@INIWRITE https://jpsoft.com/help/index.htm?f_iniwrite.htm

Joe
Simon_Weel
Posts: 34
Joined: 2021-Dec-13, 3:53 pm

Re: Command line utility to edit ini files?

Post by Simon_Weel »

Tried Horst Schaeffer tool, but it chokes on some values in the ini file. Didn't try TCC yet - it seems a bit intimidating...

I tried to add the ini file to this post, but that doesn't seem to work, so:

Code: Select all

[Revit.ini]
[Colors]
BackgroundColor=16777215
HiliteColor=12401408
PreHiliteColor=12401408
ErrorColor=33023
TemporaryColor=16776960
EditingColor=4259712
CustomColor1=00c2f3
CustomColor2=0000ff
CustomColor3=00ffff
CustomColor4=00ff00
CustomColor5=ffff00
CustomColor6=ff0000
CustomColor7=ff00ff
CustomColor8=ffffff
CustomColor9=ffffff
CustomColor10=ffffff
CustomColor11=ffffff
CustomColor12=ffffff
CustomColor13=ffffff
CustomColor14=ffffff
CustomColor15=ffffff
CustomColor16=ffffff
[Directories]
ProjectPath=P:\!ABN AMRO!\- GREENE en Yello\Revit Buildingblocks\Texturen\|L:\Revit_Support\NLRS_release_2.5.2\Materials\160222_NLRSv2.5.2_textures\
ImportLineweightsNameDWG=C:\Program Files\Autodesk\Revit 2021\Data\importlineweights-dwg-default.txt
MaterialLibraryFiles=..\Data\Rendering
IESFileLocation=C:\ProgramData\Autodesk\RVT 2021\IES\
LookupTableLocation=C:\ProgramData\Autodesk\RVT 2021\Lookup Tables\
OpenStudio=%ProgramFiles%\NREL\OpenStudio CLI For Revit 2021
ExternalParameters=L:\Revit_Support\KB Gegevensbestanden\KB_Shared_Parameters.txt        
ExportToClassIFC=L:\Revit_Support\KB Gegevensbestanden\exportlayers-ifc-IAI.txt
ImportIFCCategoryTable=L:\Revit_Support\NLRS_release_2.5.2\Support Files\Mappingtabellen\160222_NLRS2.5.2_IFC Import Mapping Table.txt
ImportIFCTemplate=L:\Revit_Support\KB Project Templates\KB_IFC_link-import_2021.rte
AdditionalRenderAppearancePaths=P:\!ABN AMRO!\- GREENE en Yello\Revit Buildingblocks\Texturen\|L:\Revit_Support\NLRS_release_2.5.2\Materials\160222_NLRSv2.5.2_textures\
ExportLayersNameDGN=..\..\..\ProgramData\Autodesk\RVT 2021\exportlayers-dwg-ISO13567.txt
[DirectoriesENU]
FamilyTemplatePath=L:\Revit_Support\KB Family Templates\2021
DataLibraryLocations=KB bibliotheek=L:\Revit_Support\KB Bibliotheek, Metric Library=..\..\..\ProgramData\Autodesk\RVT 2021\Libraries\Netherlands, Metric Detail Library=..\..\..\ProgramData\Autodesk\RVT 2021\Libraries\Netherlands\Detail Items
DefaultTemplate=KB_NLRSv2.5.2_2021=L:\Revit_Support\KB Project Templates\KB_NLRSv2.5.2_2021.rte, 2021 Template GREENE=P:\!ABN AMRO!\- GREENE en Yello\Revit Buildingblocks\2019 Template GREENE.rte
SystemsAnalysisWorkflows=Annual Building Energy Simulation=C:\Program Files\NREL\OpenStudio CLI For Revit 2021\workflows\Annual Building Energy Simulation.osw, HVAC Systems Loads and Sizing=C:\Program Files\NREL\OpenStudio CLI For Revit 2021\workflows\HVAC Systems Loads and Sizing.osw
[UserInterface]
ViewSwitchingOrder=0
DisplayRecentFilesPage=1
DisciplineOption=30108
UseHardwareAcceleration=1
CategoryDisciplineFilter=63
[Language]
Select=ENU
[Applications]
Mechanical=0
Electrical=0
Architectural=1
Structural=0
[InstallationSettings]
Language=ENU
Usage=All
[Install]
InstallGUID={67AC3D7D-3086-4806-9A18-C9A72465F1AD}
[Graphics]
FreezeScheduleHeader=0
TempDimFontSizeInPoints=14
OptimizedViewNavigation=1
Antialiasing=1
AntialiasingOptions=1
SemiTransparent=1
ThinLinesEnabled=1
ShowMaterialEditor=1
UseGraphicsHardware=0
AllowNavigationDuringRedraw=1
UseGpuOcclusionCulling=0
TempDimTextBackground=1
[Misc]
SSOServer=0
[Windows]
Maximized=1
[Spelling]
OptionFlagsSSCE=18
[ViewOptions]
DefaultViewDiscipline=Architecture
[Partitions]
WorksharingDisplayFrequency=5
Username=Siem_Weel
[AppFrame]
Theme=0
[ACMSettings]
ACMOnNetwork=1
ACMNetworkPort=14931
[AutoCam]
SteeringWheelShowHUDMessages=1
SteeringWheelShowTooltips=1
SteeringWheelShowToolCursorText=1
BigSteeringWheelSize=1
BigSteeringWheelOpacity=1
MiniSteeringWheelSize=1
MiniSteeringWheelOpacity=1
SteeringWheelInvertVerticalAxis=0
SteeringWheelConstrainWalkAngleToGround=1
SteeringWheelSpeedFactor=30
SteeringWheelEnableIncrementalZoomIn=0
SteeringWheelKeepSceneUpright=1
ViewCubePosition=0
ViewCubeOpacity=2
ViewCubeSize=4
ViewCubeSnapToClosestView=1
ViewCubeFitToView=1
ViewCubeUseAnimatedTransition=1
ViewCubeKeepSceneUpright=1
ShowViewCube=1
NavBarActiveWheel=6
[Macro]
AppSecurity=0
UIDocSecurity=0
[Selection]
AllowFaceSelection=1
AllowUnderlaySelection=0
AllowPressAndDrag=0
AllowPinnedSelection=1
AllowLinkSelection=1
[DNSM]
TaskDialog_Confirm_Create_New_Local=1
TaskDialog_Wall_Attach_To_Floor=1002
[Messages]
SuppressForceRasterPrintingWarning=1
SuppressShowButtonMessage=1
SuppressShowMassWarning=0
[Prompts]
TooltipAssistance=99
[Recent File List]
[Recent Workset List]
Config1=All
Config2=All
Config3=All
Config4=All
Config5=All
Config6=All
Config7=All
Config8=All
Config9=All
Config10=All
Config11=All
Config12=All
Config13=All
Config14=All
Config15=All
Config16=All
Config17=All
Config21=All
Config23=All
Simon_Weel
Posts: 34
Joined: 2021-Dec-13, 3:53 pm

Re: Command line utility to edit ini files?

Post by Simon_Weel »

Rekrul wrote: 2023-Sep-16, 1:12 am I just tested Initool and it works for me, however you have to be EXACT in what you tell it to look for.
This has been fixed in a new version. However, there's another snag - it can only handle UTF-8 coded files. The ini files I like to modify are written as UTF-16 by the application. I guess there's a way to convert the file first and then modify it, but it's getting rather convoluted...

Edit: just found a util that does it all: https://github.com/jackdp/IniMod
Simon_Weel
Posts: 34
Joined: 2021-Dec-13, 3:53 pm

Re: Command line utility to edit ini files?

Post by Simon_Weel »

Ok, I've been working with this new inimod util to put it to work. Now the idea is to check a bunch of settings in Revit ini files. For those who might think Revit is ancient because it uses ini files - no, it's not. For some incomprehensible reason, Autodesk decided to use all kinds of configuration files, registry settings and the lot to store configuration data of all it's applications. For Revit, this is mostly ini files, with some settings in the registry. And for AutoCAD, it's a cfg file which basically contains registry keys. GPO is something Autodesk never heard of. Real fun to handle all those applications!

Back to Revit. The ini file contains a number of mandatory paths for support files. Besides those mandatory paths, users can define additional, project-specific, paths. Every once in a while, those mandatory paths change. To bulk-udate the ini files of all users, I used NirCMD. Drawback is it overwrites any user defined paths. With this new util, I can read the existing values and check if they contain the mandatory values as well. That wasn't as easy as I thought it would be. This is what I came up with:

Code: Select all

@echo off

rem call- line to retrieve values of a specific Revit.ini file
call :_compare H:\Revit.ini Directories ProjectPath "P:\Revit Buildingblocks\Texturen\|L:\Revit_Support\textures\"

goto _end

rem subroutine retrieving values of the ini file

:_compare

rem Routine with 4 arguments:
rem		1 - path to Revit.ini
rem		2 - section to check
rem		3 - key to check
rem		4 - mandatory text for key

rem test if all arguments are there
if (%4)==() EXIT /B

rem Check line in ini file
for /f "delims=" %%G in ('inimod r %1 -s %2 -k %3 --silent') do set _line=%%G

Rem use Find to check if the mandatory value is contained within the retrieve line
Rem errorlevel 0 means the value is found.

echo "%_line%" | find /I %4 1>nul

if [%errorlevel%]==[0] goto stop

rem If necessary, change line
rem The tilde ~ in %~4 strips quotes from the line of text
rem Quotes are necessary when writing back the complete line

rem Write modified line to ini file
inimod w %1 -s %2 -k %3 -v "%~4%_line%" --silent

rem remove comments from ini file
inimod rfc %1 --silent

rem write new comment to ini file
inimod wfc %1 -c "File modified %date% -- %time%" -x 5 --silent

:stop

EXIT /B

:end
Any idea's on improvements?
Simon_Weel
Posts: 34
Joined: 2021-Dec-13, 3:53 pm

Re: Command line utility to edit ini files?

Post by Simon_Weel »

Silly me - forgot about the most important part: to modify existing values. Duh. Have to figure that out...
Post Reply