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

Re: vbscript using getfolder by Albert

Albert
Tue Mar 18 10:37:12 CDT 2008

Isn't that just because when created, Vista sets the windows folder owner to
be the system itself, and not the administrator ?

"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
>



Re: vbscript using getfolder by Pegasus

Pegasus
Tue Mar 18 10:42:42 CDT 2008


"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.



Re: vbscript using getfolder by Richard

Richard
Tue Mar 18 11:31:30 CDT 2008


"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
--



Re: vbscript using getfolder by rac8006

rac8006
Tue Mar 18 16:31:02 CDT 2008

Thanks. That is a typo in the post. In the program I have the correct
statement.

"Pegasus (MVP)" wrote:

>
> "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.
>
>
>

Re: vbscript using getfolder by Pegasus

Pegasus
Tue Mar 18 16:37:19 CDT 2008


"rac8006" <rac8006@discussions.microsoft.com> wrote in message
news:F1AABAAC-D59E-4C76-8E68-E29A11E6483F@microsoft.com...
> Thanks. That is a typo in the post. In the program I have the correct
> statement.
>

Retyping code when posting is a bad idea, for perfectly
obvious reasons. What's wrong with copy & paste?



Re: vbscript using getfolder by rac8006

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
> --
>
>
>

Re: vbscript using getfolder by mayayana

mayayana
Tue Mar 18 17:11:16 CDT 2008

> P.S. I don't understand why Vista has to set up things so that even the
> real administrator can't do
>

I haven't used Vista, but I'm curious about this for
future reference. When you say "real administrator"
you mean logging in after having run the command
to acyivate actual admin.?

net user administrator /active:yes

And even if you right-click and run as admin.? In
either case you can't actually control the system folder?



Re: vbscript using getfolder by rac8006

rac8006
Tue Mar 18 18:16:01 CDT 2008

My mistake. I tried to make the test program as simple as possible.

"Pegasus (MVP)" wrote:

>
> "rac8006" <rac8006@discussions.microsoft.com> wrote in message
> news:F1AABAAC-D59E-4C76-8E68-E29A11E6483F@microsoft.com...
> > Thanks. That is a typo in the post. In the program I have the correct
> > statement.
> >
>
> Retyping code when posting is a bad idea, for perfectly
> obvious reasons. What's wrong with copy & paste?
>
>
>

Re: vbscript using getfolder by rac8006

rac8006
Tue Mar 18 18:25:03 CDT 2008

Yes I enabled the real administrator. That is correct neither of these
options will allow the getfolder to function. Its very frustrating. Makes
one wonder what else I'm not allowed to do as administrator. I've come so
close to blowing away Vista and installing XP PRO. The laptop I just bought
came with Vista and no option to get XP.

"mayayana" wrote:

> > P.S. I don't understand why Vista has to set up things so that even the
> > real administrator can't do
> >
>
> I haven't used Vista, but I'm curious about this for
> future reference. When you say "real administrator"
> you mean logging in after having run the command
> to acyivate actual admin.?
>
> net user administrator /active:yes
>
> And even if you right-click and run as admin.? In
> either case you can't actually control the system folder?
>
>
>

Re: vbscript using getfolder by Richard

Richard
Tue Mar 18 19:42:18 CDT 2008


"mayayana" <mayaXXyana1a@mindXXspring.com> wrote in message
news:eM2%23CUUiIHA.944@TK2MSFTNGP05.phx.gbl...
>> P.S. I don't understand why Vista has to set up things so that even the
>> real administrator can't do
>>
>
> I haven't used Vista, but I'm curious about this for
> future reference. When you say "real administrator"
> you mean logging in after having run the command
> to acyivate actual admin.?
>
> net user administrator /active:yes
>
> And even if you right-click and run as admin.? In
> either case you can't actually control the system folder?
>

When I start a command prompt using "Run as administrator" the list of
folders I do not have permission to read is smaller, but still substantial.
There may be ways to overcome this, but I have not found them. I place all
of my files in my own folders to avoid any issues. Using "net user
administrator /active:yes" has the same affect. Among the many folders where
I lack permission on my Vista computer:

c:\ProgramData\Application Data
c:\ProgramData\Start Menu
c:\ProgramData\Desktop
c:\Documents and Settings
c:\System Volume Information
c:\Users\All Users\Application Data
c:\Users\All Users\Documents
c:\Users\Default\AppData\Local\Application Data
c:\Users\Default\Documents\My Music
c:\Users\Public\Documents\My Music
c:\Windows\System32\LogFiles\WMI\RtBackup

The last is the only folder I cannot read in the System32 folder. The only
other Windows folder I cannot read is "c:\Windows\CSC".

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: vbscript using getfolder by Paul

Paul
Wed Mar 19 13:02:18 CDT 2008

You might want to do a groups.google search of the
microsoft.public.windows.vista.* newsgroups for your problem. A great
deal of frustration has been vented there and occasionally you find
some nuggets of useful information.

For many new computers, the manufacturers have optimized the BIOS for
the OS they install on the computer. Sometimes the manufacturers post
all the drivers you need for earlier OSs, and sometimes they don't.
Sometimes you can make a list of all the hardware that Vista sees and
find suitable drivers for other OSs from sources other than your
manufacturer. If you decide to blow away Vista, I would recommend
that you first collect all the hardware drivers for XP and get a
separate hard drive on which to do the installation, just in case
things don't go well.

-Paul Randall

"rac8006" <rac8006@discussions.microsoft.com> wrote in message
news:A8E30D1B-A34D-49C7-85B3-C767C94CB012@microsoft.com...
> Yes I enabled the real administrator. That is correct neither of
> these
> options will allow the getfolder to function. Its very frustrating.
> Makes
> one wonder what else I'm not allowed to do as administrator. I've
> come so
> close to blowing away Vista and installing XP PRO. The laptop I
> just bought
> came with Vista and no option to get XP.
>
> "mayayana" wrote:
>
>> > P.S. I don't understand why Vista has to set up things so that
>> > even the
>> > real administrator can't do
>> >
>>
>> I haven't used Vista, but I'm curious about this for
>> future reference. When you say "real administrator"
>> you mean logging in after having run the command
>> to acyivate actual admin.?
>>
>> net user administrator /active:yes
>>
>> And even if you right-click and run as admin.? In
>> either case you can't actually control the system folder?
>>
>>
>>