Sign in to follow this  
Followers 0
ViciousXUSMC

Need help with selective editing of a config file

9 posts in this topic

So I am trying to take a program that installs and has per user profile settings and deploy it in an enterprise scenario where I will have over 80 people per computer that I need to set settings for.

I tracked down the programs configuration file to an AppData directory, so I used this script to copy it to all current users and the default profile user so that new users would have the file already applied at first log on.

;Push to all users Local AppData including Default User

$folder = StringLeft(@UserProfileDir,StringInStr(@UserProfileDir,"\",0,-1))
$search = FileFindFirstFile($folder&"*")
While 1
    $profile = FileFindNextFile($search)
    If @error Then ExitLoop
    If FileExists($folder&$profile&"\AppData\Local") Then
        ;DirCreate($folder&$profile&"\AppData\Local\bluesoleil")
        DirCopy(@ScriptDir & "\bluesoleil", $folder&$profile&"\AppData\Local\bluesoleil", 1)
    EndIf
WEnd
FileClose($search)

Well that did not work so well... I think it broke the program and upon second look at the config file I saw there are lines specific to the profile like "CURRENTUSERNAME" so I cant use a "master" copy.

So now onto this thread topic, is there a way to parse a config file and then with AutoIT make selective changes to the document easily?

Theory: Search the config file for the line starting with "CURRENTUSERNAME" and replace that line by copying the entire line, using a stringtrim and then pasting in the current user profile name via the macro for @UserName and then save the file.

Here is a copy of the config file to help make sense of it.

[AudioDeviceInfo]
AudioDevice=53007000650061006B00650072007300200028005200650061006C00740065006B0020004800690067006800200044006500660069006E006900740069006F006E00200041007500640069006F00290000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004D006900630072006F00700068006F006E006500200028005200650061006C00740065006B0020004800690067006800200044006500660069006E006900740069006F006E00200041007500640069006F0029000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000010000007C
[LocalBluetooth]
FirstRuninCurrentUser=0
CURRENTUSERNAME=frpatrmo
LocalDiscoveryMode=13
[OPPSERVER]
INBOXFOLDER=C:\Sansio\Bluetooth
OUTBOXFOLDER=C:\Sansio\Bluetooth
OWNCARDNAME=TOUGHBOOK5828.vcf
VCARD_SUPPORT=259
[FTPSERVER]
SHAREFOLDER=C:\Sansio\Bluetooth
DESIRED_ACCESS=1
[BIPSERVER]
BIPFOLDER=C:\Sansio\Bluetooth
[Ad]
UpdateTimer=168
OverTime=1419517321

While I am stuck on this I'll see about just automating the changes with standard stuff (winwait, send input, etc) but I definitly want to see if there is a better soltion along the lines of what I have in mind above.

Thanks for the help.

Share this post


Link to post
Share on other sites



ViciousXUSMC,

That looks like a standard ini file format - you should be able to use the Ini* functions to modify it very easily. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

As Melba points out, the ini files should be easy to manipulate. However, if you're looking to manipulate the installation itself (and it is an MSI) I would suggest Googling Active Setup; you can configure this with an open source tool such as Orca. You configure the setting, and then if the system sees anything "missing" for the user, it will automatically install it silently. It's clean, silent, and will work for any new user who logs into the system.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Just updating that I have a working script, it's crude and I am sure there is a better way to go about this, but atleast its working.

$file = FileOpen ( "C:\Users\" & @UserName & "\AppData\Local\bluesoleil\bsps.ini", 0 )

Dim $Contents
While 1
   $Line = FileReadLine ( $file )
   If @error Then Exitloop
   If $Line = "LocalDiscoveryMode=8" Then $Line = "LocalDiscoveryMode=13"
   If $Line = "LocalDiscoveryMode=9" Then $Line = "LocalDiscoveryMode=13"
   If $Line = "VCARD_SUPPORT=771" Then $Line = "VCARD_SUPPORT=259"
   If $Line = "INBOXFOLDER=C:\Users\" & @UserName & "\Documents\Bluetooth\inbox\" Then $Line = "INBOXFOLDER=C:\Sansio\Bluetooth\"
   If $Line = "SHAREFOLDER=C:\Users\" & @UserName & "\Documents\Bluetooth\Share\" Then $Line = "SHAREFOLDER=C:\Sansio\Bluetooth\"
   $Contents = $Contents & @CRLF & $Line
WEnd
FileClose ( $file )
$file = FileOpen ( "C:\Users\" & @UserName & "\AppData\Local\bluesoleil\bsps.ini", 2 )

FileWrite ( $file, $Contents )
Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

ViciousXUSMC,

That looks like a standard ini file format - you should be able to use the Ini* functions to modify it very easily. :)

M23

 

Thanks for this (and others who also suggested) I had not known about these.  I already wrote that one script before I saw these replies.  I just recreated it with a simple 4 line script.

Is this the cleanest way to use the .ini functions?  Simply a write statment over and over, feels dirty because its too easy lol.  Am I missing anything to make it more "professional" or a way to keep the file open for all writes without probably opening and closing it 4 times (not a big deal)

IniWrite("C:\Users\" & @UserName & "\AppData\Local\bluesoleil\bsps.ini", "OPPSERVER", "INBOXFOLDER", "C:\Sansio\Bluetooth\")
IniWrite("C:\Users\" & @UserName & "\AppData\Local\bluesoleil\bsps.ini", "OPPSERVER", "VCARD_SUPPORT", "259")
IniWrite("C:\Users\" & @UserName & "\AppData\Local\bluesoleil\bsps.ini", "LocalBluetooth", "LocalDiscoveryMode", "13")
IniWrite("C:\Users\" & @UserName & "\AppData\Local\bluesoleil\bsps.ini", "FTPSERVER", "SHAREFOLDER", "C:\Sansio\Bluetooth\")

Share this post


Link to post
Share on other sites

Try like this:

$sINI = @AppDataDir & "\Local\bluesoleil\bsps.ini"
IniWrite($sINI, "OPPSERVER", "INBOXFOLDER", "C:\Sansio\Bluetooth\")
IniWrite($sINI, "OPPSERVER", "VCARD_SUPPORT", "259")
IniWrite($sINI, "LocalBluetooth", "LocalDiscoveryMode", "13")
IniWrite($sINI, "FTPSERVER", "SHAREFOLDER", "C:\Sansio\Bluetooth\")

Then, if you change your INI location, you need only change it once.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Try like this:

$sINI = @AppDataDir & "\Local\bluesoleil\bsps.ini"
IniWrite($sINI, "OPPSERVER", "INBOXFOLDER", "C:\Sansio\Bluetooth\")
IniWrite($sINI, "OPPSERVER", "VCARD_SUPPORT", "259")
IniWrite($sINI, "LocalBluetooth", "LocalDiscoveryMode", "13")
IniWrite($sINI, "FTPSERVER", "SHAREFOLDER", "C:\Sansio\Bluetooth\")

Then, if you change your INI location, you need only change it once.

 

Fair enough, this was my final config

The @AppDataDir wont quite work I think it takes you directly to the Roaming subdirectory of AppData

$pINI = "C:\Users\" & @UserName & "\AppData\Local\bluesoleil\bsps.ini"

If FileExists($pINI) Then

IniWrite($pINI, "OPPSERVER", "INBOXFOLDER", "C:\Sansio\Bluetooth")
IniWrite($pINI, "OPPSERVER", "VCARD_SUPPORT", "259")
IniWrite($pINI, "LocalBluetooth", "LocalDiscoveryMode", "13")
IniWrite($pINI, "FTPSERVER", "SHAREFOLDER", "C:\Sansio\Bluetooth")

MsgBox(0, "Auto Installer", "The Bluesoleil settings for " & @UserName & " have been configured and saved.")


Else
    MsgBox(0, "Auto Installer", "The configuration file for Bluesoleil was not found and no actions were taken")
    EndIf
Edited by ViciousXUSMC

Share this post


Link to post
Share on other sites

You are correct, apologies I glossed over that you were going into the local directory.


√-1 2^3 ∑ π, and it was delicious!

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