Jump to content

_FileWriteToLine doesn't work in Windows Server 2012 R2?


Recommended Posts

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?

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

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 by Blue0
Link to comment
Share on other sites

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 by water
Added the link to the thread where the subject has been discussed.

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

In this case _FileWriteToLine should return an error (3 - Error when opening file).

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

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 by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

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 by Blue0
Link to comment
Share on other sites

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)
;------------------

 

Link to comment
Share on other sites

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 by water

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

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 by Blue0
Link to comment
Share on other sites

Just curious, could you run this and tell me what happens :

#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

 

Link to comment
Share on other sites

@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.

 

 

AutoIt3_x64_sZN3Y9rk8C.png

AutoIt3_x64_G92r6msTMi.png

SN5rwWNnqb.png

 

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. 

#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 by Blue0
Link to comment
Share on other sites

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 by Nine
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...