single instance of EXE server 
Author Message
 single instance of EXE server

Hi All,

Does anyone know how to prevent multiple instance of atl EXE server from
running? Any pointers to code samples will be great help.

TIA



Fri, 27 Jun 2003 05:00:43 GMT  
 single instance of EXE server
Greets,

    Use the DCOMCNFG utility to launch the out-of-process server under a
specific user account.

Regards,

Joe


Quote:
> Hi All,

> Does anyone know how to prevent multiple instance of atl EXE server from
> running? Any pointers to code samples will be great help.

> TIA



Fri, 27 Jun 2003 07:02:30 GMT  
 single instance of EXE server
Try to find the "RegisterClassObjects" function in your code and pass the
REGCLS_MULTIPLEUSE instead of REGCLS_SINGLEUSE.

Hope this helps.

Andre Lam


Quote:
> Hi All,

> Does anyone know how to prevent multiple instance of atl EXE server from
> running? Any pointers to code samples will be great help.

> TIA



Fri, 27 Jun 2003 13:54:17 GMT  
 single instance of EXE server
You have to design your server to be singleton.
Use DECLARE_CLASSFACTORY_SINGLETON macro in your class definition. Search
MSDN for more information about using mentioned macro.


Quote:
> Hi All,

> Does anyone know how to prevent multiple instance of atl EXE server from
> running? Any pointers to code samples will be great help.

> TIA



Fri, 27 Jun 2003 17:00:30 GMT  
 single instance of EXE server
Greets,

    Declaring it as a singleton will only make sure it hands out the same
object when an interface is requested... on a per process basis.  This does
not ensure that only one instance of an out-of-process server will be
launched, especially when it is requested by a client in a different
security context.

Regards,

Joe


Quote:
> You have to design your server to be singleton.
> Use DECLARE_CLASSFACTORY_SINGLETON macro in your class definition. Search
> MSDN for more information about using mentioned macro.



> > Hi All,

> > Does anyone know how to prevent multiple instance of atl EXE server from
> > running? Any pointers to code samples will be great help.

> > TIA



Fri, 27 Jun 2003 21:32:03 GMT  
 single instance of EXE server
Thanks for all your feedback.

I tried creating a service to run under w2k using
DECLARE_CLASSFACTORY_SINGLETON and tested it out with a bunch of VB clients
hitting on it [using both createobject and getobject ] and it looks like it
works as far as making the com object singleton.

Andre, when I created service it automatically had the REGCLS_MULTIPLEUSE
flag set for it so I didn't have to do anything additional for it

However, I can still go to
cmd prompt and start another exe manually and I can see two instances of exe
running in task manager. So it looks like I can not restrict the instances
to one using this technique.

Joe, I tried looking into dcomcnfg. But from your post there is not much
info to go on. You said I can launch the exe under a specific user account,
and I think I know how to configure that but how that is going to allow me
to restict it to just one instance of EXE? Call me ignorant, but I'd really
appreciate it if you can give more detailed info.

Also, once this works I need to make it EXE server that can run on both W9Xs
and NT/W2ks.

Thanks again for all your feedback.


Quote:
> Greets,

>     Declaring it as a singleton will only make sure it hands out the same
> object when an interface is requested... on a per process basis.  This
does
> not ensure that only one instance of an out-of-process server will be
> launched, especially when it is requested by a client in a different
> security context.

> Regards,

> Joe



> > You have to design your server to be singleton.
> > Use DECLARE_CLASSFACTORY_SINGLETON macro in your class definition.
Search
> > MSDN for more information about using mentioned macro.



> > > Hi All,

> > > Does anyone know how to prevent multiple instance of atl EXE server
from
> > > running? Any pointers to code samples will be great help.

> > > TIA



Sat, 28 Jun 2003 01:16:44 GMT  
 single instance of EXE server
Greets,

    When using DCOMCNFG to choose the security context, just run the utility
and select your application from the list.  Next, click on "Properties" and
select the "Identity" tab.  Select the "This User" radio button and fill out
the account and password information.  The server will then be launched by
DCOM under that particular context.

Regards,

Joe


Quote:
> Thanks for all your feedback.

> I tried creating a service to run under w2k using
> DECLARE_CLASSFACTORY_SINGLETON and tested it out with a bunch of VB
clients
> hitting on it [using both createobject and getobject ] and it looks like
it
> works as far as making the com object singleton.

> Andre, when I created service it automatically had the REGCLS_MULTIPLEUSE
> flag set for it so I didn't have to do anything additional for it

> However, I can still go to
> cmd prompt and start another exe manually and I can see two instances of
exe
> running in task manager. So it looks like I can not restrict the instances
> to one using this technique.

> Joe, I tried looking into dcomcnfg. But from your post there is not much
> info to go on. You said I can launch the exe under a specific user
account,
> and I think I know how to configure that but how that is going to allow me
> to restict it to just one instance of EXE? Call me ignorant, but I'd
really
> appreciate it if you can give more detailed info.

> Also, once this works I need to make it EXE server that can run on both
W9Xs
> and NT/W2ks.

> Thanks again for all your feedback.



> > Greets,

> >     Declaring it as a singleton will only make sure it hands out the
same
> > object when an interface is requested... on a per process basis.  This
> does
> > not ensure that only one instance of an out-of-process server will be
> > launched, especially when it is requested by a client in a different
> > security context.

> > Regards,

> > Joe



> > > You have to design your server to be singleton.
> > > Use DECLARE_CLASSFACTORY_SINGLETON macro in your class definition.
> Search
> > > MSDN for more information about using mentioned macro.



> > > > Hi All,

> > > > Does anyone know how to prevent multiple instance of atl EXE server
> from
> > > > running? Any pointers to code samples will be great help.

> > > > TIA



Sat, 28 Jun 2003 01:36:58 GMT  
 single instance of EXE server
Found a much cooler way to restrict running instance of exe to one instance,
here is the url:

http://support.microsoft.com/support/kb/articles/Q243/9/53.ASP

the approach uses a class which creates a mutex in its constructor with a
given mutex name [i.e. any GUID is fine]. First time it will create a mutex
with a specific name, but second time it will return an error and this error
will be cached in the object by calling getlasterror(). Instantiate the
class at a proper place in your code and check if the instance already
exists using the class's only method. If it exists abort.


Quote:
> Greets,

>     When using DCOMCNFG to choose the security context, just run the
utility
> and select your application from the list.  Next, click on "Properties"
and
> select the "Identity" tab.  Select the "This User" radio button and fill
out
> the account and password information.  The server will then be launched by
> DCOM under that particular context.

> Regards,

> Joe



> > Thanks for all your feedback.

> > I tried creating a service to run under w2k using
> > DECLARE_CLASSFACTORY_SINGLETON and tested it out with a bunch of VB
> clients
> > hitting on it [using both createobject and getobject ] and it looks like
> it
> > works as far as making the com object singleton.

> > Andre, when I created service it automatically had the
REGCLS_MULTIPLEUSE
> > flag set for it so I didn't have to do anything additional for it

> > However, I can still go to
> > cmd prompt and start another exe manually and I can see two instances of
> exe
> > running in task manager. So it looks like I can not restrict the
instances
> > to one using this technique.

> > Joe, I tried looking into dcomcnfg. But from your post there is not much
> > info to go on. You said I can launch the exe under a specific user
> account,
> > and I think I know how to configure that but how that is going to allow
me
> > to restict it to just one instance of EXE? Call me ignorant, but I'd
> really
> > appreciate it if you can give more detailed info.

> > Also, once this works I need to make it EXE server that can run on both
> W9Xs
> > and NT/W2ks.

> > Thanks again for all your feedback.



> > > Greets,

> > >     Declaring it as a singleton will only make sure it hands out the
> same
> > > object when an interface is requested... on a per process basis.  This
> > does
> > > not ensure that only one instance of an out-of-process server will be
> > > launched, especially when it is requested by a client in a different
> > > security context.

> > > Regards,

> > > Joe



> > > > You have to design your server to be singleton.
> > > > Use DECLARE_CLASSFACTORY_SINGLETON macro in your class definition.
> > Search
> > > > MSDN for more information about using mentioned macro.



> > > > > Hi All,

> > > > > Does anyone know how to prevent multiple instance of atl EXE
server
> > from
> > > > > running? Any pointers to code samples will be great help.

> > > > > TIA



Sat, 28 Jun 2003 03:45:06 GMT  
 single instance of EXE server
A trick I used in an MFC app could be adapted to ATL, you take your app's
main window (or make a dummy, hidden window if you have no I/O), and when
your app starts up, you check for a window of that class, if it exists,
activate the window in the original app, and exit the second instance of the
app.  The only painful part is getting a window to come up forground under
Win98/2000.  That function is also below.  If you are not doing display I/O,
you can take out all of the iconic restoration junk.  Hope this helps.

BOOL CMyApp::FirstInstance()
{
 CWnd *pWndPrev, *pWndChild;

 // Determine if another window with your class name exists...
 if (pWndPrev = CWnd::FindWindow(_T("MyWinClass"),NULL))
 {
  // If so, does it have any popups?
  pWndChild = pWndPrev->GetLastActivePopup();

  // If iconic, restore the main window
  if (pWndPrev->IsIconic())
     pWndPrev->ShowWindow(SW_RESTORE);

  pWndPrev->SetForegroundWindow();
  ForceForegroundWindow(pWndPrev->m_hWnd);

  // Bring the main window or its popup to
  // the foreground
  // and you are done activating the previous one.
  return FALSE;
 }
 // First instance. Proceed as normal.
 else
  return TRUE;

Quote:
}

void ForceForegroundWindow(HWND hWnd)
{
 DWORD ThreadID1, ThreadID2, nRet, l;

 if(GetForegroundWindow() != hWnd)
 {
  // Get the thread responsible for this window and the thread
  // for the foreground window
  l = 0;
  ThreadID1 = GetWindowThreadProcessId(::GetForegroundWindow(), &l);
  l = 0;
  ThreadID2 = GetWindowThreadProcessId(hWnd, &l);

  // By sharing input state, threads share their concept of the active
window
  if(ThreadID1 != ThreadID2)
  {
   AttachThreadInput(ThreadID1, ThreadID2, TRUE);
   nRet = ::SetForegroundWindow(hWnd);
   AttachThreadInput(ThreadID1, ThreadID2, FALSE);
  }
  else
  {
   nRet = ::SetForegroundWindow(hWnd);
  }

  if(::IsIconic(hWnd))
   ::ShowWindow(hWnd, SW_RESTORE);
  else
   ::ShowWindow(hWnd, SW_SHOW);
 }

Quote:
}



Sat, 28 Jun 2003 04:00:45 GMT  
 single instance of EXE server
Greets,

    This is a problem which is not really relevant in the scope of using an
out-of-process server with a client using DCOM.  The problem you will run
into is that any client which launches another instance of the process in a
different security context (i.e. if you have not used DCOMCNFG to configure
a specific account) then the application will abort using the method
outlined in that KB article and leave the client confused.

    You basically need to choose how you want this to behave:  1) a single
process handing out a single instance of an object to multiple clients in
different security contexts; 2) a single processing handing out a single
instance of an object to multiple clients in the same security context; 3)
multiple processes handing out single instances to clients in different
security contexts; 4) mutliple processes handing out multiple instances to
clients in the same security context;  5) single process handing out
mutliple instances to clients in a specifc security context.... and other
such configurations.  Those are going to determine how you configure your
component to behave.

    It sounds to me that if you are using KB article, you are now limiting
only one client in a given security context to have access to the server.
If that is the case, do you still want to allow the client to create
mutliple instances of objects from the server?  or a single instance?  How
are you going to handle cases where clients cannot launch the server?

Regards,

Joe


Quote:
> Found a much cooler way to restrict running instance of exe to one
instance,
> here is the url:

> http://support.microsoft.com/support/kb/articles/Q243/9/53.ASP

> the approach uses a class which creates a mutex in its constructor with a
> given mutex name [i.e. any GUID is fine]. First time it will create a
mutex
> with a specific name, but second time it will return an error and this
error
> will be cached in the object by calling getlasterror(). Instantiate the
> class at a proper place in your code and check if the instance already
> exists using the class's only method. If it exists abort.



> > Greets,

> >     When using DCOMCNFG to choose the security context, just run the
> utility
> > and select your application from the list.  Next, click on "Properties"
> and
> > select the "Identity" tab.  Select the "This User" radio button and fill
> out
> > the account and password information.  The server will then be launched
by
> > DCOM under that particular context.

> > Regards,

> > Joe



> > > Thanks for all your feedback.

> > > I tried creating a service to run under w2k using
> > > DECLARE_CLASSFACTORY_SINGLETON and tested it out with a bunch of VB
> > clients
> > > hitting on it [using both createobject and getobject ] and it looks
like
> > it
> > > works as far as making the com object singleton.

> > > Andre, when I created service it automatically had the
> REGCLS_MULTIPLEUSE
> > > flag set for it so I didn't have to do anything additional for it

> > > However, I can still go to
> > > cmd prompt and start another exe manually and I can see two instances
of
> > exe
> > > running in task manager. So it looks like I can not restrict the
> instances
> > > to one using this technique.

> > > Joe, I tried looking into dcomcnfg. But from your post there is not
much
> > > info to go on. You said I can launch the exe under a specific user
> > account,
> > > and I think I know how to configure that but how that is going to
allow
> me
> > > to restict it to just one instance of EXE? Call me ignorant, but I'd
> > really
> > > appreciate it if you can give more detailed info.

> > > Also, once this works I need to make it EXE server that can run on
both
> > W9Xs
> > > and NT/W2ks.

> > > Thanks again for all your feedback.



> > > > Greets,

> > > >     Declaring it as a singleton will only make sure it hands out the
> > same
> > > > object when an interface is requested... on a per process basis.
This
> > > does
> > > > not ensure that only one instance of an out-of-process server will
be
> > > > launched, especially when it is requested by a client in a different
> > > > security context.

> > > > Regards,

> > > > Joe



> > > > > You have to design your server to be singleton.
> > > > > Use DECLARE_CLASSFACTORY_SINGLETON macro in your class definition.
> > > Search
> > > > > MSDN for more information about using mentioned macro.



> > > > > > Hi All,

> > > > > > Does anyone know how to prevent multiple instance of atl EXE
> server
> > > from
> > > > > > running? Any pointers to code samples will be great help.

> > > > > > TIA



Sat, 28 Jun 2003 04:14:41 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. ATL MFC EXE singleton server, single instance application

2. ATL MFC EXE singleton server, single instance application

3. Attach multiple executables to single ATL COM EXE instance

4. single com server instance

5. single server instance

6. Single instance Com server

7. total confusion in single threaded exe server

8. Single project for DLL and EXE server

9. Single project for DLL and EXE server

10. Get running instances of server.exe

11. Newbie needs help: Managing ActiveX exe server instancing / IIS (long)

12. Why two instances of EXE Server lauched?

 

 
Powered by phpBB® Forum Software