permissions denied error with CreateTextFile()

vba_php

Forum Troll
Local time
Today, 12:02
Joined
Oct 6, 2019
Messages
2,880
I have searched high and low as to what could be causing this but i can't seem to fix the stupid thing. here's the simple code:
Code:
    Dim fso As Scripting.FileSystemObject
    Dim tsTxtFile As Scripting.TextStream
    
    ' (1) Open an instance of the FileSystemObject.
    Set fso = New Scripting.FileSystemObject
    
    ' (2) Open an instance of the FileSystemObject TextStream class.
    Set tsTxtFile = fso.CreateTextFile("C:\test.txt", True)

tsTxtFile.Close
I have even tried running it the normal way:
Code:
'    Dim obj_fso As Object
    Dim oFile As Object
    Set obj_fso = CreateObject("Scripting.FileSystemObject")

    If obj_fso.FileExists("c:\test.txt") Then
        Kill "c:\test.txt"
    End If

        Set oFile = obj_fso.CreateTextFile("c:\test.txt", True)
        oFile.Close
with no luck. Could it be happening because I'm running a trial version of access as a part of a trial version of office 365?
 
Try creating the text file in another directory. I.e. desktop . Sometimes I have trouble creating files in the root “c:\” on some computers due to weird permissions settings.


Sent from my iPhone using Tapatalk
 
that worked fine horton. what's the problem with the c: drive anyway?
 
that worked fine horton. what's the problem with the c: drive anyway?
No problem. - It's just not a location where random users and applications should dump their garbage to.
 
Probably something to do with permissions. I’m an Administrator on my computer and yet it still won’t let me. I imagine it’s something to do with the actual request coming from Access.


Sent from my iPhone using Tapatalk
 
In my experience it started with Win 10, but we skipped 8. I don't think you can manually save a file there either, at least not without jumping through hoops.
 
Saving to the root c:\ drive is restricted by default (and has been for about 10 years)

Here's an example of the message you get when trying to save to the root drive c:\

attachment.php


To overcome this restriction, you need to run the program (in this case Notepad) as an administrator.
You will then be able to save to the root c:\ drive if you really must do so
 

Attachments

  • Capture.PNG
    Capture.PNG
    4.9 KB · Views: 2,441
Kind of makes sense rally. Like sonic8 said, you don’t want to use c:\ as a dumping ground.


Sent from my iPhone using Tapatalk
 
for my purposes you guys, it doesn't matter where the files are stored. I only spec'd the c:\ drive to my users because every windows computer has one. That way no one can possibly get confused. But I'll change it accordingly. thanks.
 
Adam, I think it is a holdover from the (hold on to your hat) MS-DOS days when the FAT16 file system had a numeric limit on the number files that could be in the root folder of a drive. Unlike FAT32 and NTFS, the FAT16 root directory had a fixed location and a fixed set of file pointers. It was pre-allocated when you init'ed the disk. Therefore, to prevent locking up a system due to a full root folder on the system disk, they put permissions on it for "READ-ONLY" for most users.
 
in later versions of windows you can't ordinarily write directly to the C:\ folder.
That's what's happening, I think.

(colin/isladogs has already noted this)
 
Dave, I agree. I was giving a historical perspective.

We should ALSO note that Windows has undergone a massive series of changes in the way it handled multiple users sharing the same machine. It USED to be that you didn't have a Users folder. You put each user on the system as C:\Username - which would lead to the issue that if anyone could do that, user files would be instantly compromised. Which meant that for the versions of Windows (before NT) that did user management that way, you had to restrict how you created user home folders. Now, the \Users\username folder handles that. But still, restrictions on the C:\ folder (root folder) were restricted a long time ago.
 

Users who are viewing this thread

Back
Top Bottom