Click here to Skip to main content
15,915,160 members
Home / Discussions / C#
   

C#

 
QuestionCodec DirectShow Net Pin
zarmin8-Jun-06 5:51
zarmin8-Jun-06 5:51 
QuestionType casting classes with different namespaces Pin
James Poulose8-Jun-06 5:09
James Poulose8-Jun-06 5:09 
AnswerRe: Type casting classes with different namespaces Pin
Michael Potter8-Jun-06 5:24
Michael Potter8-Jun-06 5:24 
QuestionDrag Drop event not firing Pin
MphasisThomas8-Jun-06 5:04
MphasisThomas8-Jun-06 5:04 
AnswerRe: Drag Drop event not firing Pin
AmithaRaghu5-Jan-10 2:05
AmithaRaghu5-Jan-10 2:05 
Questiondatagridview currentrow changed ? Pin
cmpeng348-Jun-06 5:01
cmpeng348-Jun-06 5:01 
AnswerRe: datagridview currentrow changed ? Pin
leckey8-Jun-06 5:27
leckey8-Jun-06 5:27 
QuestionASP.NET webservice uses COM object and causes System.UnauthorizedAccessException: Access is denied [LONG!] Pin
klanglieferant8-Jun-06 4:31
klanglieferant8-Jun-06 4:31 
Hi!

The situation is a bit more complex than i could formulate it in the subject.

Basically the problem is the different user rights situation running a process as a child-process of aspnet_wp.exe than starting it directly as the logged on user.

I'll try to explain the situation, and if you have any idea where else to search, please post it.

Maybe you might use this approach for you own needs, so i'll decribe it a bit more in detail.


Image the following situation (using .NET 2.0, VS80, c#, c++):

A c# console application is creating the COMServer ("Host.exe") with moniker binding:
object boundhost = System.Runtime.InteropServices.Marshal.BindToMoniker ( monikername );

It is possible to get the correct COM interface like shown below and use it:
IAnyInterface usefulobject = boundhost as IAnyInterface.

Furthermore, the console application provides a .NET remoting object, that uses functions of that bound COMServer:
System.String filename = "Server.exe.config";
System.Runtime.Remoting.RemotingConfiguration.Configure ( filename, false );
System.Console.ReadLine();

[...].
public class ServerObject : System.MarshalByRefObject
{
    [...]

    public void CallCOMMethod()
    {
        if ( usefulobject != null )
        {
            usefulobject.CallTheMethod();
        }
    }

    [...]
}

When starting the Server.exe (console application) it is running as a regular user process, and the bound Host.exe is running under ..\winlogon.exe\services.exe\svchost.exe\Host.exe (visible with ProcessExplorer; thank you guys for that great tool!).
Everything is fine, and i'm able to talk to my COM object via .NET Remoting.

The next part causes some trouble: I try to start and stop the console application remotely with use of a ASP.NET 2.0 WebService (e.x. LaunchService.asmx):
[System.Web.Services.WebMethod]
public bool LaunchServer ()
{
    System.Diagnostics.Process p = new System.Diagnostics.Process ();
    p.StartInfo.UseShellExecute = true;
    p.StartInfo.FileName = "D:\\Anydir\\Server.exe";
    p.StartInfo.WorkingDirectory = "D:\\AnyDir\\";
    p.StartInfo.Arguments = "";
    p.Start();
    return true;
}


The LaunchServer WebMethod call starts the Server.exe as child process of aspnet_wp.exe as user ASPNET and the Server.exe as well.
Regardless of the console output which is missing, I route all outputs to System.Diagnostics.Debug. and i see that the server is running.
First, I had problems reading a file, so i moved the ASPNET user into the group of Administrators (do not try that at home!!), just to see whether it is technically possible at all to use remoting channels from service-processes.
Yep. excellent.
Calling the right method on the remoting object, the Host.exe starts up and the returned object is stored in the Server.exe and can be used.

This is only possible for COM object, providing no COMEvent interface !

Objects, which are providing COM event sources are not loaded:

[
  coclass,
  threading(both),
  aggregatable(never),
  support_error_info("IAnyInterface"),
  vi_progid("COMObject.AnyObject"),
  progid("COMObject.AnyObject.1"),
  version(1.0),
  uuid("{B2D69299-C894-4032-BA07-1AAC494D3D01}"),
  helpstring("AnyObject Class"),
  event_source(com)
]
class ATL_NO_VTABLE CAnyObject :
	public MyComBaseClass,
	public IAnyInterface,
	public _IAnyInterfaceEvents
{
public:
    // ------------------------ Constructor/Destructor ------------------------

    CAnyObject();
    virtual ~CAnyObject();

    // ------------------------ Event Source ------------------------

    __event __interface _IAnyObjectChangedEvents;

    DECLARE_PROTECT_FINAL_CONSTRUCT()

    HRESULT FinalConstruct()
    {
        return S_OK;
    }

    void FinalRelease() 
    {
    }

    void RaiseEvent()
    {
        __raise OnChanged( x ); 
    }

    [...]

}


The exception when the Server.exe is trying to get the COM object like above and link to its event source is:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) 
at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(Object pUnkSink, Int32& pdwCookie) 
at COMObject._IAnyObjectChangedEvents_EventProvider.add_OnChanged(_IAnyObjectChangedEvents_OnChangedEventHandler ) 
at COMObject._IAnyObjectChangedEvents_Event.add_OnChanged(_IAnyObjectChangedEvents_OnChangedEventHandler ) 
at Server.BindToComObjectWithEvents() in ...


The event callback is registered in Server.exe like:

usefulobject.OnChanged += new COMObject._IAnyObjectChangedEvents_OnChangedEventHandler ( eventhanderinserver );


hmm..

Why is it possible to get a COM object and call its functions, but as soon as the COM object provides events and the event handler is about to link the callback, it raised the exception ?

I tried to configure with dcomcnfg.exe the privileges for the COMServer but nothing solved it (it's only working with the "Interactive User" setting on the identity tab).

The Server.exe is running as {machinemname}\ASPNET user and the Host.exe is running under my own account (belonging to BUILTIN\Administrators).

Any ideas ? D'Oh! | :doh:
Thank you very much.
Questionhowto transfer data from datagridview to MS Word and MS Excel ? Pin
cmpeng348-Jun-06 3:51
cmpeng348-Jun-06 3:51 
AnswerRe: howto transfer data from datagridview to MS Word and MS Excel ? Pin
Suamal9-Jun-06 0:51
Suamal9-Jun-06 0:51 
GeneralMessage Closed Pin
9-Jun-06 1:43
cmpeng349-Jun-06 1:43 
GeneralRe: howto transfer data from datagridview to MS Word and MS Excel ? Pin
Mairaaj Khan9-Jun-06 20:08
professionalMairaaj Khan9-Jun-06 20:08 
Questionhello Stephan Samuel Pin
Mahmood Ilyas8-Jun-06 2:22
Mahmood Ilyas8-Jun-06 2:22 
AnswerRe: hello Stephan Samuel Pin
J4amieC8-Jun-06 3:01
J4amieC8-Jun-06 3:01 
QuestionCopy content of Excel cells Pin
sydney_sider8-Jun-06 2:19
sydney_sider8-Jun-06 2:19 
QuestionChanging data in DataTable does not update bound DataGridView Pin
iswoolley8-Jun-06 1:30
iswoolley8-Jun-06 1:30 
AnswerRe: Changing data in DataTable does not update bound DataGridView Pin
alyeasad8-Jun-06 1:49
alyeasad8-Jun-06 1:49 
GeneralRe: Changing data in DataTable does not update bound DataGridView Pin
iswoolley8-Jun-06 2:02
iswoolley8-Jun-06 2:02 
GeneralRe: Changing data in DataTable does not update bound DataGridView Pin
PyroManiak8-Jun-06 7:52
PyroManiak8-Jun-06 7:52 
GeneralRe: Changing data in DataTable does not update bound DataGridView Pin
iswoolley8-Jun-06 22:26
iswoolley8-Jun-06 22:26 
Questionusing C# code in VC++(MFC) application Pin
Shailesh Ha8-Jun-06 1:16
Shailesh Ha8-Jun-06 1:16 
AnswerRe: using C# code in VC++(MFC) application Pin
Jun Du8-Jun-06 7:57
Jun Du8-Jun-06 7:57 
GeneralRe: using C# code in VC++(MFC) application Pin
Shailesh Ha12-Jun-06 21:31
Shailesh Ha12-Jun-06 21:31 
AnswerRe: using C# code in VC++(MFC) application Pin
Koushik Biswas8-Jun-06 8:04
Koushik Biswas8-Jun-06 8:04 
GeneralRe: using C# code in VC++(MFC) application Pin
Shailesh Ha9-Jun-06 2:06
Shailesh Ha9-Jun-06 2:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.