Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Microsoft VBScript runtime error Code 800A0046 line 49 , Char 1 "Permission denied"

78 views
Skip to first unread message

Jeffrey Smith

unread,
Jun 4, 2015, 12:00:21 PM6/4/15
to

I'm using a script to clear Temp files and folders developed by Michael Harris and posted at:

https://groups.google.com/forum/#!topic/microsoft.public.scripting.wsh/j7e2oL0F0pY

It has worked for me since I re-installed Windows 7 a couple of weeks ago but has suddenly started giving me this error:

Microsoft VBScript runtime error Code 800A0046 line 49 , Char 1 "Permission denied"

(Note: I had actually had this happen to me a few years back, so I don't know if this is an intermittent problem or what conditions make it happen)

This is the code (Note, too that I get the same error when I try to open Microsoft Windows Based Script Host, so this was opened with Notepad):

'===DeleteTempFiles.vbs===
' Source: http://groups.google.com/group/microsoft.public.scripting.wsh/browse_frm/thread/8fb7b6a0bd05d296/eb34633c642bcdb7#eb34633c642bcdb7
'Michael Harris
'Microsoft.MVP.Scripting

Const TemporaryFolder = 2 'for GetSpecialFolder
set fso = createobject("scripting.filesystemobject")
'init an empty array (ubound will be -1)...
'
'we use an array and store the file objects.
'this avoids any problems with altering the
'contents of the Files collections while they
'are being iterated.
'
arFiles = array()
count = -1
'get the path to the temp folder
'
tempdir = fso.GetSpecialFolder(TemporaryFolder)
'load the (global scope) arFiles
'SelectFiles calls itself recursively
'for SubFolders
'
SelectFiles tempdir
msgbox count+1 & " files found"
'now do the actual deletes. the error trap
'is in case any are in-use...
'
dcount = 0
for each file in arFiles
on error resume next
file.delete true
if err.number = 0 then dcount = dcount + 1
err.clear
on error goto 0
next
'now go back and delete empty folders
'below the temp folder
DeleteEmptyFolders tempdir,false
'comment out for "silent" operation,
'or add support for a "/s" command-line switch.
'
msgbox count+1 & " files found, " & dcount & " deleted."
sub SelectFiles(sPath)
'select files to delete and add to array...
'
set folder = fso.getfolder(sPath)
set files = folder.files
for each file in files
count = count + 1
redim preserve arFiles(count)
set arFiles(count) = file
next
for each fldr in folder.subfolders
SelectFiles fldr.path
next
end sub
sub DeleteEmptyFolders(sPath,bDeleteThisFolder)
set folder = fso.getfolder(sPath)
'recurse first...
'
for each fldr in folder.subfolders
DeleteEmptyFolders fldr.path,true
next
'if no files or folders then delete...
'
'bDeleteThisFolder is false for
'the root of the subtree, and true for
'sub-folders (unless you want to delete
'the entire subtree if it is empty).
'
if (folder.files.count = 0) and _
(folder.subfolders.count) = 0 and _
bDeleteThisFolder then
folder.delete
exit sub
end if
end sub
'
'===end-script===

I'd appreciate any insights.

Jeff
0 new messages