473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Windows Service Path for referenced dll

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

Jul 21 '05 #1
5 6721
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.CurrentD omain.SetupInformation.Con
figurationFile);

<hakan_dont_spam_me@go_away_spam_home.se> wrote in message
news:06****************************@phx.gbl...
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
Jul 21 '05 #2
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() methodby doing the following:

// Prepare our remoting server by reading configuration in the config file.
RemotingConfiguration.Configure (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

<hakan_dont_spam_me@go_away_spam_home.se> wrote in message
news:06****************************@phx.gbl...
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
.

Jul 21 '05 #3
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é
<hakan_dont_spam_me@go_away_spam_home.se> wrote in message
news:09****************************@phx.gbl...
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() methodby doing the following:

// Prepare our remoting server by reading configuration in the config file.
RemotingConfiguration.Configure (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

<hakan_dont_spam_me@go_away_spam_home.se> wrote in message
news:06****************************@phx.gbl...
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
.

Jul 21 '05 #4
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

-----Original Message-----
You can define the working directory of your Service in the OnStart() methodby doing the following:

// Prepare our remoting server by reading configuration in the config file.
RemotingConfiguration.Configure (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

<hakan_dont_spam_me@go_away_spam_home.se> wrote in message
news:06****************************@phx.gbl...
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
.

Jul 21 '05 #5
Refer to my second post.

José
<hakan_dont_spam_me@go_away_spam_home.se> wrote in message
news:04****************************@phx.gbl...
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

-----Original Message-----
You can define the working directory of your Service in the OnStart() methodby doing the following:

// Prepare our remoting server by reading configuration in the config file.
RemotingConfiguration.Configure (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

<hakan_dont_spam_me@go_away_spam_home.se> wrote in message
news:06****************************@phx.gbl...
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
.

Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Lovely Angel | last post by:
Dear Friends Hope you doing great. I have recently shifted to a webhost which is Using Windows 2003 and IIS 6. Now my application was working fine earlier but now I am facing this problem ...
6
by: Laszlo Zsolt Nagy | last post by:
Sorry, I realized that the import zlib was not executed from my (working) service. So here is the question: why can't I use zlib from a win32 service? Is there any way to make it working? ...
10
by: Ger | last post by:
I am having problems using VB.Net's Management base object on a machine hosting Windows Server 2003. I am trying to set file permissions from a Windows Service. These files may be loacted on a...
4
by: Jim | last post by:
I am writing a Windows Service in VB.Net, and right upfront I need to pass the path to my config.xml file to the constructor of the class which reads it. In the old days, App.Path & "\config.xml"...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
5
by: | last post by:
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...
0
by: Jason | last post by:
Ok, for the life of me, I just don't understand what's going on. I want to use remoting to send messages from a windows service to a windows form app, but I just can't get it to work. So, here's...
1
by: =?Utf-8?B?UGllcnJl?= | last post by:
Hello, I have an simle application that uses a referenced library of my own. It's been a year now that I have no problems until a few days. Here is the details of my problem: The library...
0
by: =?Utf-8?B?U2ltb25EZXY=?= | last post by:
Hi All I would like to install the same Windows Service project on the same server under different names, one for each customer. I have been able to do it but I would like an expert opinion as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.