Problem with CIM_DataFile class

D

Dick Sutton

I have a situation on a small office LAN where the dbms needs to be backed
up prior to the Office Manager leaving for the day. Since the users of the
data base may or may not have the dbms in use, I thought that I would check
the 'InUseCount' of one of the dbms files to see if it was in use. I know
that if this file is open, then the database is in use.

However, no matter when or how I run this code, the answer is always the
same: <null>. What am I overlooking? What am I doing wrong? See sample
code below.

Thanks in advance...

Dick

--------------------------------------------------------------------------------
Option Explicit
Dim oWMI, oFile, strFilePath

strFilePath = "C:\\MED\\mwtrn.adt"

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oFile = oWMI.Get("CIM_DataFile.Name=""" & strFilePath & """")

If oFile.InUseCount > 0 Then
MsgBox "Med DBMS in use!"
Else
MsgBox "Good to go!"
End If

--------------------------------------------------------------------------------
 
J

Jim Vierra

Try it this way - It works for me. Double \ is not good for vbscript; only
C# and Jscript.

Option Explicit
Dim oWMI, oFile, strFilePath

strFilePath = "C:\MED\mwtrn.adt"

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oFile = oWMI.Get("CIM_DataFile.Name='" & strFilePath & "'")

If oFile.InUseCount > 0 Then
MsgBox "Med DBMS in use!"
Else
MsgBox "Good to go!"
End If
 
D

Dick Sutton

Jim,
Thanks for the tip, but it still doesn't work. I placed a line:

MsgBox oFile.InUseCount

before the If statement and ran it. I received an error saying:

Invalid use of Null: InUseCount

I'm sure that I must be doing something else wrong.
Any other ideas?

Have you ever had the InUseCount work?

Dick

Jim Vierra said:
Try it this way - It works for me. Double \ is not good for vbscript;
only C# and Jscript.

Option Explicit
Dim oWMI, oFile, strFilePath

strFilePath = "C:\MED\mwtrn.adt"

Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set oFile = oWMI.Get("CIM_DataFile.Name='" & strFilePath & "'")

If oFile.InUseCount > 0 Then
MsgBox "Med DBMS in use!"
Else
MsgBox "Good to go!"
End If
 
J

Jim Vierra

What OS are you querying? Do you have sufficient permissions. You need to
be an admin and have access to the file. You should also explicitly declare
impersonation in case DCOM isn't set up the way you expect.

--
Jim Vierra

Dick Sutton said:
Jim,
Thanks for the tip, but it still doesn't work. I placed a line:

MsgBox oFile.InUseCount

before the If statement and ran it. I received an error saying:

Invalid use of Null: InUseCount

I'm sure that I must be doing something else wrong.
Any other ideas?

Have you ever had the InUseCount work?

Dick
 
D

Dick Sutton

Hi Jim,

I'm running on Win XP Home. I'm also using an admin account, so permissions
should not be an issue. As you can see from the sample code that I included
in my original post, I am running this test script on just 'this' computer
(i.e. the '.' in place of a computer name).

I set the GetObject line to use impersonate as follows:
..
Set oWMI =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

The result is the same error saying:

Invalid use of Null: InUseCount

I hope you have some more ideas... I'm running out ...
Dick
 
J

Jim Vierra

Try downloading and installing WSH 5.6. Sometimes this clears up some
script parsing problems.

I don't think wbemtest is on Home edition or it would be an easy place to
test if it's the scripting or WMI.

Look in SDK for coverage of the WMI class. Home may not be included.
 
D

Dick Sutton

Jim,

Actually I have the latest WSH 5.6 package. Also, wbemttest is included on
my XP Home system. You can't imagine the hours (or maybe you can) that I've
sat here running up and down the list of objects using wbemtest and trying
everything that I can think of. I think that in this case, Microsoft just
haven't implemented the InUseCount data. I guess I was hoping for a simple
error that I was making.

I have been able to get a list of open files on a LAN connection, but not on
a local machine. If you get anymore ideas, be sure to post back. I just
can't believe that I can't get a list of local file handles from WMI.

Thanks again...

Dick
 
J

Jim Vierra

You might try OH from the Resource Kit.

"Home Edition" is one of my pet peeves. It ranks up there with Windows ME.
One step forward and two steps back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top