Using a COM component

hajeeme

New member
Joined
Jan 15, 2010
Messages
4
Programming Experience
Beginner
Hey Guys,

I'm trying to use a registered COM component in my ASP.Net web application. The application is written in VB.Net.
I've added a reference to the Com component using the IDE.

Here's the code:

Try
Dim physicalToken As New PhysicalDevices2.PhysicalToken
Dim physicalTokens As New PhysicalDevices2.PhysicalTokens
Dim roCollection As PhysicalDevices2.ROCollection
If Not IsDBNull(physicalTokens) Then
Response.Write("physicalTokens not Null<br>")
roCollection = physicalTokens.Enumerate()
Dim count As Integer = roCollection.Count
Response.Write(count.ToString + "<br>")
physicalToken = physicalTokens.GetFirstToken()
If Not IsDBNull(physicalToken) Then
Response.Write("physicalToken not Null<br>")
Response.Write(physicalToken.SerialString + "<br>")
Else
Response.Write("physicalToken Null<br>")
End If
Else
Response.Write("physicalTokens Null<br>")
End If
Catch excp As Exception
Response.Write(excp.Message + "<br>")
End Try

And the output:

physicalTokens not Null
0
physicalToken not Null
Object reference not set to an instance of an object.

The last line of the output is referring to physicalToken.SerialString


When I try the same thing in a standard vbs script:

dim physicalToken
dim roCollection
Set physicalTokens = WScript.CreateObject ("PhysicalDevices2.PhysicalTokens" )
If not IsNull(physicalToken ) Then
wscript.echo "physicalTokens not Null"
set roCollection = physicalTokens.Enumerate()
wscript.echo roCollection.Count
set physicalToken = physicalTokens.GetFirstToken()
If Not IsNull(physicalToken) Then
wscript.echo "physicalToken not Null"
wscript.echo physicalToken.SerialString
Else
wscript.echo "physicalToken Null"
End If
Else
wscript.echo "physicalTokens Null"
End If

I get the correct expected output:

physicalTokens not Null
1
physicalToken not Null
05937386d9f031df

Being that I'm not proficient in VB.Net, I'm thinking that it's probably a syntax problem of some sort.

Your help is most appreciated,

Aron-Zvi
 
This
If Not IsDBNull(physicalTokens)
should probably be
VB.NET:
If physicalTokens IsNot Nothing
Since roCollection.Count is 0 the GetFirstToken function most likely return a null reference (Nothing in VB.Net), which you can't detect with IsDBNull. Why your Enumerate call in ASP.Net does not return the same data I don't know. It could be a limitation in rights for the user account that runs the request.
 
Indeed you are correct JohnH. I tried a regular VB.Net and everything works as expected.

I've just tried using impersonation to run the web app as Administrator of the local machine. I've verified that the web app is running as the user, however, it's still not working. Any further ideas?
 
Back
Top