Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA WMI Intermittent Error

Hi,

I have created a simple VBA program to retrieve the current disk space
on our server into an Excel workbook. One of the servers that I'm
running the query against is located on another trusted domain. When I
run the VBA code on my workstation, logged on as me the code run fine,
but if I run the same code on one of our servers (still logged on as
me) the code fails with the error 80070721, "a security package
specific error occurred". As you can see from the code below, I'm
using Impersonation level impersonate. If I change this and specify a
user name and password (the one I'm currently logged on as ) it all
works fine. I'm running Windows XP SP2 on my workstation and Windows
2003 Server SP 1 on the other server. The server in the other domain
is running Windows 2000 Server SP3 (Upgraded from Windows NT 4).
Any help would be much appreciated.

Sub GetDiskInformation(strComputer As String)
Dim objDisk As Object
Dim colDisks As Object
Dim objWMIService As Object
Dim intCount As Integer
Dim intColumnID As Integer
Dim dblFreeSpace As Double
Dim dblTotalSize As Double
Dim strGB As String

'On Error GoTo errormessage

intColumnID = 1

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

Set colDisks = objWMIService.ExecQuery("Select * from
Win32_LogicalDisk")

Sheets("Disk Space").Cells(intRowID + 1, intColumnID).Value =
strComputer

For Each objDisk In colDisks
If objDisk.drivetype = 3 Then
dblFreeSpace = objDisk.FreeSpace / 1024 / 1024 / 1024
dblTotalSize = objDisk.Size / 1024 / 1024 / 1024

If dblFreeSpace < 1 Then
dblFreeSpace = dblFreeSpace * 1000
blnGB = " MB"
Else
blnGB = " GB"
End If

If dblTotalSize < 1 Then
dblTotalSize = dblTotalSize * 1000
blngb2 = " MB"
Else
blngb2 = " GB"
End If

dblFreeSpace = Round(dblFreeSpace, 2)
dblTotalSize = Round(dblTotalSize, 2)

Sheets("Disk Space").Cells(intRowID + 1, intColumnID +
1).Value = objDisk.DeviceID
Sheets("Disk Space").Cells(intRowID + 1, intColumnID +
2).Value = dblFreeSpace & blnGB & "(" & dblTotalSize & blngb2 & ")"
intColumnID = intColumnID + 2
End If
Next

intRowID = intRowID + 1

errormessage:
Set objWMIService = Nothing
End Sub

Thanks in advance
Dave

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Intermittent Error: Source not found IainC Links and Linking in Excel 1 November 19th 09 02:55 AM
Client Safety Options - Intermittent error KaneSama2k3 Excel Worksheet Functions 0 March 17th 08 11:20 AM
intermittent error and lockup problem Gary Keramidas Excel Programming 3 June 1st 07 08:46 PM
Run-time error '1004'; Document not saved - intermittent Kerry Excel Programming 0 December 15th 05 10:10 PM
intermittent error - ActiveX component can't create object Naveen Excel Programming 1 December 30th 04 05:11 PM


All times are GMT +1. The time now is 11:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"