permissions denied error with CreateTextFile() (1 Viewer)

vba_php

Forum Troll
Local time
Today, 08:37
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?
 

nhorton79

Registered User.
Local time
Tomorrow, 01:37
Joined
Aug 17, 2015
Messages
147
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
 

vba_php

Forum Troll
Local time
Today, 08:37
Joined
Oct 6, 2019
Messages
2,880
that worked fine horton. what's the problem with the c: drive anyway?
 

sonic8

AWF VIP
Local time
Today, 15:37
Joined
Oct 27, 2015
Messages
998
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.
 

nhorton79

Registered User.
Local time
Tomorrow, 01:37
Joined
Aug 17, 2015
Messages
147
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
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 06:37
Joined
Aug 30, 2003
Messages
36,124
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.
 

isladogs

MVP / VIP
Local time
Today, 14:37
Joined
Jan 14, 2017
Messages
18,209
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:\



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: 1,770

nhorton79

Registered User.
Local time
Tomorrow, 01:37
Joined
Aug 17, 2015
Messages
147
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
 

vba_php

Forum Troll
Local time
Today, 08:37
Joined
Oct 6, 2019
Messages
2,880
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.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:37
Joined
Feb 28, 2001
Messages
27,142
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.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 14:37
Joined
Sep 12, 2006
Messages
15,638
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)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:37
Joined
Feb 28, 2001
Messages
27,142
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

Top Bottom