Managing Open Resources

   

Managing Open Resources

For each user session, there are resources associated with the open connection. If a user is using an Access database, the associated .MDB file is considered an open resource in Server Manager. Using ADSI, you can enumerate all files currently in use, and subsequently view the user and lock count information for each open resource.

The ability to disconnect a user from a resource can be an important feature to administrators charged with data migration tasks where the file they want to move may be in use. When file access is denied because of an exclusive lock on the file by a user, often the only way for an administrator to gain access to the file is to simply disconnect the user from the resource.

Note

Unfortunately, the ability to perform this task using ADSI is not implemented in release 2.5 of the ADSI libraries.


Enumerating Open Resources Using Visual Basic

As shown in Figure 7.5, you can use the GUI to enumerate all open resources on a given machine. To perform this same function using ADSI, simply use a For Each Next loop to enumerate the contents of the IADsResource collection.

Figure 7.5. Open Resources dialog box in Windows NT Server Manager.

graphics/07fig05.gif

Use the following Visual Basic code to enumerate all open resources on a given machine:

 Dim FileService As IADsFileServiceOperations Dim ComputerName As String Dim ComputerDomain As String Dim Resource As IADsResource ComputerDomain = "  Target_Computer_Domain  " ComputerName = "  Target_Computer_Name  " Set FileService = GetObject("WinNT://"&ComputerDomain&"/"&ComputerName& "/LanmanServer") For Each Resource In FileService.Resources      Debug.Print "ResourceID: "&Resource.Name&" Resource: "&Resource.Path & " Opened by: graphics/ccc.gif "&_ Resource.User&" Lock Count: "&Resource.LockCount Next 

Note

The Debug.Print statement shows all properties of the IADsResource interface in the Windows NT service provider that you can examine.


Let's look at each individual property of the IADsResource interface:

  • Name . This property is the system-generated name assigned to the resource. This is essential for identifying the resource within a collection for manipulation.

  • Path . This property is the physical path of the open resource.

  • User . This property is the user who holds the resource open.

  • LockCount . This property is the number of locks on the resource.

Examining the Properties of a Single Open Resource Using Visual Basic

Windows NT dynamically assigns the Name property to the open resources on a machine, making it impossible to take any sort of educated guess as to what the proper way to identify the resource might be. To overcome this minor obstacle , simply combine a conditional with the enumeration function shown in the previous section, "Enumerating Open Resources Using Visual Basic," to filter data down to a specific user and resource.

Use the following Visual Basic code to show all open resources for a particular user:

 Dim FileService As IADsFileServiceOperations Dim ComputerName As String Dim ComputerDomain As String Dim ResourceUser As String Dim ResourcePath As String Dim Resource As IADsResource Dim Collection As IADsCollection ComputerDomain = "Target_Computer_Domain" ComputerName = "Target_Computer_Name" ResourceUser = "Target_Username" Set FileService = GetObject("WinNT://"&ComputerDomain&"/"&ComputerName& "/LanmanServer") Set Collection = FileService.Resources Debug.Print "User "&ResourceUser&" has the following resources open:" For Each Resource In Collection      If Resource.User = ResourceUser Then           Debug.Print Resource.Path      End If Next 

Tip

By changing the conditional statement and the contents of the ResourceUser variable, you can show a list of all users currently associated with an open resource, or even show all files that currently have locks on them.



   
Top


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net