Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Wed, 8 Jun 2005 11:01:28 +0100,    group: microsoft.public.dotnet.myservices        back       


DllImport and Windows Services   
(Note follow-up set to microsoft.public.dotnet.myservices only)

We have a client-server environment where clients request services from the
server via a C/C++ DLL (it is *not* COM based). The DLL has been used by
many application including C++ and VB over many years.

I tried to make use of this DLL in a .Net C# application by making use of
DllImport as follows:

[ DllImport("CodaLink.dll", EntryPoint="LinkEncrypt",
CharSet=CharSet.Ansi) ]
private static extern int LinkEncrypt([Out] StringBuilder Output, string
Input, string UserID);

I encapsulated these types of calls in a .Net DLL assembly, created a sample
..Net Console application that uses the DLL, and that ran fine.

I then tried to create a .Net Windows Services and installed it using the
same security context as the Console application but it is failing. I think
it if failing to establish a connection to the server. I have made sure that
both the Windows Service EXE and the .Net DLL Assembly are in the same
directory and I've also included the containing directory into the system
PATH. From the service I write the PATH to the EventLog and it does contain
the containing folder as expected.

The Windows Service appears to be making some calls to the DLL but I do not
understand why the DLL works from a Console app but not in a Windows
Service.

Please help?
date: Wed, 8 Jun 2005 11:01:28 +0100   author:   Tushar

Re: DllImport and Windows Services   
Services and Console applications never run in the same user context!
One of the differences is that Services don't load an "interactive user 
profile" (HKCU registry hive) , instead, they fall back to the "default" 
profile.
I guess your LinkEncrypt function relies on the presense of HKCU to find 
it's keystore. So in one word the DLL is not designed to be used from a 
Service. One option is to create a logon session (call Win32 LogonUser()) 
and load the profile (LoadUserProfile()) of an interactive user.

Willy.

"Tushar"  wrote in message 
news:uo6O2CBbFHA.724@TK2MSFTNGP12.phx.gbl...
> (Note follow-up set to microsoft.public.dotnet.myservices only)
>
> We have a client-server environment where clients request services from 
> the
> server via a C/C++ DLL (it is *not* COM based). The DLL has been used by
> many application including C++ and VB over many years.
>
> I tried to make use of this DLL in a .Net C# application by making use of
> DllImport as follows:
>
> [ DllImport("CodaLink.dll", EntryPoint="LinkEncrypt",
> CharSet=CharSet.Ansi) ]
> private static extern int LinkEncrypt([Out] StringBuilder Output, string
> Input, string UserID);
>
> I encapsulated these types of calls in a .Net DLL assembly, created a 
> sample
> .Net Console application that uses the DLL, and that ran fine.
>
> I then tried to create a .Net Windows Services and installed it using the
> same security context as the Console application but it is failing. I 
> think
> it if failing to establish a connection to the server. I have made sure 
> that
> both the Windows Service EXE and the .Net DLL Assembly are in the same
> directory and I've also included the containing directory into the system
> PATH. From the service I write the PATH to the EventLog and it does 
> contain
> the containing folder as expected.
>
> The Windows Service appears to be making some calls to the DLL but I do 
> not
> understand why the DLL works from a Console app but not in a Windows
> Service.
>
> Please help?
>
>
date: Wed, 8 Jun 2005 12:17:26 +0200   author:   Willy Denoyette [MVP]

Re: DllImport and Windows Services   
Thank you for the reply.

The service installer is set to "User" and it prompts me for UID/PWD during
InstallUtil. In the services applet the LogOnAs column contains my account
for the servcie (because that is what I used.) Does this not mean that the
service runs in my user context?

As a test I changed the registry HKCU with invalid server settings and the
servcie came up with a different error. When I put the settings to correct
values it is coming up with a different error which proves that it is
reading HKCU.

I also performed another test: I set the PATH for my accout (not system) to
zzz. In command prompt this appends my PATH to my system PATH. In the
service I dump the path the the EventLog that does include my local path.

I therefore conlcude that the service is running in my user context.

Please help.


"Willy Denoyette [MVP]"  wrote in message
news:ud7%23GNBbFHA.3280@TK2MSFTNGP09.phx.gbl...
Services and Console applications never run in the same user context!
One of the differences is that Services don't load an "interactive user
profile" (HKCU registry hive) , instead, they fall back to the "default"
profile.
I guess your LinkEncrypt function relies on the presense of HKCU to find
it's keystore. So in one word the DLL is not designed to be used from a
Service. One option is to create a logon session (call Win32 LogonUser())
and load the profile (LoadUserProfile()) of an interactive user.

Willy.

"Tushar"  wrote in message
news:uo6O2CBbFHA.724@TK2MSFTNGP12.phx.gbl...
> (Note follow-up set to microsoft.public.dotnet.myservices only)
>
> We have a client-server environment where clients request services from
> the
> server via a C/C++ DLL (it is *not* COM based). The DLL has been used by
> many application including C++ and VB over many years.
>
> I tried to make use of this DLL in a .Net C# application by making use of
> DllImport as follows:
>
> [ DllImport("CodaLink.dll", EntryPoint="LinkEncrypt",
> CharSet=CharSet.Ansi) ]
> private static extern int LinkEncrypt([Out] StringBuilder Output, string
> Input, string UserID);
>
> I encapsulated these types of calls in a .Net DLL assembly, created a
> sample
> .Net Console application that uses the DLL, and that ran fine.
>
> I then tried to create a .Net Windows Services and installed it using the
> same security context as the Console application but it is failing. I
> think
> it if failing to establish a connection to the server. I have made sure
> that
> both the Windows Service EXE and the .Net DLL Assembly are in the same
> directory and I've also included the containing directory into the system
> PATH. From the service I write the PATH to the EventLog and it does
> contain
> the containing folder as expected.
>
> The Windows Service appears to be making some calls to the DLL but I do
> not
> understand why the DLL works from a Console app but not in a Windows
> Service.
>
> Please help?
>
>
date: Wed, 8 Jun 2005 12:14:44 +0100   author:   Tushar

Re: DllImport and Windows Services   
It's most definitely a permissions issue.
Is the DLL trying to access a "protected" resource... or something via a UNC 
path (off the box)?
You may want to change the account under which the service is running.
-Gene
"Tushar"  wrote in message 
news:uo6O2CBbFHA.724@TK2MSFTNGP12.phx.gbl...
> (Note follow-up set to microsoft.public.dotnet.myservices only)
>
> We have a client-server environment where clients request services from 
> the
> server via a C/C++ DLL (it is *not* COM based). The DLL has been used by
> many application including C++ and VB over many years.
>
> I tried to make use of this DLL in a .Net C# application by making use of
> DllImport as follows:
>
> [ DllImport("CodaLink.dll", EntryPoint="LinkEncrypt",
> CharSet=CharSet.Ansi) ]
> private static extern int LinkEncrypt([Out] StringBuilder Output, string
> Input, string UserID);
>
> I encapsulated these types of calls in a .Net DLL assembly, created a 
> sample
> .Net Console application that uses the DLL, and that ran fine.
>
> I then tried to create a .Net Windows Services and installed it using the
> same security context as the Console application but it is failing. I 
> think
> it if failing to establish a connection to the server. I have made sure 
> that
> both the Windows Service EXE and the .Net DLL Assembly are in the same
> directory and I've also included the containing directory into the system
> PATH. From the service I write the PATH to the EventLog and it does 
> contain
> the containing folder as expected.
>
> The Windows Service appears to be making some calls to the DLL but I do 
> not
> understand why the DLL works from a Console app but not in a Windows
> Service.
>
> Please help?
>
>
date: Wed, 8 Jun 2005 17:16:00 -0400   author:   Gene

Re: DllImport and Windows Services   
Are you admin of your computer?
It could be that the service has less right than you and Interop requires a 
high level of trust

"Tushar"  wrote in message 
news:uo6O2CBbFHA.724@TK2MSFTNGP12.phx.gbl...
> (Note follow-up set to microsoft.public.dotnet.myservices only)
>
> We have a client-server environment where clients request services from 
> the
> server via a C/C++ DLL (it is *not* COM based). The DLL has been used by
> many application including C++ and VB over many years.
>
> I tried to make use of this DLL in a .Net C# application by making use of
> DllImport as follows:
>
> [ DllImport("CodaLink.dll", EntryPoint="LinkEncrypt",
> CharSet=CharSet.Ansi) ]
> private static extern int LinkEncrypt([Out] StringBuilder Output, string
> Input, string UserID);
>
> I encapsulated these types of calls in a .Net DLL assembly, created a 
> sample
> .Net Console application that uses the DLL, and that ran fine.
>
> I then tried to create a .Net Windows Services and installed it using the
> same security context as the Console application but it is failing. I 
> think
> it if failing to establish a connection to the server. I have made sure 
> that
> both the Windows Service EXE and the .Net DLL Assembly are in the same
> directory and I've also included the containing directory into the system
> PATH. From the service I write the PATH to the EventLog and it does 
> contain
> the containing folder as expected.
>
> The Windows Service appears to be making some calls to the DLL but I do 
> not
> understand why the DLL works from a Console app but not in a Windows
> Service.
>
> Please help?
>
>
date: Thu, 9 Jun 2005 09:09:41 +1000   author:   Lloyd Dupont net.galador@ld

Re: DllImport and Windows Services   
Yes I think that is the case however I've solved the problem another way
(but is not elegant).

I am trying to make contact the people to wrote the original API that the
service is calling. I am being told that that API is trying to access some
COM component and requires access to some registry setting that is not
available to Windows Services. They tell me that I should call the API from
an application instead as opposed to Windows Service.

I therefore tried to ShellExecute another test EXE from the Windows Service
and that EXE would be running (one would assume) in the same context as the
service itself but (surprise, surprise) the application works.

Even if this has solved my problem, I do not understand why? Why does a
service run in a different context to the application that the same service
is calling?

*** Pleeeeeeeeease help!!!!!!!!!! ***



"Lloyd Dupont" <net.galador@ld> wrote in message
news:OyElt8HbFHA.2128@TK2MSFTNGP14.phx.gbl...
Are you admin of your computer?
It could be that the service has less right than you and Interop requires a
high level of trust

"Tushar"  wrote in message
news:uo6O2CBbFHA.724@TK2MSFTNGP12.phx.gbl...
> (Note follow-up set to microsoft.public.dotnet.myservices only)
>
> We have a client-server environment where clients request services from
> the
> server via a C/C++ DLL (it is *not* COM based). The DLL has been used by
> many application including C++ and VB over many years.
>
> I tried to make use of this DLL in a .Net C# application by making use of
> DllImport as follows:
>
> [ DllImport("CodaLink.dll", EntryPoint="LinkEncrypt",
> CharSet=CharSet.Ansi) ]
> private static extern int LinkEncrypt([Out] StringBuilder Output, string
> Input, string UserID);
>
> I encapsulated these types of calls in a .Net DLL assembly, created a
> sample
> .Net Console application that uses the DLL, and that ran fine.
>
> I then tried to create a .Net Windows Services and installed it using the
> same security context as the Console application but it is failing. I
> think
> it if failing to establish a connection to the server. I have made sure
> that
> both the Windows Service EXE and the .Net DLL Assembly are in the same
> directory and I've also included the containing directory into the system
> PATH. From the service I write the PATH to the EventLog and it does
> contain
> the containing folder as expected.
>
> The Windows Service appears to be making some calls to the DLL but I do
> not
> understand why the DLL works from a Console app but not in a Windows
> Service.
>
> Please help?
>
>
date: Thu, 9 Jun 2005 12:47:09 +0100   author:   Tushar

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us