Sign in to follow this  
Followers 0
StefanS

maximum characters ins _FileWriteToLine?

21 posts in this topic

I am trying to change a line in file.

Unfortunately the line is very long and I want to overwrite it with an even longer line.

Autoit stops after 4060 characters …is that the maximum?

If so… is there a way work around that Limit?

I need to write a line with rd. 29000 characters :ermm:

Best

Stefan

Share this post


Link to post
Share on other sites



StefanS,

Welcome to the AutoIt forum. :)

Why even think of FileWriteLine for something of this magnitude? Can you give us an idea of the structure of this file with amazingly long lines - there is almost certainly a better way to replace the data. ;)

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

Hey and thank you for the quick response!

Well, the line I’m trying to edit is an encrypted site definition of our VPN Client.
Therefore it has to be in one line in that specific file.

Copying the file is not an option.
I see no other way to exchange the data in there.

Best

Stefan

Share this post


Link to post
Share on other sites

StefanS,

I understand that you need to change that chunk of text and that it appears to be a "line" in teh file - but that does not mean you need to use FileWriteLine. If you have the permissions to change the file using that function, you should be able to rewrite it completely using - so I suggest reading the file into memory and then extracting the data before and after the part to be changed before pre/suffixing them around the new data and then rewriting the whole thing. ;)

That is why I asked about the internal structure of the file - how do we determine where to split it? You must be able to identify the line number (or _FileWriteLine would not have been an option) - so how about trying _FileReadToArray? That gets each line into a separate element of the array and then all you would need to do would be to change that one element before rewriting the file using _FileWriteFromArray. Give it a try and let us know how you get on. :)

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

Hey Melba23,

i think there is no split point.

I identify the line number .... because there is just one line  :unsure:

and... the whole text has to be replaced ... not just a part of it :(

Best

Stefan

Share this post


Link to post
Share on other sites

StefanS,

 

the whole text has to be replaced

Then why are you using FileWriteLine in the first place? Why not just use FileWrite directly? :huh:

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

Hey Melba23,

uhm... i thought FileWrite is just to add text to file, not to overwrite text ... :unsure:

Best

Stefan

Share this post


Link to post
Share on other sites

StefanS,

Use FileOpen with the $FO_OVERWRITE flag - then use the returned handle in the FileWrite command - and do not forget to FileClose when you are done. ;)

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

Yepp!

Tried that :)

But the result is the same :(

It stops after rd 4070 characters

Best

Stefan

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

StefanS,

How do you pass the data to the FileWrite command? Are you writing it manually in a single line? Becasue that will run into the line character limit.

What you should do is store the entire thing into a single variable and then pass that:

#include <FileConstants.au3>

$sData = "################################"
$sData &= "################################"
; etc, etc so that no line is over the 4095 limit

$hFile = FileOpen("Your_File_Name", $FO_OVERWRITE)
; Now pass it all in one go
FileWrite($hFile, $sData)
FileClose($hFile)
i have just written a 17Mb file like that to test it - so you should be good to go with a mere 29kb. ;)

M23

Edit: And I have lifted your "New Member" posting restriction - so this can go on an on and on and .... (if we really have to)! :D

Edited by Melba23
1 person likes this

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

Hey Melba23

Ahhhhh....!!! So there is a line character limit ... didn't know that....

Will try your solution later today and let you know!

Best

Stefan

PS thanks for lifting me up :)

Share this post


Link to post
Share on other sites

 Hey Melba23...

It works!!!

Great job!! Thank you!

but... now i ran into the next problem... :(

everything works well with a test file in an unprotectet directory...

But unter Win7 C:Program Files (x86)... is protectet....

I thougt "Hey .. not a big deal... run the FileOpen as "Runas" command...

Here is the point where i fail again :(

This is what i tried:

$file = RunAs($suser, $slocal, $spwd, 0, FileOpen("C:Program Files (x86)testTest.config", 2))

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
 

RunAs($suser, $slocal, $spwd, 0, FileWrite($file, $SData))

RunAs($suser, $slocal, $spwd, 0, FileClose($file))

tried RunAsWait as well ... same result...

nothing happens.... not even a "Unable to open file" msg.... just .. nothing...?

Any idea?

Best

Stefan

Share this post


Link to post
Share on other sites

FileOpen is an AutoIt function, you can't use RunAs on an internal function. You could try using #RequireAdmin at the top of the script to run the script as an admin.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

StefanS,

What ^ he said! :D

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

To sad!

:(

 

#RequireAdmin is not an option, because the user has to accept it, right?

i need to write that file without user interaction

Best

Stefan

Share this post


Link to post
Share on other sites

Scheduled tasks, to run as a user with admin rights, as highest security level.  Security issue, someone changes your script to do something they would not be able to have done otherwise :)


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Your only other option that I can think of is to have a companion exe file that does the file operations for you that you use RunAs/RunAsWait to start from your main script. That way your main script doesn't need admin rights, your companion script won't need #RequireAdmin, and the user doesn't see anything. The only flaw to that is that the username and password aren't 100% safe in the script so if the user has access to the main script, they COULD get that information from it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Good Morning! :bye:

I played around a bit last night and i think i found a solution that fits for me.

1. RunAs using icacls to change the file permissions so that usergroup S-1-5-32-545:F (Users) can write the file

2. RunAs using net stop to stop the VPN Service

3. FileOpen, FileWrite and FileClose as normal user (THANKS to Melba23 helping me with that!)

4. RunAs using icacls to change back the file permissions

5. RunAs using net start to start the VPN Service again.

What do you think?

If I do it that way, i have all in one file.

That's what i wanted.

@BrewmanNH

Okay... username and password for the local admin are in the script, but if i compile it it is nearly save, isn't it?

Or is there a real working decompiler on the market now?

I remember a while ago i searched for a decompiler, because i lost some source code and i ended up writing the script new.

Best

Stefan

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