473,698 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

App.Path equivalent in VB.Net Windows Service

Jim
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.xm l" would have done nicely. I have
tried using Reflection.Asse mbly.GetExecuti ngAssembly.Loca tion but this is
horrible! I can't use the easy Application.Pat h property because it is a
service not a Forms application.

Is there a simple way to do this, or does anyone have any less than simple
but working code which might give me a clue?

Regards

--Jim.
Nov 21 '05 #1
4 16992
Application.Sta rtupPath
"Jim" <no******@this. address> wrote in message
news:Bg******** ********@fe2.ne ws.blueyonder.c o.uk...
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.xm l" would have done nicely. I
have tried using Reflection.Asse mbly.GetExecuti ngAssembly.Loca tion but this
is horrible! I can't use the easy Application.Pat h property because it is a
service not a Forms application.

Is there a simple way to do this, or does anyone have any less than simple
but working code which might give me a clue?

Regards

--Jim.

Nov 21 '05 #2
Jim

"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com> wrote
in message news:eV******** ******@TK2MSFTN GP12.phx.gbl...
Application.Sta rtupPath
"Jim" <no******@this. address> wrote in message
news:Bg******** ********@fe2.ne ws.blueyonder.c o.uk...
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.xm l" would have done nicely. I
have tried using Reflection.Asse mbly.GetExecuti ngAssembly.Loca tion but
this is horrible! I can't use the easy Application.Pat h property because
it is a service not a Forms application.

Is there a simple way to do this, or does anyone have any less than
simple but working code which might give me a clue?

Regards

--Jim.

----- Original Message -----
From: "Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Sent: Friday, December 10, 2004 5:48 PM
Subject: Re: App.Path equivalent in VB.Net Windows Service

Application.Sta rtupPath
"Jim" <no******@this. address> wrote in message
news:Bg******** ********@fe2.ne ws.blueyonder.c o.uk...
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.xm l" would have done nicely. I
have tried using Reflection.Asse mbly.GetExecuti ngAssembly.Loca tion but
this is horrible! I can't use the easy Application.Pat h property because
it is a service not a Forms application.

Is there a simple way to do this, or does anyone have any less than
simple but working code which might give me a clue?

Regards

--Jim.



Application.Sta rtupPath doesn't work for a Service, only a Forms App (I
think, I can't make it go anyway). HOWEVER I have now found the answer:
System.AppDomai n.CurrentDomain .BaseDirectory( )Regards--Jim.
Nov 21 '05 #3
You are right, I read it too quickly... It's one of those days...

Chris
"Jim" <no******@this. address> wrote in message
news:l_******** *********@fe2.n ews.blueyonder. co.uk...

"Chris, Master of All Things Insignificant" <chris@No_Spam_ Please.com>
wrote in message news:eV******** ******@TK2MSFTN GP12.phx.gbl...
Application.Sta rtupPath
"Jim" <no******@this. address> wrote in message
news:Bg******** ********@fe2.ne ws.blueyonder.c o.uk...
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.xm l" would have done
nicely. I have tried using
Reflection.A ssembly.GetExec utingAssembly.L ocation but this is horrible! I
can't use the easy Application.Pat h property because it is a service not
a Forms application.

Is there a simple way to do this, or does anyone have any less than
simple but working code which might give me a clue?

Regards

--Jim.


----- Original Message -----
From: "Chris, Master of All Things Insignificant"
<chris@No_Spam_ Please.com>
Newsgroups: microsoft.publi c.dotnet.langua ges.vb
Sent: Friday, December 10, 2004 5:48 PM
Subject: Re: App.Path equivalent in VB.Net Windows Service

Application.Sta rtupPath
"Jim" <no******@this. address> wrote in message
news:Bg******** ********@fe2.ne ws.blueyonder.c o.uk...
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.xm l" would have done
nicely. I have tried using
Reflection.A ssembly.GetExec utingAssembly.L ocation but this is horrible! I
can't use the easy Application.Pat h property because it is a service not
a Forms application.

Is there a simple way to do this, or does anyone have any less than
simple but working code which might give me a clue?

Regards

--Jim.



Application.Sta rtupPath doesn't work for a Service, only a Forms App (I
think, I can't make it go anyway). HOWEVER I have now found the answer:
System.AppDomai n.CurrentDomain .BaseDirectory( )Regards--Jim.

Nov 21 '05 #4
"Jim" <no******@this. address> schrieb:
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.xm l" would have done nicely. I
have tried using Reflection.Asse mbly.GetExecuti ngAssembly.Loca tion but this
is horrible! I can't use the easy Application.Pat h property because it is a
service not a Forms application.


\\\
Imports System.IO
Imports System.Reflecti on
..
..
..
Private Function ApplicationPath () As String
Return _
Path.GetDirecto ryName([Assembly].GetEntryAssemb ly().Location)
End Function
///

BTW: Use 'System.IO.Path .Combine' to combine paths instead of using '&'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #5

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

Similar topics

5
6745
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 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 :
1
3277
by: bob | last post by:
I have created a simple Windows service in VB.Net which installs fine using InstallUtil.exe to install it to, for example "c:\test", or "c:\Windows\YellowBanana", but if I install it to "c:\Program Files\Test" it installs ok but will not start (no useful error message is given other than the usual annoying suggestion about having sufficient privileges). The problem only seems to happen with spaces, not long filenames. I have found a...
6
3423
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? >------------- >Python could not import the service's module > File "T:\Python\Projects\NamedConnector\Service.py", line 17, in ? > from Processor import * > File "c:\Python\Projects\NamedConnector\Processor.py", line 35, in ?
14
9372
by: Gianfranco | last post by:
Hi everybody, First of all, sorry for my english if it isn't perfect ;-p I have an error in an asp.net application. I have win2003 server, with iis 6. I'm developping with visual studio 2005, vb.net, framework 2 I'm trying to access some binary files stored in C: in server2003. if i
1
4887
by: Jody Gelowitz | last post by:
We are having an issue in that when trying to read a file that is on Server2 from Server1 (through our ASP.NET project), we receive the error: Access to the path "\\Server2\MyShare\MyFile.tif" is denied. Here is the server setup that we have: Dev - Development Computer on WinXP Pro SP2 (IIS5), VS2003 developing under .NET Framework 1.1 Server1 - Web Server on Win2003 Server (IIS6) Server2 - File Server on Win2003 Server
1
2726
by: Zachariah | last post by:
I created a Windows Service and part of its functionality is to move a PDF file from a location on the service's local drive stInPath (C:\PDF\) to a location on another server stOutPath (\\123.123.123.123\C\PDF\) with this line of code: fs.MoveFile(stInPath, stOutPath) For testing I've been using the same code in a windows Application form. When I run the Application Form the
3
2317
by: Vikas Kumar | last post by:
I have created a windows service that service downloads updated database after regular intervals till now i am setting path in app.config where it will download database and will use it from that location i want it to dynamically take path of folder where that service will get installed i don't have any idea abt remoting so pls help me by telling something more exact abt this
2
4405
by: Gregor Horvath | last post by:
Hi, I have a testservice.py (see below). I installed the Windows-Service successfully. (via commandlineoption install) The problem is that it runs only when it is in c:\windows\system32 or in the python path. I added the desired path (Y:\) to the PYTHONPATH environment variable for the system account and rebooted. When I start command line python and do a import testservice everything is fine.
12
3708
by: Anil Gupte | last post by:
I wrote my Windows Service first as a regular Windows Exe because it is easier to debug. In that I used AppDir = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\")) ' Where this application Excutable sits Now, when I am converting it to a Service, what path can I use? Or can I specify a path in the service to always use as a data path? I would prefer the former because I do not know the layout of...
0
9152
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9014
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8855
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7708
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.