Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permission denied

Status
Not open for further replies.

ixoni

MIS
May 12, 2003
9
IE
In the followong script I check disk space for all the servers in the Array. When I have 6 servers in the array, 3 of them error with "Permission Denied." However, if I place one at a time in the array, they all work. For example, if I only put the server "psiacct" in the array, it works fine. If I put 5 more servers in the array, then psiacct errors out "Permission denied." I am running the script from my workstation with full admin rights.
Any ideas? I only put the first part of the script in relavent to the problem.

'FreeSpace.vbs Barry Hohstadt 12/15/03
'Determines if free space on server disks falls below 400MB and write results to log.

On Error Resume Next
Const CONVERSION_FACTOR = 1048576 'converts to MB
Const WARNING_THRESHHOLD = 400 'in MB

'Modify array to add or remove servers.
Computers = Array("psipro", "psiacct", "psiterm", "psisql", "psiweb")

For Each Computer In Computers
Set objWMIService = GetObject ("winmgmts://" & computer)
If Err.Number <> 0 Then
Wscript.Echo Computer & &quot; &quot; & Err.Description
Err.Clear
Else
set colLogicalDisk = objWMIService.InstancesOf (&quot;win32_LogicalDisk&quot;)
For Each objLogicalDisk In colLogicalDisk
 
Hello ixoni,

Try connect to the proper namespace see if it corrects the behavior?
Code:
Set objWMIService = GetObject (&quot;winmgmts://&quot; & computer & &quot;/root/cimv2&quot;)
regards - tsuji
 
Thanks tsuji, that is proper scripting, but unfortunately it did not help. I discoverd that if I put 6 servers in array, 3 error out, 4 servers, 2 error out, 2 servers, 1 errors out. Must be something wrong in the logic. Here is the whole script as it may help with the problem:

'FreeSpace.vbs Barry Hohstadt 12/15/03
'Determines if free space on server disks falls below 400MB and write results to log.

On Error Resume Next
Const CONVERSION_FACTOR = 1048576 'converts to MB
Const WARNING_THRESHHOLD = 400 'in MB

'Modify array to add or remove servers.
Computers = Array(&quot;psipro&quot;,&quot;cssis2&quot;,&quot;psiacct&quot;,&quot;psiterm&quot;)

For Each Computer In Computers
Set objWMIService = GetObject (&quot;winmgmts://&quot; & computer & &quot;/root/cimv2&quot;)
If Err.Number <> 0 Then
Wscript.Echo Computer & &quot; &quot; & Err.Description
Err.Clear
Else
set colLogicalDisk = objWMIService.InstancesOf (&quot;win32_LogicalDisk&quot;)
For Each objLogicalDisk In colLogicalDisk
FreeMegabytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR
If FreeMegabytes < WARNING_THRESHHOLD Then
WriteLog
objFile.WriteLine (Computer & vbTab & objLogicalDisk.DeviceID & _
&quot; is low on disk space.&quot;)
Else
WriteLog
objFile.WriteLine (Computer & vbTab & objLogicalDisk.DeviceID & _
&quot; is OK.&quot;)
End If
Next
End If
Next



' Sub Routines
Sub WriteLog
Const ForWriting = 2
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFile = objFSO.CreateTextFile (&quot;FreeSpaceLog.txt&quot;)
End Sub
 
Try to call the WriteLog sub only once (before the For Each Computer loop) as you raise an error trying to create an existing file without the overwrite option.

Hope This Help
PH.
 
PH, I think you are on to the problem, but not exactly. When I moved the sub I then got &quot;object required&quot; errors instead of &quot;permission denied.&quot; I recall that this script worked OK when I was using wscript.echo instead trying to write to a file. Perhaps I am going about this the wrong way, and need to rethink the design.

Thanks!
 
Try to amend your script like this:
Code:
...
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFile = objFSO.CreateTextFile (&quot;FreeSpaceLog.txt&quot;)
Computers = Array(&quot;psipro&quot;,&quot;cssis2&quot;,&quot;psiacct&quot;,&quot;psiterm&quot;)
For Each Computer In Computers
...
    If FreeMegabytes < WARNING_THRESHHOLD Then
      objFile.WriteLine (Computer & vbTab & _
        objLogicalDisk.DeviceID & _
        &quot; is low on disk space.&quot;)
    Else 
      objFile.WriteLine (Computer & vbTab & _
        objLogicalDisk.DeviceID & _
        &quot; is OK.&quot;)                
    End If
...
and remove the Sub WriteLog.

Hope This Help
PH.
 
PH, I got it work this way, but have not tried your suggestion yet. Your way would be cleaner if it works. Will Try it out. But appreciate your help as you led me to a solution that worked.

'FreeSpace.vbs Barry Hohstadt 12/15/03
'Determines if free space on server disks falls below 400MB and write results to log.

On Error Resume Next
Const CONVERSION_FACTOR = 1048576 'converts to MB
Const WARNING_THRESHHOLD = 400 'in MB

'Modify array to add or remove servers.
Computers = Array(&quot;psipro&quot;,&quot;cssis2&quot;,&quot;psiacct&quot;,&quot;psiterm&quot;)

CreateLog
For Each Computer In Computers
Set objWMIService = GetObject (&quot;winmgmts://&quot; & computer & &quot;/root/cimv2&quot;)
If Err.Number <> 0 Then
Wscript.Echo Computer & &quot; &quot; & Err.Description
Err.Clear
Else
set colLogicalDisk = objWMIService.InstancesOf (&quot;win32_LogicalDisk&quot;)
For Each objLogicalDisk In colLogicalDisk

FreeMegabytes = objLogicalDisk.FreeSpace / CONVERSION_FACTOR
If FreeMegabytes < WARNING_THRESHHOLD Then
WriteLog_Low

Else
WriteLog_OK

End If
Next
End If
Next



' Sub Routines
Sub CreateLog
Const ForWriting = 2
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFile = objFSO.CreateTextFile (&quot;FreeSpaceLog.txt&quot;, ForWriting)
objFile.Close
End Sub

Sub WriteLog_OK
Const ForAppending = 8
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objAppendFile = objFSO.OpenTextFile (&quot;FreeSpaceLog.txt&quot;, ForAppending)
objAppendFile.WriteLine (Computer & vbTab & objLogicalDisk.DeviceID & _
&quot; is OK.&quot;)
End Sub

Sub WriteLog_Low
Const ForAppending = 8
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objAppendFile = objFSO.OpenTextFile (&quot;FreeSpaceLog.txt&quot;, ForAppending)
objAppendFile.WriteLine (Computer & vbTab & objLogicalDisk.DeviceID & _
&quot; is low on disk space.&quot;)
objAppendFile.Close

End Sub
 
Hello ixoni,

There are many ways to do the same thing, we know that. So let me use your way of rendering the functionality. I see some fundamental issue unsettled.

[1] In Createlog, fso.createtextfile has the second parameter true/false(default). It cannot be ForWriting.
[2] You can no problem set up fso each time in createlog and writelog_, but you must in this case dereference it, else it is a real memory leak. You add at the end set fso=nothing.
[3] Writelog_low you have closed the textfile. That is the right thing to do. How about Writelog_ok? You have to do the same.
[4] I come to suspect that permission denied is not that you are denied to access the info wmiservice wants to access, but the logfile hanging opened and you want to write to it via another instance of fso.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top