Groups | Blog | Home
all groups > dotnet general > november 2003 >

dotnet general : Windows Service Path for referenced dll


hakan_dont_spam_me NO[at]SPAM go_away_spam_home.se
11/10/2003 11:22:26 PM
Hi,
I have a Windows Service that uses a referenced dotnet-dll.
In my dll I set some public string to a stringvalue that I=20
get from reading a xml-file(my config file). It works fine=20
if I use it in a vb-form. But since Windows Services ?
executes? in windows\system32 I can=B4t locate my xml-config-
file.

I don=B4t want to set different "compiling-statements" such=20
as :=20
#IF CONFIG =3D "service2" then=20
xmlPath =3D "c:\kklk\service2"
#ELSEIF CONFIG=3D"service3" then=20
xmlPath =3D "c:\kklk\service3"
#END IF

I want to return the location of the directory where my=20
service is. Not the "running" location of the service=20
("windows\system32"). Everything I try returns=20
c:\windows\system32

Is there some way of doing the following??
--- myClass.dll

Public ReadOnly strPathName As String =3D GetPath("path1")

Private Function GetPath(ByVal strValue As String) As=20
String
=20
Dim oConf As New mmmmXML.XMLConfigurator
(Environment.CurrentDirectory().ToString=20
& "/XMLConfigurator.xml") '<=3D=3D get the directory of where=20
the dll and service-code resides. This doesn=B4t work

Dim strPath As String
strPath =3D oConf.GetXPathValue("/mmmmCONFIG/mmmmPATH
[@name=3D'" & strValue & "']/@path")
Return strPath
End Function
--------------------

hmmm.. hope someone will understand my problem

//hakan
hakan_dont_spam_me NO[at]SPAM go_away_spam_home.se
11/11/2003 12:51:21 AM
Thanks for your reply Jos=E9,

my problem is that I don=B4t want to configure my service. I=20
want to configure my referenced dll. In other words. I=20
want my service + referenced dll=B4s to know that they are=20
executed in the MyService.exe=B4s directory.
MyService
MyServiceCode
ReferenceToDotNetDll
Dll reads xml-file and set values. XML-file placed in
same directory as the MyService.exe

Is this what you have explained to me? In that case can=20
you please post som more detailed codesnippets?

//hakan

[quoted text, click to view]
hakan_dont_spam_me NO[at]SPAM go_away_spam_home.se
11/11/2003 2:08:13 AM
Hmm, my reply didn=B4t make it :(

Thanks for your reply Jos=E9,

My problem is that I want use my own read-config-from-a-
xml-file-function that resides in the dll. In other words:=20
I want my referenced dotnet-dll to "understand" that the=20
working-directory is NOT c:\windows\system32, instead the=20
directory where the MyService.exe resides. My structure of=20
MyService:

-MyService
--Referenced DotNet-dll
---dll read xml-file and sets different public variables.=20

All files (xml,dll,Myservice.exe) is in the same directory.

Is this what your tried to explain to me? If so, can you=20
please provide me with some more detailed code-snippets.

thanx


//hakan




[quoted text, click to view]
José Joye
11/11/2003 8:45:45 AM
You can define the working directory of your Service in the OnStart() method
by doing the following:

// Prepare our remoting server by reading configuration in the config file.

RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.Con
figurationFile);





[quoted text, click to view]
Hi,
I have a Windows Service that uses a referenced dotnet-dll.
In my dll I set some public string to a stringvalue that I
get from reading a xml-file(my config file). It works fine
if I use it in a vb-form. But since Windows Services ?
executes? in windows\system32 I can´t locate my xml-config-
file.

I don´t want to set different "compiling-statements" such
as :
#IF CONFIG = "service2" then
xmlPath = "c:\kklk\service2"
#ELSEIF CONFIG="service3" then
xmlPath = "c:\kklk\service3"
#END IF

I want to return the location of the directory where my
service is. Not the "running" location of the service
("windows\system32"). Everything I try returns
c:\windows\system32

Is there some way of doing the following??
--- myClass.dll

Public ReadOnly strPathName As String = GetPath("path1")

Private Function GetPath(ByVal strValue As String) As
String

Dim oConf As New mmmmXML.XMLConfigurator
(Environment.CurrentDirectory().ToString
& "/XMLConfigurator.xml") '<== get the directory of where
the dll and service-code resides. This doesn´t work

Dim strPath As String
strPath = oConf.GetXPathValue("/mmmmCONFIG/mmmmPATH
[@name='" & strValue & "']/@path")
Return strPath
End Function
--------------------

hmmm.. hope someone will understand my problem

//hakan

José Joye
11/11/2003 10:08:00 AM
Ooooops,
I gave you a wrong snippet .....

Place right at the top of your OnStart() method of your Service main the
following code:

// Define working directory (For a service, this is set to System dir by
default...)
Process pc = Process.GetCurrentProcess();
Directory.SetCurrentDirectory
(pc.MainModule.FileName.Substring(0,pc.MainModule.FileName.LastIndexOf(@"\")
));


This will define the working directory of your service as being the location
where the exe file of the Service is stored.
This assume that the dll launched are in the same directory or known by the
normal ". NET probing".

Just try to place the snippet code I gave you to your OnStart()... and let
me know.

José
[quoted text, click to view]
Thanks for your reply José,

my problem is that I don´t want to configure my service. I
want to configure my referenced dll. In other words. I
want my service + referenced dll´s to know that they are
executed in the MyService.exe´s directory.
MyService
MyServiceCode
ReferenceToDotNetDll
Dll reads xml-file and set values. XML-file placed in
same directory as the MyService.exe

Is this what you have explained to me? In that case can
you please post som more detailed codesnippets?

//hakan

[quoted text, click to view]

José Joye
11/11/2003 2:01:13 PM
Refer to my second post.

José
[quoted text, click to view]
Hmm, my reply didn´t make it :(

Thanks for your reply José,

My problem is that I want use my own read-config-from-a-
xml-file-function that resides in the dll. In other words:
I want my referenced dotnet-dll to "understand" that the
working-directory is NOT c:\windows\system32, instead the
directory where the MyService.exe resides. My structure of
MyService:

-MyService
--Referenced DotNet-dll
---dll read xml-file and sets different public variables.

All files (xml,dll,Myservice.exe) is in the same directory.

Is this what your tried to explain to me? If so, can you
please provide me with some more detailed code-snippets.

thanx


//hakan




[quoted text, click to view]

AddThis Social Bookmark Button