Solved

GetObject(,"myactivex.component")

Posted on 2002-06-07
41
880 Views
Last Modified: 2012-05-05
Hi,
I finished my Ping server statistics program a short while ago. You can probably imagine what it does. However the next step is to make a web interface for this application.

The scripting language I am going to use is ASP and will be migrated to ASP.Net after that. But first the ASP part.

The PingServer is an ActiveX executable which runs on the server. I have added the ability to use the GetObject method just the same as Excel.Application does. When I use GetObject(,"MyActiveX.component") within another VB application I get the running instance of the application. But when I try to access the same from ASP I won't get the running instance but a new instance. This new instance will stay alive and after the first call the the object the GetObject(,"myactivex.component") returns always the existing object.

Since ASP does not allow me to access the component straight away I have created another additional component (ActiveX dll) with the following code:

Private x As Object

Private Sub Class_Terminate()
    Set x = Nothing
End Sub

Public Function ASPGetObject(ByVal sObjectName As String) As Object
    On Error Resume Next
    Set x = GetObject(, sObjectName)
    If (Err.Number = 429) Then
        Err.Clear
        Set x = GetObject("", sObjectName)
        Set x = Nothing
        Set x = GetObject(, sObjectName)
    End If
    Set ASPGetObject = x
End Function

Calling ASPGetObject("MyActiveX.Component") returns my instance.

My question is. Why does it not return me the first running instance but starts a new one which is then used in succeeding calls to this component.

I guess it has something to do with ASP being in memory and not allowing calls to other apartments (IIS runs within Component Services)... how can I fix this?

CJ
0
Comment
Question by:CJ_S
  • 21
  • 9
  • 3
  • +4
41 Comments
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
Are you using Server.CreateObject?

From MSDN:

When using VBScript on the server with ASP, two VBScript features are disabled. Because scripts written with Active Server Pages are executed on the server, the VBScript statements that present user-interface elements, InputBox and MsgBox, are not supported. In addition, do not use the VBScript functions CreateObject and GetObject in server-side scripts. Use Server.CreateObject instead so that ASP can track the object instance. Objects created by CreateObject or GetObject cannot access the ASP built-in objects and cannot participate in transactions. The exception to this rule is when you are using the Admin Objects, and when you are using Java monikers.
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
In ASP I am using the following (not so special) code:
<%
     Set x = Server.CreateObject("ASPObjectWrapper.Objects")
     Set y = x.ASPGetObject("WebOnAir.onAir")
     Set y = Nothing
     Set x = Nothing
%>

Should be okay then...
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
I am by no means an ASP expert but would this not be something that you would instantiate at the IIS level using the global.asa file so that it is available then to all IIS processes. Using a straight Server.CreateObject("WebOnAir.onAir") statement instead of using your wrapper class.
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
I don't want to use Server.CreateObject because I don't want a new object to be instantiated. I want the ASP page to retrieve the current running instance WITH gui.

Within Global.asa I can write that code, but even then it will do the same as described above.

The application starts up by default when the machine boots. Then a couple of days later people would like to log in to their own little system to view the information that has been retrieved using that tool In the meanwhile I also want to walk to the machine and see the program running and receiving events.

CJ
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
I believe it is because you try to start up the component with different user. From ASP, you start up with IWAM_XXX but from your app, you start up as login user.

To resolve this, you can add you dll to COM+(MTs) and start up with a specific user.
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
The other solution will be:

write your own service program and start up as specific user.


I can't think of another way to do.


I don't think  Server.CreateObject will solve your problem.

0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
When i was first playing around and debugged the activex exe the application showed up immediately on screen. But when compiled it doesn't do that (other memory space -> IIS). I'm fairly sure it has something to do with that, and that there has to be a solution to this (hence the amount of points).

I'm willing to increase the points to 1000 if someone has a solution.

CJ
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
EDDYKT,
already done that, doesn't work :-/ Unless I forgot an important setting.

CJ
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
Exactly as eddy mentionned..

your first instance is running in the context of the user that instantiated it.. so if you want to let it use the running instance then do it in com+

Start the Component services..in the tree select computers.. mycomputer..com+ applications...right click on it--> new -> application.. now in the wizard click next and select an empty application -> name your package  leave it in server process and click next -> Select the user and enter the account that launched the 1st instance   -> Finish..

now in the tree expand the new package untill you see the component directory-> right click it -> select new component-> in the wizard click next.. you can install your already registred dll (you select the 2nd choice) -> Select your component from the list (internal name displayed) -> Finish..
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
To verify my though, you can print out the username using getusername from your component, you will see that your compoent starts up from differenet user.
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
I have added the component (not the activex exe) to Component services the way Silvers5 mentioned (and as I have tried before). I restarted my machine, logged in as myself (in component services I have used myself as the user), manually opened the webonair application and tried to access the application from my ASP page (Anonymous access as will the production environment eventually).

I can upload the files to my server if needed. Just ask...

CJ
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
Can you make it work?

If not, bring up your Com+ Application properties

Make sure on your security tab, there is "enforce access.." is checked. On security level, choose 2nd option and Authentication level for call is Packet and Impersionation level is Impersonate

On identity tab, make sure this user (your user)

On activateion should be server application
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
Can you make it work?

If not, bring up your Com+ Application properties

Make sure on your security tab, there is "enforce access.." is checked. On security level, choose 2nd option and Authentication level for call is Packet and Impersionation level is Impersonate

On identity tab, make sure this user (your user)

On activateion should be server application
0
 
LVL 20

Expert Comment

by:Silvers5
Comment Utility
>my ASP page (Anonymous access as will the production environment eventually).

no! you are initialising the component as your account..
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
The component will run as if it were me myself (that's why it is in Component Services).

be back in a couple of minutes... (testing the enforce)
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
Okay, I have checked that too. For the enforce access checkbox I also had to add a role. After having done that there will still be 2 instances running.

I have uploaded the files to my server, they can be downloaded here:
http://www.soft-trax.com/downloads/package.zip
Unzip the zip. Then you will find 1 dll, register it. You'll also find index.asp. This is the entry that I am using (as described above).

Install the application using setup.exe (don't worry, nothing special will happen). It does assume though that you have the MDAC installed and CDONTS is available.
When installing you will encounter one error, just ignore it.

Now start the application manually, and then try accessing the application from the ASP page. You'll find out that a second instance is created.

I hope you can help.

I know points are not always what you are looking for, but if you find 1000 points too few for all this work I will bve glad to increase it to any amount of points with a maximum of 2000 (A graded -> 8000)... just for the efforts and to have this application running as I want it to be. I will continue with this myself also.

CJ
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
EDDYKT,
If I run the activex as a service then I think the same error will still appear. If nobody can find a solution to this I will definitely check that suggestion... but right now I don't think that will do.

CJ
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
I download you project but I've install yet.

Can you change your wrapper class instead of using getobject use createobject


Try it and let me know
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
for example


Public Function ASPGetObject(ByVal sObjectName As String) As Object
   On Error Resume Next
   Set ASPGetObject = createobject(sObjectName)
End Function
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
>>I have added the ability to use the GetObject method just the same as Excel.Application does

Does this mean you just added code to insert the exe into the ROT?

Does altering the class' Instancing property to SingleUse provide any change in how things behave above?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
>>after the first call the the object the GetObject(,"myactivex.component") returns always the existing
object.


I believe the component is not singleuse
0
 
LVL 2

Expert Comment

by:manihopever
Comment Utility
Are you trying this in some other machine or in the machine where you have the source code.
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
>> Does this mean you just added code to insert the exe into the ROT?

I first used GlobalMultiUse but changed that to MultiUse when I didn't use it globally. I will try SingleUse tomorrow.

>> Are you trying this in some other machine or in the machine where you have the source code
on my development machine, but have also tried it on a test server (windows 2000 server), no difference behaviour.

CJ
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
>>>> Does this mean you just added code to insert the exe into the ROT?

>>I first used GlobalMultiUse but changed that to MultiUse when I didn't use it globally. I will try SingleUse
tomorrow.

I don't think singleuse is what you want. Which means will create many instances one for each connection.
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
True, but since the object is already GetObject compatible it should work properly. I can always give it a try... thanks anyway :-)
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
>> Does this mean you just added code to insert the exe into the ROT?

I used the rot type library and added the code to the onAir class.

CJ
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
May also try using WScript object:

WScript.GetObject(...)
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
Don't you have to create the WScript object? I always get an error when trying to use the object wscript without instantiating it...?
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
You can't use the WScript object directly in ASP?  I guess it is only a client-side thing?  It was just a shot in the dark...and I guess it may not even be implementable.  Sorry 'bout that...
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
No worries. I appreciate all the help :-)

0
 
LVL 25

Expert Comment

by:clockwatcher
Comment Utility
You've got a DCOM security issue going on.

Run DCOMCNFG and set your application to run as a specific user.  Here are the steps:
 
  Run dcomcnfg.  
  Find your Application based on it's ProgID -- MyActiveX.Component.  
  Select Properties.  
  Select the Identity tab
  Change it from the default of "Launching User" to a specific user account.

Then in ASP just use the normal GetObject syntax-- get rid of your wrapper class.

<%
  set x = GetObject("MyActiveX.Component")
  x.DoWhatever
%>


Try it and let me know.  I was able to duplicate your problem and the above fixed it for me.
0
 
LVL 25

Expert Comment

by:clockwatcher
Comment Utility
That ASP code should have been:

<%
 set x = GetObject("","MyActiveX.Component")
 x.DoWhatever
%>

But, you get the idea.
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
Comment Utility
Did you have a chance to try those DCOM configuration changes?
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
We're having quite an emergency since last monday. No, but I will get to it. Sorry for the delay (thanks for coming back here)
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
I am really sorry for not closing this down just yet. I still haven't had any time to look into this (deadlines, appointments etc.).

:-(
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
Continueing with this today! (finally, i know)
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
I still have a slight problem. I reinstalled my machine with XP pro and thus had to recreate some settings and stuff. The following is what I have now:

IIS:
- anonymous access

DCOMCNFG:
- identity set on WebOnAir.Webs (this is also the only one that seems to be available to put settings on).

But now I am getting an access denied error message. I knew how I get around this, but it doesn't seem to work right anymore. it works for plain ActiveX components but not with an ActiveX executable.

When the IIS default user is the administrator it has no problem accessing the activex exe (which is running as a service). I'm still offering 2000 pts for a solution.

Giving the IUSR_MACHINENAME launch permissions with DCOMCNFG doesn't do the job (still same error).

Anybody?

CJ

0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
Might it be related to the call being made to WebOnAir.onAir and the DCOM takes WebOnAir.Webs?

0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
After a reboot it all seems to be working now...
0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
I'll be passing the points to clockwatcher since his comment made it work for me (it seems I was using the COM+_ instead of DCOM properties)...

CJ

0
 
LVL 22

Author Comment

by:CJ_S
Comment Utility
Look for some other q's for you!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now