Script to add the contents clipboard on a particular line of ini file

Page 1 of 2 12 LastLast

  1. Posts : 943
    windows 10 professional 64-bit, 22H2
       #1

    Script to add the contents clipboard on a particular line of ini file


    I have O&O Registry Editor. It uses an ini file, to remember the last opened registry key. I would like to have a script that would copy the contents of the clipboard to the line called:
    LastAddress=

    I've researched modifying ini files, but don't know the way to copy & insert the clipboard contents to this ini file. Can anyone help?

    Thank you in advance!
      My Computers


  2. Posts : 42,735
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi Autohotkey (free scripting language) should be able to do that.

    It can use the clipboard and manipulate text strings from a file.

    Examples of some of the many commands:
    Script to add the contents clipboard on a particular line of ini file-1.pngScript to add the contents clipboard on a particular line of ini file-2.pngScript to add the contents clipboard on a particular line of ini file-3.pngScript to add the contents clipboard on a particular line of ini file-4.png
      My Computers


  3. Posts : 943
    windows 10 professional 64-bit, 22H2
    Thread Starter
       #3

    dalchina said:
    Hi Autohotkey (free scripting language) should be able to do that.

    It can use the clipboard and manipulate text strings from a file.

    Examples of some of the many commands:
    Script to add the contents clipboard on a particular line of ini file-1.pngScript to add the contents clipboard on a particular line of ini file-2.pngScript to add the contents clipboard on a particular line of ini file-3.pngScript to add the contents clipboard on a particular line of ini file-4.png
    Thank you. I forgot about AutoHotkey. I will give this a try.

    - - - Updated - - -

    Well, I tried this to change the line
    LastAddress=
    but somehow I'm missing something in my understanding.

    ; this is to test making a script to change the 5th line of an ini file , that says, LastAddress=SomeText, & insert clipboard contents after the =

    FileRead, 5thLine, "C:\Users\Phil\Desktop\TestOOReg.INI",
    FoundPos := InStr(LastAddress=, * [, CaseSensitive = false, StartingPos = 1, Occurrence = 1])
    StringReplace, clipboard, clipboard, LastAddress=, LastAddress=clipboard, All ; Replace all occurrences of ABC with DEF (also converts the clipboard to plain text).
      My Computers


  4. Posts : 42,735
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #4

    A couple of quick comments just at a glance that could be quite wrong:
    First, comments help to indicate your intent. Without those, I'm slightly guessing.
    What your first line does is to read the whole file content into '5thLine'.
    If you actually meant to read just the 5th line, wouldn't

    Filereadline

    be more appropriate?

    Instr(haystack

    haystack should be 5thline shouldn't it- assuming you are aiming to search just the 5th line.

    I could be wrong about what you're aiming to do of course.


    Sorry, am busy working out how to recreate a recovery partition from scratch, just to see if it's possible- made some useful progress today with DISM commands.

    I've not used string handling in Auothotkey myself, so you might try its forum.
    My experience of even simple scripts is you have to look, fiddle, and experiment with each part as necessary using e.g. msgbox to check values, variables and so on.

    Test the result of each separate element as far as you can separately.
      My Computers


  5. Posts : 7,606
    Windows 10 Home 20H2
       #5

    phrab said:
    ; this is to test making a script to change the 5th line of an ini file , that says, LastAddress=SomeText, & insert clipboard contents after the =
    Can you post the contents of the .ini file?
    It is possible to write a new file using the contents of both the file and clipboard.
      My Computer


  6. Posts : 943
    windows 10 professional 64-bit, 22H2
    Thread Starter
       #6

    Matthew Wai said:
    Can you post the contents of the .ini file?
    It is possible to write a new file using the contents of both the file and clipboard.
    Thank you for responding, Matthew. The ini file is long, but here is the beginning of the contents of the ini file. The line that says
    LastAddress=Whatever
    is what I'm trying to change. I want to be able to copy a registry path from the internet & replace the "Whatever" above with that path, which is now in the clipboard.
    The first lines are
    [Settings]
    AppStartCounter=10
    FileTypeAnswer=2
    WndPlacement=32:32:1440:756:1:0
    LastAddress=HKEY_CURRENT_USER\Software
    AddrList1=HKEY_CURRENT_USER\Software\AvastAdSDK
    AddrList2=HKEY_CURRENT_USER\Software\Acronis

    I appreciate your help.
      My Computers


  7. Posts : 7,606
    Windows 10 Home 20H2
       #7

    1. Click here to download "Testing.vbs".
    2. Copy any text into the clipboard.
    3. Double-click on "Testing.vbs".
    4. An .ini file will be created in the current working directory.
    5. The copied text will be right after "LastAddress=" in the .ini file.
    Script to add the contents clipboard on a particular line of ini file Attached Files
      My Computer


  8. Posts : 943
    windows 10 professional 64-bit, 22H2
    Thread Starter
       #8

    TestOOReg.txt
    Matthew Wai said:
    1. Click here to download "Testing.vbs".
    2. Copy any text into the clipboard.
    3. Double-click on "Testing.vbs".
    4. An .ini file will be created in the current working directory.
    5. The copied text will be right after "LastAddress=" in the .ini file.
    Thank you again, Matthew!. Yes, your testing.vbs works. However, I apologize for not being clear, so I'm not out of the woods yet. The ini file has the settings for O&O Registry Editor. Whenever I use the app, the settings in the ini file will change...i.e. a number of the lines will be different, as they are not constants. What I want to do is change only that one line (the LastAddress= to whatever is in the clipboard) & leave all the other lines alone.

    I've attached the ini file, so that you can see, but even the lines

    AddrList1=HKEY_CURRENT_USER\Software\AvastAdSDK
    AddrList2=HKEY_CURRENT_USER\Software\Acronis

    will change each time I use the app. I want to leave every line alone except the LastAddress line.
    TestOOReg.txt

    [Edited: for some reason, I can attach a file so that it can be read without downloading it]TestOOReg.txt
      My Computers


  9. Posts : 989
    Microsoft Windows 10 Home
       #9

    PowerShell:
    Code:
    $IniFile = 'c:\Path\To\file.ini'
    $NewText = gcb
    (gc $IniFile -Raw) -replace '(?<=LastAddress=).+(?=\n)', $NewText | sc $iniFile
    Last edited by KeithM; 30 May 2020 at 19:21. Reason: Forgot Set-Content (sc)
      My Computer


  10. Posts : 2,450
    Windows 10 Pro x64
       #10

    Copy and paste the following three lines of code into a text file.
    In the 1st line replace within the quotes the path of your .ini file.
    Save the text file with an extension ps1, for example Test.ps1

    Code:
    $INIFile = "C:\Users\<UserName>\Desktop\OOreg.ini"
    $LastAddressFromClipboard = Get-Clipboard -Format Text -TextFormatType UnicodeText
    (Get-Content $INIFile | ForEach-Object { $_ -replace "LastAddress=.+", "LastAddress=$LastAddressFromClipboard" }) | Set-Content $INIFile

    Copy to the clipboard the address you want to save in your .ini file
    Open File Explorer and go to the folder where you saved the Test.ps1 file.
    In File Explorer select File > Open Windows PowerShell (either as user or Administrator, I prefer Administrator)
    In the PowerShell console window type .\Test.ps1

    That's it!
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:36.
Find Us




Windows 10 Forums