Windows 11 + CreateFile = $%é*+@

Windows specific forum
User avatar
SPH
Enthusiast
Enthusiast
Posts: 566
Joined: Tue Jan 04, 2011 6:21 pm

Windows 11 + CreateFile = $%é*+@

Post 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?

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
Kiffi
Addict
Addict
Posts: 1497
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

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

Post 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")
...
Hygge
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

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

Post by RASHAD »

Try to run the snippet as admin
Egypt my love
User avatar
mk-soft
Always Here
Always Here
Posts: 6242
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

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

Post 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
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
SPH
Enthusiast
Enthusiast
Posts: 566
Joined: Tue Jan 04, 2011 6:21 pm

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

Post 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:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
Post Reply