Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 928
  • Last Modified:

GetObject(,"myactivex.component")

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
CJ_S
Asked:
CJ_S
  • 21
  • 9
  • 3
  • +4
1 Solution
 
TimCotteeHead of Software ServicesCommented:
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
 
CJ_SAuthor Commented:
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
 
TimCotteeHead of Software ServicesCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
CJ_SAuthor Commented:
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
 
EDDYKTCommented:
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
 
EDDYKTCommented:
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
 
CJ_SAuthor Commented:
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
 
CJ_SAuthor Commented:
EDDYKT,
already done that, doesn't work :-/ Unless I forgot an important setting.

CJ
0
 
Michel SakrCommented:
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
 
EDDYKTCommented:
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
 
CJ_SAuthor Commented:
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
 
EDDYKTCommented:
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
 
EDDYKTCommented:
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
 
Michel SakrCommented:
>my ASP page (Anonymous access as will the production environment eventually).

no! you are initialising the component as your account..
0
 
CJ_SAuthor Commented:
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
 
CJ_SAuthor Commented:
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
 
CJ_SAuthor Commented:
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
 
EDDYKTCommented:
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
 
EDDYKTCommented:
for example


Public Function ASPGetObject(ByVal sObjectName As String) As Object
   On Error Resume Next
   Set ASPGetObject = createobject(sObjectName)
End Function
0
 
AzraSoundCommented:
>>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
 
EDDYKTCommented:
>>after the first call the the object the GetObject(,"myactivex.component") returns always the existing
object.


I believe the component is not singleuse
0
 
manihopeverCommented:
Are you trying this in some other machine or in the machine where you have the source code.
0
 
CJ_SAuthor Commented:
>> 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
 
EDDYKTCommented:
>>>> 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
 
CJ_SAuthor Commented:
True, but since the object is already GetObject compatible it should work properly. I can always give it a try... thanks anyway :-)
0
 
CJ_SAuthor Commented:
>> 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
 
AzraSoundCommented:
May also try using WScript object:

WScript.GetObject(...)
0
 
CJ_SAuthor Commented:
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
 
AzraSoundCommented:
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
 
CJ_SAuthor Commented:
No worries. I appreciate all the help :-)

0
 
clockwatcherCommented:
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
 
clockwatcherCommented:
That ASP code should have been:

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

But, you get the idea.
0
 
clockwatcherCommented:
Did you have a chance to try those DCOM configuration changes?
0
 
CJ_SAuthor Commented:
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
 
CJ_SAuthor Commented:
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
 
CJ_SAuthor Commented:
Continueing with this today! (finally, i know)
0
 
CJ_SAuthor Commented:
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
 
CJ_SAuthor Commented:
Might it be related to the call being made to WebOnAir.onAir and the DCOM takes WebOnAir.Webs?

0
 
CJ_SAuthor Commented:
After a reboot it all seems to be working now...
0
 
CJ_SAuthor Commented:
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
 
CJ_SAuthor Commented:
Look for some other q's for you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 21
  • 9
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now