Discussion:
objFSO.CreateTextFile permission denied
(too old to reply)
stev379
2006-03-01 14:54:40 UTC
Permalink
The snippet below checks for a flag file, and works fine when I'm logged in
as an admin on XP, but errors on the Set objFile =
objFSO.CreateTextFile("C:\PTRMIG_FLG_.txt") line when logged in as a Power
User or less. It returns a Permission Denied error. How can I create a file
on the root of a machines C: drive or the root of the currently logged on
users profile?


Set objFSO = CreateObject("Scripting.FileSystemObject")
'Check for flag file and stop script if it exists

If objFSO.FileExists("C:\PTRMIG_FLG_.txt") Then

WScript.Quit
Else

Set objFile = objFSO.CreateTextFile("C:\PTRMIG_FLG_.txt")
End If



Thanks for any help or suggestions!
Michael Harris (MVP)
2006-03-02 02:26:35 UTC
Permalink
Post by stev379
The snippet below checks for a flag file, and works fine when I'm
logged in as an admin on XP, but errors on the Set objFile =
objFSO.CreateTextFile("C:\PTRMIG_FLG_.txt") line when logged in as
a Power User or less. It returns a Permission Denied error. How can
I create a file on the root of a machines C: drive or the root of the
currently logged on users profile?
You can't unless some admin changes the permissions on the root of the drive
to allow it. No file write access into the root of the C drive for
non-admins is the default on a Windows system (ever since NT as far as I
know).

However, even ordinary users can create folders off the root and write
freely to those. I suggest you stay out of writing files to the root and
adapt to the default existing security.
Post by stev379
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Check for flag file and stop script if it exists
If objFSO.FileExists("C:\PTRMIG_FLG_.txt") Then
WScript.Quit
Else
Set objFile = objFSO.CreateTextFile("C:\PTRMIG_FLG_.txt")
End If
Thanks for any help or suggestions!
--
Michael Harris
Microsoft MVP Scripting

Scripting: Your First Steps
http://www.microsoft.com/technet/scriptcenter/topics/beginner/firststeps.mspx
Continue reading on narkive:
Search results for 'objFSO.CreateTextFile permission denied' (Questions and Answers)
4
replies
VBScript opentextfile "permission denied"?
started 2011-04-26 12:20:55 UTC
programming & design
Loading...