Blue0 Posted July 27, 2020 Share Posted July 27, 2020 Can't get _FileWriteToLine to work in Windows Server 2012 R2 64-bit 6.3 Build 9600. #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> _FileWriteToLine("C:\Temp\test.txt", 3, "", True) Is there another way to empty or delete a row that would work in WServer2012? Link to comment Share on other sites More sharing options...
Marc Posted July 27, 2020 Share Posted July 27, 2020 Just tried it on a Server 2012R2, works fine (deleted line 3 of my test-file) How about adding another line if @error Then MsgBox(16, "error", @error) ? Blue0 1 Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Blue0 Posted July 27, 2020 Author Share Posted July 27, 2020 Added that and no msgbox. Link to comment Share on other sites More sharing options...
Marc Posted July 27, 2020 Share Posted July 27, 2020 Then the 3rd line of your file should be empty... 🤨 at least in my tests, if I create a file 1 2 3 4 5 6 and run the script, the resulting file is (as it should be) 1 2 4 5 6 What does your resulting file look like? Blue0 1 Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
Blue0 Posted July 27, 2020 Author Share Posted July 27, 2020 (edited) On my w10 it works and there's empty space on 3rd row. But on the server the same .exe doesn't do anything. 3rd row still shows "3" and the if @error doesn't pop up a msgbox. Script finishes because the process disappears from the list and from the toolbar. I've tried compiling as both x86 and x64. Tried enabling UPX. Changed fileinstall compression from lowest to highest. Is the server missing something to run the function? Edited July 27, 2020 by Blue0 Link to comment Share on other sites More sharing options...
water Posted July 27, 2020 Share Posted July 27, 2020 (edited) Which version of AutoIt do you run on the client and the server? IIRC the way how AutoIt deletes lines has been changed lately. discussed in this thread. Edited July 27, 2020 by water Added the link to the thread where the subject has been discussed. Blue0 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Dan_555 Posted July 27, 2020 Share Posted July 27, 2020 Maybe your executable needs admin permissions to delete/modify files on the win server ? Blue0 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
water Posted July 27, 2020 Share Posted July 27, 2020 In this case _FileWriteToLine should return an error (3 - Error when opening file). Blue0 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Dan_555 Posted July 27, 2020 Share Posted July 27, 2020 (edited) Well, idk how it is there, but i remember here on windows 10, if a program (32bit crimson editor in this case) is ran from the program files (x86), it saves the settings, but not in it's folder but in some virtual folder (called VirtualStore). (this happened with few other programs, which made me install/run all other apps from a different folder) If this happens on the server too, then there would be no error, because the changes were made, but the original file may be untouched. But ofc idk anything about the server version. Edited July 27, 2020 by Dan_555 Blue0 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Blue0 Posted July 27, 2020 Author Share Posted July 27, 2020 (edited) 1 hour ago, water said: Which version of AutoIt do you run on the client and the server? IIRC the way how AutoIt deletes lines has been changed lately. discussed in this thread. AutoIt v3.3.14.5. SciTE 4.1.2.0. I don't have AutoIt on the server. I'm copying the compiled .exe from my W10 computer to the server. 28 minutes ago, Dan_555 said: Maybe your executable needs admin permissions to delete/modify files on the win server ? Tried adding #requireadmin to the script. I also ran the .exe as admin logged in with admin account. Also tried logging in with non admin and ran the .exe as admin. FileWriteLine works but _FileWriteToLine doesn't and no msgbox #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> $FileName = "C:\Temp\test.txt" $hFile = FileOpen($FileName, 1) FileWriteLine($hFile, "test1") FileWriteLine($hFile, "test2") FileWriteLine($hFile, "test3") FileWriteLine($hFile, "test4") FileWriteLine($hFile, "test5") FileWriteLine($hFile, "test6") _FileWriteToLine("C:\Temp\test.txt", 3, "", True) if @error Then MsgBox(16, "error", @error) FileClose($hFile) Edited July 27, 2020 by Blue0 Link to comment Share on other sites More sharing options...
r2du-soft Posted July 27, 2020 Share Posted July 27, 2020 hi test this #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> ;------------------ $sFilePath = "C:\Temp" If Not FileExists($sFilePath) Then DirCreate($sFilePath) EndIf ;--------- $FileName = "C:\Temp\test.txt" $hFile = FileOpen($FileName, 1) FileWriteLine($hFile, "test1") FileWriteLine($hFile, "test2") FileWriteLine($hFile, "test3") FileWriteLine($hFile, "test4") FileWriteLine($hFile, "test5") FileWriteLine($hFile, "test6") FileClose($hFile) ;--------- _FileWriteToLine("C:\Temp\test.txt", 3, "", True) if @error Then MsgBox(16, "error", @error) ;------------------ Blue0 1 Link to comment Share on other sites More sharing options...
water Posted July 27, 2020 Share Posted July 27, 2020 (edited) Could you move the FileClose after the last FileWriteLine? This way the file is properly written to disk and the cache is emptied before calling _FileWriteToLine which reopens the file. #include <File.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> $sFileName = "C:\Temp\test.txt" $hFile = FileOpen($sFileName, 1) FileWriteLine($hFile, "test1") FileWriteLine($hFile, "test2") FileWriteLine($hFile, "test3") FileWriteLine($hFile, "test4") FileWriteLine($hFile, "test5") FileWriteLine($hFile, "test6") FileClose($hFile) _FileWriteToLine($sFileName, 3, "", True) If @error Then MsgBox(16, "error", @error) Edited July 27, 2020 by water Blue0 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Blue0 Posted July 27, 2020 Author Share Posted July 27, 2020 Doesn't seem to help. I'm really baffled. Installed a virtual windows server on my w10 and the script works on that, but not on the physical server. Link to comment Share on other sites More sharing options...
Danp2 Posted July 27, 2020 Share Posted July 27, 2020 Are you sure the script is actually executing? Maybe it's being "intercepted" by you AV software. Have you tried adding a MsgBox at the end that should always display to confirm that it actually ran? Blue0 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Blue0 Posted July 27, 2020 Author Share Posted July 27, 2020 Yup, pretty sure it's executing because the filewriteline does work. I can put a random msgbox message at the end to confirm it though. Link to comment Share on other sites More sharing options...
Blue0 Posted July 27, 2020 Author Share Posted July 27, 2020 (edited) Well.. There's no point in trying to solve this though I guess.. Like in the thread water linked. Using FileWriteToLine to erase a line is weird. ^^ Tested and the _FileDeleteLine, which BrewManNH posted, works on the server. Gonna use that one. Thank you everyone for the replies! Edited July 27, 2020 by Blue0 Link to comment Share on other sites More sharing options...
Nine Posted July 27, 2020 Share Posted July 27, 2020 Just curious, could you run this and tell me what happens : expandcollapse popup#include <Constants.au3> #include <Array.au3> $sFileName = "Test.txt" $hFile = FileOpen($sFileName, $FO_OVERWRITE) FileWriteLine($hFile, "test1") FileWriteLine($hFile, "test2") FileWriteLine($hFile, "test3") FileWriteLine($hFile, "test4") FileWriteLine($hFile, "test5") FileWriteLine($hFile, "test6") FileClose($hFile) _FileWriteToLineEX($sFileName, 3, "", True) If @error Then MsgBox ($MB_SYSTEMMODAL,"error", @error) MsgBox ($MB_SYSTEMMODAL,"","Ended") Func _FileWriteToLineEX($sFilePath, $iLine, $sText, $bOverWrite = False, $bFill = False) If $bOverWrite = Default Then $bOverWrite = False If $bFill = Default Then $bFill = False If Not FileExists($sFilePath) Then Return SetError(2, 0, 0) If $iLine <= 0 Then Return SetError(4, 0, 0) If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) If Not IsString($sText) Then $sText = String($sText) If $sText = "" Then Return SetError(6, 0, 0) EndIf If Not IsBool($bFill) Then Return SetError(7, 0, 0) ; Read current file into array Local $aArray = FileReadToArray($sFilePath) ; Create empty array if empty file If @error Then Local $aArray[0] _ArrayDisplay ($aArray, "Before mod") Local $iUBound = UBound($aArray) - 1 ; If Fill option set If $bFill Then ; If required resize array to allow line to be written If $iUBound < $iLine Then ReDim $aArray[$iLine] $iUBound = $iLine - 1 EndIf Else If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0) EndIf ; Write specific line - array is 0-based so reduce by 1 - and either replace or insert $aArray[$iLine - 1] = ($bOverWrite ? $sText : $sText & @CRLF & $aArray[$iLine - 1]) ; Concatenate array elements Local $sData = "" For $i = 0 To $iUBound $sData &= $aArray[$i] & @CRLF Next $sData = StringTrimRight($sData, StringLen(@CRLF)) ; Required to strip trailing EOL $aArray = StringSplit ($sData, @CRLF, $STR_ENTIRESPLIT+$STR_NOCOUNT) _ArrayDisplay ($aArray, "After mod") ; Write data to file Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE) If $hFileOpen = -1 Then Return SetError(3, 0, 0) FileWrite($hFileOpen, $sData) FileClose($hFileOpen) Return 1 EndFunc Blue0 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Blue0 Posted July 28, 2020 Author Share Posted July 28, 2020 (edited) @Nine Sorry for the late response. Row 2 was emptied. And there's no difference between the server, w10 or the fresh virtual server. Got the same result on all of them. Tried copying the _FileWriteToLine func from the File.au3 and using it. That works too.. Maybe there's a problem with my AutoIT install? I have no idea why the same .exe doesn't work in the server with File.au3 included while working in everywhere else I tried. expandcollapse popup#include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> $sFileName = "C:\Temp\test.txt" $hFile = FileOpen($sFileName, 1) FileWriteLine($hFile, "test1") FileWriteLine($hFile, "test2") FileWriteLine($hFile, "test3") FileWriteLine($hFile, "test4") FileWriteLine($hFile, "test5") FileWriteLine($hFile, "test6") FileClose($hFile) _FileWriteToLine($sFileName, 3, "", True) If @error Then MsgBox(16, "error", @error) Func _FileWriteToLine($sFilePath, $iLine, $sText, $bOverWrite = False, $bFill = False) If $bOverWrite = Default Then $bOverWrite = False If $bFill = Default Then $bFill = False If Not FileExists($sFilePath) Then Return SetError(2, 0, 0) If $iLine <= 0 Then Return SetError(4, 0, 0) If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) If Not IsString($sText) Then $sText = String($sText) If $sText = "" Then Return SetError(6, 0, 0) EndIf If Not IsBool($bFill) Then Return SetError(7, 0, 0) ; Read current file into array Local $aArray = FileReadToArray($sFilePath) ; Create empty array if empty file If @error Then Local $aArray[0] Local $iUBound = UBound($aArray) - 1 ; If Fill option set If $bFill Then ; If required resize array to allow line to be written If $iUBound < $iLine Then ReDim $aArray[$iLine] $iUBound = $iLine - 1 EndIf Else If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0) EndIf ; Write specific line - array is 0-based so reduce by 1 - and either replace or insert $aArray[$iLine - 1] = ($bOverWrite ? $sText : $sText & @CRLF & $aArray[$iLine - 1]) ; Concatenate array elements Local $sData = "" For $i = 0 To $iUBound $sData &= $aArray[$i] & @CRLF Next $sData = StringTrimRight($sData, StringLen(@CRLF)) ; Required to strip trailing EOL ; Write data to file Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) + $FO_OVERWRITE) If $hFileOpen = -1 Then Return SetError(3, 0, 0) FileWrite($hFileOpen, $sData) FileClose($hFileOpen) Return 1 EndFunc ;==>_FileWriteToLine Edited July 28, 2020 by Blue0 Link to comment Share on other sites More sharing options...
Nine Posted July 28, 2020 Share Posted July 28, 2020 (edited) Yes there is possibly a glitch somewhere in your installation. I would suggest you uninstall and clear the whole autoit folder. Then proceed with a fresh install along with the beta version and the full version of Scite. Edited July 28, 2020 by Nine Blue0 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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