Page 1 of 1

Windows 11 + CreateFile = $%é*+@

Posted: Thu Aug 22, 2024 12:03 pm
by SPH
I'm on W11
I removed Norton antivirus. I only have Windows security.
When I try this code, it doesn't work:

Code: Select all

If CreateFile(0, "Test.txt")    ; Ouvre un fichier existant ou en crée un nouveau s'il n'existait pas
  FileSeek(0, Lof(0))           ; Place le pointeur à la fin du fichier en utilisant le résultat de Lof() 
  WriteLong(0,123456789)
  WriteStringN(0, "... une autre ligne à la fin du fichier.")
  CloseFile(0)
Else
  MessageRequester("Information","Impossible de créer le fichier!")
EndIf
If ReadFile(0, "Test.txt")   ; Si le fichier peut être lu , on continue...
  While Eof(0) = 0           ; Boucle tant que la fin du fichier n'est pas atteinte. (Eof = 'End Of File') 
    Debug ReadLong(0)        ; Affiche ligne par ligne le contenu du fichier
  Wend
  CloseFile(0)               ; Ferme le fichier précédemment ouvert
Else
  MessageRequester("Information","Impossible d'ouvrir le fichier!")
EndIf
Why?
How do I tell Windows that it can create the file?

Re: Windows 11 + CreateFile = $%é*+@

Posted: Thu Aug 22, 2024 12:16 pm
by Kiffi
This happens due to missing access rights (also under Windows 10).

This one works, for example:

Code: Select all

If CreateFile(0, GetTemporaryDirectory() + "Test.txt")
...

Re: Windows 11 + CreateFile = $%é*+@

Posted: Thu Aug 22, 2024 12:16 pm
by RASHAD
Try to run the snippet as admin

Re: Windows 11 + CreateFile = $%é*+@

Posted: Thu Aug 22, 2024 12:53 pm
by mk-soft
Only use admin rights if absolutely necessary. For example, for system functions, setup, etc
Otherwise the programmes will not run on other users who do not have admin rights.

Always use a valid path ...

Code: Select all

Define UserPath.s = GetUserDirectory(#PB_Directory_Documents)
Define FileName.s = UserPath + "Text.txt"

Debug FileName

Re: Windows 11 + CreateFile = $%é*+@

Posted: Thu Aug 22, 2024 8:04 pm
by SPH
RASHAD wrote: Thu Aug 22, 2024 12:16 pm Try to run the snippet as admin
I am a newbie under Windows 11. I got my computer 2 months ago and coding under Windows 11 is a pain!!!
A question on my mind: how to code as an administrator??

As I am the only one and Windows 11 was already installed, it should be me who is the administrator... :shock:

Thanks for your help! :idea: