Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - access denied on scrip

Reply
 
Old 04-14-2009   #1 (permalink)
Elbryyan


 
 

access denied on scrip

I have a script that I copied to give me a report on the amount of free disk
space on a list of servers from a text file. This script has been working
fine for a few months but now I am getting an access denied message on this
line I belive..

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

The error is
Permission denied: 'GetObject'
Code: 800A0046
Source: Microsoft VBScript runtime error

Here is the full script...

on error resume next
Const ForReading = 1
Const Conversion_factor = 1048576
Const HARD_DISK = 3

dt = Replace(Date,"/","-")
strFileName = dt & "-FreeSpace.txt"

Set objExplorer = CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 200
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1

Do While (objExplorer.Busy)
Loop

Set objDocument = objExplorer.Document
objDocument.Open
objDocument.Writeln "<html><head><title>Service Status</title></head>"
objDocument.Writeln "<body bgcolor='white'>"
objDocument.Writeln "Retrieving service information. Please wait. <p>"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(strFileName)

Set objFile2 = objFSO.OpenTextFile("Servers.txt", ForReading)

Do Until objFile2.AtEndOfStream
strComputer = objFile2.ReadLine
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk
WHERE DriveType = " & HARD_DISK & "")
strEmailBody = ("Computer: " & strComputer)& vbCrLf
objFile.WriteLine ("Computer: " & strComputer)
For Each objDisk in colDisks
objDocument.Writeln "*"
strFreeSpace = Int(objDisk.FreeSpace / Conversion_factor)
strTotalSPace = Int(objDisk.Size / Conversion_factor)
strEmailBody = strEmailBody & ("Free space (MB) on " & objDisk.DeviceID &
" " & strFreeSpace & " (" & Int((strFreeSpace/strTotalSpace)*100) & "%)") &
vbCrLf
objFile.WriteLine ("Free space (MB) on " & objDisk.DeviceID & " " &
strFreeSpace & " (" & Int((strFreeSpace/strTotalSpace)*100) & "%)")
Next
strCompleteEmailBody = strCompleteEmailBody & vbCrLF & strEmailBody
Loop

objDocument.Writeln "<br>Service Information Retrieved."
objDocument.Writeln "</body></html>"

objFile.Close
objFile2.Close

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "*******"
objEmail.To = "********"
objEmail.Subject = "Server Free Disk Space Report"
objEmail.Textbody = strCompleteEmailBody
'objEmail.AddAttachment = "strFilename"
objEmail.Send

wscript.sleep 4000
objdocument.close
objExplorer.quit

As far as I know nothing has changed, the script runs from a remote windows
XP computer with domain admin rights. If I run the script locally then I do
not have a problem. I'm really a scripting novice so any help is appreciated.


My System SpecsSystem Spec
Old 04-14-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: access denied on scrip


"Elbryyan" <Elbryyan@xxxxxx> wrote in message
news:35875879-3F0C-4FE0-9630-6AEFC86D1E87@xxxxxx
Quote:

>I have a script that I copied to give me a report on the amount of free
>disk
> space on a list of servers from a text file. This script has been working
> fine for a few months but now I am getting an access denied message on
> this
> line I belive..
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
>
> The error is
> Permission denied: 'GetObject'
> Code: 800A0046
> Source: Microsoft VBScript runtime error
>
> Here is the full script...
>
> on error resume next
> Const ForReading = 1
> Const Conversion_factor = 1048576
> Const HARD_DISK = 3
>
> dt = Replace(Date,"/","-")
> strFileName = dt & "-FreeSpace.txt"
>
> Set objExplorer = CreateObject("InternetExplorer.Application")
> objExplorer.Navigate "about:blank"
> objExplorer.ToolBar = 0
> objExplorer.StatusBar = 0
> objExplorer.Width = 400
> objExplorer.Height = 200
> objExplorer.Left = 0
> objExplorer.Top = 0
> objExplorer.Visible = 1
>
> Do While (objExplorer.Busy)
> Loop
>
> Set objDocument = objExplorer.Document
> objDocument.Open
> objDocument.Writeln "<html><head><title>Service Status</title></head>"
> objDocument.Writeln "<body bgcolor='white'>"
> objDocument.Writeln "Retrieving service information. Please wait. <p>"
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objFile = objFSO.CreateTextFile(strFileName)
>
> Set objFile2 = objFSO.OpenTextFile("Servers.txt", ForReading)
>
> Do Until objFile2.AtEndOfStream
> strComputer = objFile2.ReadLine
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer &
> "\root\cimv2")
> Set colDisks = objWMIService.ExecQuery ("SELECT * FROM Win32_LogicalDisk
> WHERE DriveType = " & HARD_DISK & "")
> strEmailBody = ("Computer: " & strComputer)& vbCrLf
> objFile.WriteLine ("Computer: " & strComputer)
> For Each objDisk in colDisks
> objDocument.Writeln "*"
> strFreeSpace = Int(objDisk.FreeSpace / Conversion_factor)
> strTotalSPace = Int(objDisk.Size / Conversion_factor)
> strEmailBody = strEmailBody & ("Free space (MB) on " & objDisk.DeviceID &
> " " & strFreeSpace & " (" & Int((strFreeSpace/strTotalSpace)*100) & "%)")
> &
> vbCrLf
> objFile.WriteLine ("Free space (MB) on " & objDisk.DeviceID & " " &
> strFreeSpace & " (" & Int((strFreeSpace/strTotalSpace)*100) & "%)")
> Next
> strCompleteEmailBody = strCompleteEmailBody & vbCrLF & strEmailBody
> Loop
>
> objDocument.Writeln "<br>Service Information Retrieved."
> objDocument.Writeln "</body></html>"
>
> objFile.Close
> objFile2.Close
>
> Set objEmail = CreateObject("CDO.Message")
> objEmail.From = "*******"
> objEmail.To = "********"
> objEmail.Subject = "Server Free Disk Space Report"
> objEmail.Textbody = strCompleteEmailBody
> 'objEmail.AddAttachment = "strFilename"
> objEmail.Send
>
> wscript.sleep 4000
> objdocument.close
> objExplorer.quit
>
> As far as I know nothing has changed, the script runs from a remote
> windows
> XP computer with domain admin rights. If I run the script locally then I
> do
> not have a problem. I'm really a scripting novice so any help is
> appreciated.
>
Get rid of the "on error resume next" so that you can see which line
generates the error.


My System SpecsSystem Spec
Old 04-14-2009   #3 (permalink)
Elbryyan


 
 

Re: access denied on scrip

>
Quote:

> "Elbryyan" <Elbryyan@xxxxxx> wrote in message
Quote:

> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strComputer &
> > "\root\cimv2")
> >

I know which line it was, the one posted above.
My System SpecsSystem Spec
Old 04-14-2009   #4 (permalink)
Pegasus [MVP]


 
 

Re: access denied on scrip


"Elbryyan" <Elbryyan@xxxxxx> wrote in message
news:19F43C41-1F64-48D8-934C-688EB02D5884@xxxxxx
Quote:
Quote:

>>
>> "Elbryyan" <Elbryyan@xxxxxx> wrote in message
Quote:

>> > Set objWMIService = GetObject("winmgmts:" _
>> > & "{impersonationLevel=impersonate}!\\" & strComputer &
>> > "\root\cimv2")
>> >
>
>
> I know which line it was, the one posted above.
You wrote "on this line, I believe", which expresses a degree of
uncertainty. Furthermore you could have an error earlier in the code that is
getting suppressed by the "on error" statement. When debugging code you
*must* remove the "on error" statement.


My System SpecsSystem Spec
Old 04-14-2009   #5 (permalink)
Elbryyan


 
 

Re: access denied on scrip

I removed the 'on error' line and that is the message that I get.

Permission denied: 'GetObject'
Code: 800A0046
Source: Microsoft VBScript runtime error


"Pegasus [MVP]" wrote:
Quote:

>
> "Elbryyan" <Elbryyan@xxxxxx> wrote in message
> news:19F43C41-1F64-48D8-934C-688EB02D5884@xxxxxx
Quote:
Quote:

> >>
> >> "Elbryyan" <Elbryyan@xxxxxx> wrote in message
> >> > Set objWMIService = GetObject("winmgmts:" _
> >> > & "{impersonationLevel=impersonate}!\\" & strComputer &
> >> > "\root\cimv2")
> >> >
> >
> >
> > I know which line it was, the one posted above.
>
> You wrote "on this line, I believe", which expresses a degree of
> uncertainty. Furthermore you could have an error earlier in the code that is
> getting suppressed by the "on error" statement. When debugging code you
> *must* remove the "on error" statement.
>
>
>
My System SpecsSystem Spec
Old 04-14-2009   #6 (permalink)
Pegasus [MVP]


 
 

Re: access denied on scrip


"Elbryyan" <Elbryyan@xxxxxx> wrote in message
news:E84D95BA-3856-4EB4-9E49-7015BB60BEAF@xxxxxx
Quote:

> I removed the 'on error' line and that is the message that I get.
>
> Permission denied: 'GetObject'
> Code: 800A0046
> Source: Microsoft VBScript runtime error
>
I did a bit of googling for
8800A0046 "Permission denied"
and tripped over this link:
http://forum.parallels.com/showthread.php?t=81016. You may have to
re-register some libraries. By the way, you could (and probably should) make
your code more robust by fully qualifying the names assigned to strFilename
and "servers.txt". Having relative instead of absolute references will
sooner or later cause a problem.


My System SpecsSystem Spec
Old 04-14-2009   #7 (permalink)
T Lavedas


 
 

Re: access denied on scrip

On Apr 14, 3:48*pm, Elbryyan <Elbry...@xxxxxx>
wrote:
Quote:

> * I removed the 'on error' line and that is the message that I get.
>
> Permission denied: 'GetObject'
> Code: 800A0046
> Source: Microsoft VBScript runtime error
>
> "Pegasus [MVP]" wrote:
>
Quote:

> > "Elbryyan" <Elbry...@xxxxxx> wrote in message
> >news:19F43C41-1F64-48D8-934C-688EB02D5884@xxxxxx
>
Quote:
Quote:

> > >> "Elbryyan" <Elbry...@xxxxxx> wrote in message
> > >> > Set objWMIService = GetObject("winmgmts:" _
> > >> > * * *& "{impersonationLevel=impersonate}!\\" & strComputer&
> > >> > "\root\cimv2")
>
Quote:
Quote:

> > > I know which line it was, the one posted above.
>
Quote:

> > You wrote "on this line, I believe", which expresses a degree of
> > uncertainty. Furthermore you could have an error earlier in the code that is
> > getting suppressed by the "on error" statement. When debugging code you
> > *must* remove the "on error" statement.
Which computer is giving the problem? The very first one? Are you
even sure the text file is giving you the right computer names? It
may be that someone did something as simple as added a blank line to
the end of the file "Servers.txt", which would cause the script to
bomb. (It really needs some serious error handling efforts, which is
outside the scope of this thread.)

To check this, try adding a line after the file read ...

objDocument.Writeln "Servicing computer: [" & strComputer & "]<br>"

and then run the script to get an idea if this is the problem. If
there is an empty set of brackets before the error, then that's the
problem. Otherwise, it should identify which server's set up has
changed to cause the problem.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
My System SpecsSystem Spec
Old 04-15-2009   #8 (permalink)
Richard Mueller [MVP]


 
 

Re: access denied on scrip


"T Lavedas" <tglbatch@xxxxxx> wrote in message
news:e64feccf-e9c1-47a7-a66a-575f3c749a6b@xxxxxx
On Apr 14, 3:48 pm, Elbryyan <Elbry...@xxxxxx>
wrote:
Quote:

> I removed the 'on error' line and that is the message that I get.
>
> Permission denied: 'GetObject'
> Code: 800A0046
> Source: Microsoft VBScript runtime error
>
> "Pegasus [MVP]" wrote:
>
Quote:

> > "Elbryyan" <Elbry...@xxxxxx> wrote in message
> >news:19F43C41-1F64-48D8-934C-688EB02D5884@xxxxxx
>
Quote:
Quote:

> > >> "Elbryyan" <Elbry...@xxxxxx> wrote in message
> > >> > Set objWMIService = GetObject("winmgmts:" _
> > >> > & "{impersonationLevel=impersonate}!\\" & strComputer &
> > >> > "\root\cimv2")
>
Quote:
Quote:

> > > I know which line it was, the one posted above.
>
Quote:

> > You wrote "on this line, I believe", which expresses a degree of
> > uncertainty. Furthermore you could have an error earlier in the code
> > that is
> > getting suppressed by the "on error" statement. When debugging code you
> > *must* remove the "on error" statement.
Which computer is giving the problem? The very first one? Are you
even sure the text file is giving you the right computer names? It
may be that someone did something as simple as added a blank line to
the end of the file "Servers.txt", which would cause the script to
bomb. (It really needs some serious error handling efforts, which is
outside the scope of this thread.)

To check this, try adding a line after the file read ...

objDocument.Writeln "Servicing computer: [" & strComputer & "]<br>"

and then run the script to get an idea if this is the problem. If
there is an empty set of brackets before the error, then that's the
problem. Otherwise, it should identify which server's set up has
changed to cause the problem.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/

--------------
My guess is either one of the computers in the list cannot be reached, or
there is a blank line in the file (very common). Tom's suggestion should
determine which.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
No Network access - Access Denied Network & Sharing
can't open access control editor. Access is denied General Discussion
Access Denied, Access Denied- like a broken record! Vista General
When standard users access Vista registry remotely, Access Denied Vista account administration
Access is denied message when trying to access a remote printer Vista print fax & scan


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46