Jump to content

Autoit wont (sometimes) create file O_o


Recommended Posts

Hello everyone,

I'd like my autoit program to create a new text file, and write things in it. As soon as I compile it, it works with no error, if I launch it in the build folder, the text file is created. However, if I move it elsewhere, it just wont create it, AND claim the file already exists ?!

I do not thing it has anything to do with admin rights, as long as I tried it in many "common places", or ran it in admin mode, with the same results :/

Here is a snip:

Dim $path
$path = @ScriptDir & "\LOG.DAT"
;Dim $VarTmp
;$VarTmp = ""
Dim $dll
$dll = DllOpen("user32.dll")

Dim $file
$file = FileOpen($path, 1) ; 1-> write mode (append)
; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

I never got the error message, even though the file (LOG.DAT) is not created :/

What canI have done wrong?

Thanks :)

Link to post
Share on other sites

Welcome to the AutoIt forum! :D

First off, when you moved it, did you check that directory for the created file? As @ScriptDir will change to the directory it was moved to.

you can always check if you created the file successfully with a check with FileRead:

$file = FileOpen($path, 1)
Local $fRead = FileRead($file)
If @error Then
    MsgBox(0, "", "Did not work")
EndIf

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to post
Share on other sites

Well, first Mikahs, I double checked by running a copy of the executable in another location and checking the text file of the first location, but still, nothing had changed :/ I've done a lot of tests before posting this, and I had the same issue with some other programs, therefore I gave up developing them, but now I'd really like to know whats wrong with that.

To make sure the path is right, I implemented two additional lines:

MsgBox(0,"debug", "Log: " & $path)
Exit

And, the path is correct for the two different locations, but only works for 1 :/

Then,Jfish, I'm trying to make a keyboard heatmap for statistics when playing tf2, to be precise :)

here is moar code:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=heat2.exe
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Misc.au3>

Dim $Fichier
$Fichier = @ScriptDir & "\LOG.DAT"
;Dim $VarTmp
;$VarTmp = ""
Dim $dll
$dll = DllOpen("user32.dll")

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

While 1
;Sleep ( 50 )
;Kpres("01", "Left mouse button")
;Kpres("02", "Right mouse button")
;Kpres("04", "Middle mouse button")
;Kpres("05", "Windows 2000/XP: X1 mouse button")
;Kpres("06", "Windows 2000/XP: X2 mouse button")
Kpres("08", "|BACKSPACE|")
While _IsPressed("08") = 1
WEnd
Kpres("09", "|TAB|")
; A lotta loops
; later on...

WEnd
DllClose($dll)


func Kpres($num,$res)
If _IsPressed($num, $dll) Then
FileWrite($file, $res)

Endif

EndFunc

FileClose($file)

Do you need compiler options or something?

Thanks for the support :)

EDIT: more coherence with latly posted code

Edited by yhu420
Link to post
Share on other sites

Just an FYI @ScriptDir is the directory the script is in, so if you move it, it changes.

But, I'm not sure if this is considered gaming and is against the rules. :(

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to post
Share on other sites
  • Moderators

yhu420,

 

I'm trying to make a keyboard heatmap for statistics when playing tf2

That sounds to me as if it breaks both the "game" and "keylogger" rules - thread locked. :naughty:

Plase read the Forum rules (there is also a link at bottom right of each page) befor eposting again. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to post
Share on other sites
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...