Windows Service Path for referenced dll

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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);





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
 
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
 
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é
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
-----Original Message-----
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);





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


.
 
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
 
Refer to my second post.

José
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
 
Back
Top