![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. > generates the error. |
My System Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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. 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 > 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 Specs![]() |
| | #7 (permalink) |
| | 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. 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 Specs![]() |
| | #8 (permalink) |
| | 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. 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 Specs![]() |
![]() |
| 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 | |||