GetAutoServerSettings Function |
object.GetAutoServerSettings([Progid], [Clsid])
object
Use: Required
Data Type: Object expression
An object variable representing the RacReg library.
Progid
Use: Optional
Data Type: Variant
The programmatic identifier (ProgID) for the component.
Clsid
Use: Optional
Data Type: Variant
The class identifier (CLSID) for the component.
A Variant containing an array of values, described in the following table:
Index | Description |
---|---|
1 | 1 if the ActiveX component is registered to execute remotely, if registered to run locally |
2 | Remote machine name |
3 | RPC network protocol name |
4 | RPC authentication level |
Returns registration information for an ActiveX object.
Although both ProgID and Clsid are optional, one must be specified. They are also mutually exclusive.
The variant array that is returned by GetAutoServerSettings is one-based.
To access this function, you must reference the RacReg library in the References section of your project.
Public Function tryCalling() As Boolean 'create local variables Dim oMyObj As MyRemServer.ServClass Dim oRacReg As New RacReg.RegClass Dim vASS As Variant Dim sTest As String 'get the settings of the ActiveX server vASS = _ oRacReg.GetAutoServerSettings("MyRemServer.ServClass") If Not (IsEmpty(vASS)) Then 'check element 1 of the array - True if remote If vASS(1) Then 'quick and dirty method of contacting the server 'at least it'll still work with NT5! sTest = Dir("\" & vASS(2) & "c$autoexec.bat") 'test the return value of the Dir function If sTest = "autoexec.bat" Then 'if ok then create the instance Set oMyObj = New MyRemServer.ServClass 'do some stuff with the object here End If Else 'the server is local - no problem! Set oMyObj = New MyRemServer.ServClass 'do some stuff with the object here End If End If tryCalling_Exit: 'tidy up before you leave Set oMyObj = Nothing Set oRacReg = Nothing tryCalling_Err: 'catch the error thrown by the Dir function when it 'times out because the LAN or WAN lines to the 'remote server are down If Err.Number = 52 Then MsgBox "The server " & vASS(2) & _ " can't be reached at this time" Else MsgBox Err.Description End If 'a variation is to ask the user if they want to retry '& resume to a label just above the Dir function. Resume tryCalling_Exit End Function
Be sure to test that the variant is not empty before trying to reference the array elements.
This rather neat little function allows you to determine if an ActiveX component is registered to run locally or remotely via DCOM. That said, it doesn't allow you to change where the component is registered, nor is there any immediately perceptible benefit in knowing on which server it's to run. I suppose if you know that a particular server is switched off during certain times of the day you can bypass the call!
The function allows you to build in some precall testing to check that the LAN or WAN lines to the server are operational. In other words, you could programmatically "ping" the server and, if successful, make your call to the ActiveX component. This is particularly beneficial when producing client-server applications that operate across a corporate WAN. An annoyance of trying maintain such systems is that the error returned when the "lines" are down is exactly the same as the one when a local DLL can't be instantiated. Therefore, being able to inform the user that a remote server can't be reached and to exit the program gracefully is of great benefit to both user and developer. A complete working example of this concept is shown in the previous example.
RPC stands for Remote Procedure Call; DCOM for Distributed COM.
If this book hits the streets before you upgrade to NT5, and you're having problems with DCOM on your NT4 boxes, make sure you've applied the now legendary Service Pack 3, since earlier builds and service packs had some fairly fundamental glitches in DCOM (i.e., it didn't work!). If you're running Windows 95, you don't automatically have DCOM; however, it's available as a free download from the Microsoft web site. As Windows 9x moves ever closer to NT, DCOM has been made an integral part of Windows 98.
The example for GetAutoServerSettings in the VB5 help file contains an error; the name of the remote server is held at element 2 of the array, not element 1.
The "registered to run remotely" flag held in element 1 of the array returns 1 or 0, not True or False (a subtle but important difference in VB).