By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

Struggling to diagnose a COM exception error (80041003)

P: n/a
I'm rewriting some existing VBScript into VB.Net code. It was all going well
until I hit the following error when testing the code:

System.Runtime.InteropServices.COMException (0x80041003)
at Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)

The specific call that is failing is:

objShareCfg =
objShare.INetSharingConfigurationForINetConnection (objNetConn)

I've now referenced NETCONLIB, which is the COM interface for the INet
stuff. If I change the DIM statements for objShareCfg and objNetConn to the
correct types, I still get the COMException.

If I change the initial object creation part from:

objShare = CreateObject("HNetCfg.HNetShare")

to

Dim objShare As New NETCONLib.NetSharingManagerClass

I still get the COMException but the location (not surprisingly) changes:

System.Runtime.InteropServices.COMException (0x80041003): Exception from
HRESULT: 0x80041003.
at
NETCONLib.NetSharingManagerClass.get_INetSharingCo nfigurationForINetConnection(INetConnection
pNetConnection)

The VBScript runs without error under the same user account on the same
computer. The VB.Net code runs without error on the development machine :-(.

Anyone got any suggestions on what I can try next?

--Philip
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hi Philip,

I just Googled that error number and it seems like it's an "Admin Rights
Required" error code. This would make sense judging by what you're trying
to do (configure connection sharing?) and be consistent with it working fine
on your development machine. It's always wise to test an your software in a
separate Power User & Restricted User account, in case there are any
pitfalls you hadn't coded for.

Cheers,
Alex

"Philip Colmer" <pc*****@newsgroups.nospam> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
I'm rewriting some existing VBScript into VB.Net code. It was all going
well until I hit the following error when testing the code:

System.Runtime.InteropServices.COMException (0x80041003)
at Microsoft.VisualBasic.CompilerServices.LateBinding .LateGet(Object o,
Type objType, String name, Object[] args, String[] paramnames, Boolean[]
CopyBack)

The specific call that is failing is:

objShareCfg =
objShare.INetSharingConfigurationForINetConnection (objNetConn)

I've now referenced NETCONLIB, which is the COM interface for the INet
stuff. If I change the DIM statements for objShareCfg and objNetConn to
the correct types, I still get the COMException.

If I change the initial object creation part from:

objShare = CreateObject("HNetCfg.HNetShare")

to

Dim objShare As New NETCONLib.NetSharingManagerClass

I still get the COMException but the location (not surprisingly) changes:

System.Runtime.InteropServices.COMException (0x80041003): Exception from
HRESULT: 0x80041003.
at
NETCONLib.NetSharingManagerClass.get_INetSharingCo nfigurationForINetConnection(INetConnection
pNetConnection)

The VBScript runs without error under the same user account on the same
computer. The VB.Net code runs without error on the development machine
:-(.

Anyone got any suggestions on what I can try next?

--Philip

Nov 21 '05 #2

P: n/a

"Alex Clark" <qu*******@community.nospam> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Hi Philip,

I just Googled that error number and it seems like it's an "Admin Rights
Required" error code. This would make sense judging by what you're trying
to do (configure connection sharing?) and be consistent with it working
fine on your development machine. It's always wise to test an your
software in a separate Power User & Restricted User account, in case there
are any pitfalls you hadn't coded for.

Cheers,
Alex


That was my first thought as well ... except for the fact that the original
VBScript works without errors on the same computer that the VB.NET code is
failing on. The account I'm using on that test computer is a restricted user
account.

I'm only reading the settings, not trying to change anything.

--Philip
Nov 21 '05 #3

P: n/a
Hi

It is strange that the working code did not work on another machine.
To isolate the problem, I suggest you try run the VB.NET App with
Administrator to see if that works.
You may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4

P: n/a

""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:DL*************@TK2MSFTNGXA01.phx.gbl...
Hi

It is strange that the working code did not work on another machine.
To isolate the problem, I suggest you try run the VB.NET App with
Administrator to see if that works.
You may have a try and let me know the result.


The code does run with an administrator account.

I've put some extra WriteLine statements in the code to try to figure out
what is going on (as I don't have the debugger on the test machine). The
error is occuring inside a For loop:

For Each objNetConn In objEveryColl
Console.WriteLine("Trying to get
INetSharingConfigurationForINetConnection.")
objShareCfg =
objShare.INetSharingConfigurationForINetConnection (objNetConn)
Console.WriteLine("Got it.")

It is the call to objShare.INetSharingConfigurationForINetConnection that is
blowing up. What is strange, though, is that I don't think there is a
connection to interrogate here. The code afterwards goes:

Try
ConnectionProps = objShare.NetConnectionProps(objNetConn)
Catch ex As Exception
Console.WriteLine("Got exception " & ex.ToString & " while
trying to get connection properties")
Exit Sub
End Try

Console.WriteLine("*** Connection : " & ConnectionProps.Name)

When I run this as an administrator, I get a bunch of connections listed and
then the code finishes. When I run this as myself, I get the SAME list of
connections listed but it then stops with the COM exception error. This
suggests that the For loop is getting it wrong, for some reason, when
running as a user account.

I could wrap a Try ... Catch around the code but I'm concerned that I'm
basically putting a sticking plaster over something that does run properly
in its original VBScript version.

--Philip
Nov 21 '05 #5

P: n/a
Hi

I have somewhat confused with your scenario.
When you run the code in a for loop as an administrator, if there is any
exception?
When there will have and when not?

If the code throw exception only when you run as an user account. I think
you may try to check the eventlog to see if there is any security log.
Or you may try to check the filemon or regmon to see if there is any denied.
http://www.sysinternals.com/Utilities/filemon.html
http://www.sysinternals.com/Utilities/regmon.html

Also if the VB Script code did not have error, did not export same output
when your run the same account?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

P: n/a
I've done some more digging into the VBScript version. It has an "On Error
Resume Next" which was masking the COM exception.

The VBScript code does this:

For each objNetConn in objEveryColl
Dim objShareCfg
Dim ConnectionProps

WScript.Echo "Before INetSharingConfigurationForINetConnection: " &
err.number
Set objShareCfg =
objShare.INetSharingConfigurationForINetConnection (objNetConn)
WScript.Echo "After INetSharingConfigurationForINetConnection: " &
err.number
If (IsObject(objShareCfg) = FALSE) Then
WScript.Echo("Unable to retrieve Sharing Cfg Object")
WScript.Quit (2)
End If
...

When it gets the the Bluetooth connection on my PC, err.number changes to
0x80041003. HOWEVER, objShareCfg would appear to change to point to an
object since if I reset objShareCfg to Nothing just before the first
WScript.Echo, I still end up with an object after the COM Exception.

I guess that on the VB.Net side of things, I could do a try-catch and ignore
any exception raised by that call and just test for it being an object?

The Bluetooth code is from XP SP2 (i.e. the Microsoft version) so this might
suggest there is a problem in that code somewhere?

--Philip
Nov 21 '05 #7

P: n/a
Got to the bottom of it ...

The exception is being caused by a dial-up connection that is specific to
the user (i.e. not available to all users). Rewriting the VB.Net code thus:

Try
objShareCfg =
objShare.INetSharingConfigurationForINetConnection (objNetConn)
Catch
' Do nothing - let it fall through to the If test.
End Try

If Not IsReference(objShareCfg) Then
Console.WriteLine("Failed to get
INetSharingConfigurationForINetConnection")
End If

seems to emulate the VBScript more closely and "hide" the COM exception
error.

I don't know if someone at MS wants to investigate why the COM exception is
happening?

--Philip

Nov 21 '05 #8

P: n/a
Hi

In VB.NET you can still use the On Error Resume Next.
Also from your descript above, the problem lie in VB Script too, so it is a
underlying Unmanaged scenario issue.
Because the Administrator will work but not for certian user, so it is a
permission problem, the user has no permission to access the dialup
connection.
If I have any misunderstanding please feel free to post here.
BTW: for ICS(Internet Connection Sharing) issue you may also try to post in
the group below.
microsoft.public.windows.networking.firewall
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.