rac8006
Tue Mar 18 16:56:00 CDT 2008
I also found that the problem was the f.Size which really caused the
permission denied. I also found that when you do the getfolder function on
the windows directory that the system walks thru the windows directory trying
to add up all of the file sizes. When it gets to the system32 directory it
gets the error.
If you change the system32 to windows you will get the same error. It would
appear that you would have to walk thru every single folder and add the sizes
up yourself. Ignoring any errors during the search.
I've noticed that a program called opus9 which is a replacement for windows
explorer does not give an exact size for the windows folder. Opus has an
option to display the folder size for each folder. If you run opus with this
option the directories ProgramData, Users and Windows display a size with a ~
symbol in front of the size. Now I'm beginning to beleive that this is
bacause of these folders that can't be opened.
I guess I'm going to have to modify the program to do each file myself.
I will checkout your code to see if it can be modified to do what I want.
Thanks for your help.
P.S. I don't understand why Vista has to set up things so that even the
real administrator can't do
"Richard Mueller [MVP]" wrote:
>
> "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
> news:emU%2326QiIHA.4320@TK2MSFTNGP06.phx.gbl...
> >
> > "rac8006" <rac8006@discussions.microsoft.com> wrote in message
> > news:C41F9004-7E44-4FB4-AA01-9D38444A3CA6@microsoft.com...
> >> I've posted this question in so many forum's with no answer. Why does
> >> the
> >> following script get a permission denied error on vista even when run as
> >> administrator or run while logged in as the builtin administrator?
> >>
> >> Int n
> >> On Error Resume Next
> >> Dim fs, f
> >> Set objShell = CreateObject("Shell.Application")
> >> Set fs = CreateObject("Scripting.FileSystemObject")
> >> Set f = fs.GetFolder("c:\windows\system32)
> >> n = f.Size
> >> If Err.Number <> 0 Then
> >> MsgBox Err.Number & ": " & Err.Description & " folder: " & f.name
> >> Err.Clear
> >> End If
> >> str = UCase(f.Name) & " uses " & n & " bytes."
> >> wscript.Echo str
> >>
> >
> > Probably because you wrote
> >
> > Set f = fs.GetFolder("c:\windows\system32) instead of
> > Set f = fs.GetFolder("c:\windows\system32")
> >
> > It is better not to have "On Error Resume Next" statements
> > while debugging - they often mask trivial errors.
> >
>
> You have to be very careful about using "On Error Resume Next". It can mask
> all kinds of problems. I recommend only using it when necessary, when you
> expect possible errors. Then you should handle the errors and restore normal
> error handling as soon as practical.
>
> In this case, the Vista operating system has new permissions that prevent
> even Administrators from reading certain folders. I found that programs that
> read folders had to be modified to handle the permission errors by skipping
> the folders that cannot be read. For example, I have a VBScript program that
> searches for files that contain a specified string linked here:
>
>
http://www.rlmueller.net/FindFiles.htm
>
> This program uses "On Error Resume Next" to trap the permission errors, but
> then restores normal error handling. In your case, I would recommend
> something similar to:
> ===============
> Option Explicit
> Dim fs, f, n, str
>
> Set fs = CreateObject("Scripting.FileSystemObject")
> Set f = fs.GetFolder("c:\windows\system32")
>
> On Error Resume Next
> n = FormatNumber(f.Size, 0)
> If Err.Number <> 0 Then
> Wscript.Echo Err.Number & ": " & Err.Description & " folder: " & f.name
> On Error GoTo 0
> Else
> On Error GoTo 0
> Wscript.Echo UCase(f.Name) & " uses " & CStr(n) & " bytes."
> End If
> ==========
> By trial and error I found that the permission error is raised when you
> attempt to retrieve the Size property. The statement "On Error GoTo 0"
> restores normal error handling, and also clears any error condition. That's
> why I output the error number before restoring normal error handling.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -
http://www.rlmueller.net
> --
>
>
>