Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

objFSO.CreateTextFile Permission denied

Status
Not open for further replies.

stev379

Technical User
Jan 2, 2005
19
US
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?
This runs as a logon script.

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!
 
if the user does not have permissions to create a file in the root then youare stuffed try

WshShell.ExpandEnvironmentStrings("%userprofile%")

...or some other environment string, there are other ways of getting environment strings but i am lazy and use this method and get my arsed flamed for it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top