473,395 Members | 1,639 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,395 software developers and data experts.

how obtain the exe path of a window service file?

Hi,

i created a windows service. This service is installed in some c:\program
files\x directory
when started it needs the directory in which it is started.

when i use the system.environment.currentdirectory i get the
C:\WINNT\SYSTEM32 in stead of the
c:\program files\x.

i think the windows service is started by another program out of the
system32 dir.
Is there a (simple) way to get the c:\program files\x direcotry where the
executable is located.

thanks.

Nov 20 '05 #1
6 9968
In short, use:

System.Reflection.Assembly.GetEntryAssembly.Locati on

See my post "Re: AppPath() Replacement" for more information

Hope this helps,

Trev.
"Willie wjb" <wj****@nomail.nl> wrote in message
news:uu*************@TK2MSFTNGP11.phx.gbl...
Hi,

i created a windows service. This service is installed in some c:\program
files\x directory
when started it needs the directory in which it is started.

when i use the system.environment.currentdirectory i get the
C:\WINNT\SYSTEM32 in stead of the
c:\program files\x.

i think the windows service is started by another program out of the
system32 dir.
Is there a (simple) way to get the c:\program files\x direcotry where the
executable is located.

thanks.

Nov 20 '05 #2
You're absolutely right! Your service is started by the
system service manager.

Try using System.IO.Directory.GetCurrentDirectory, this
should return your applications working directory and not
C:\WINNT\SYSTEM32.

-Fabricio
-----Original Message-----
Hi,

i created a windows service. This service is installed in some c:\programfiles\x directory
when started it needs the directory in which it is started.
when i use the system.environment.currentdirectory i get theC:\WINNT\SYSTEM32 in stead of the
c:\program files\x.

i think the windows service is started by another program out of thesystem32 dir.
Is there a (simple) way to get the c:\program files\x direcotry where theexecutable is located.

thanks.

.

Nov 20 '05 #3
m
> Try using System.IO.Directory.GetCurrentDirectory, this
should return your applications working directory and not
C:\WINNT\SYSTEM32.
Nope, Sorry. It does the same as Environment.CurrentDirectory. Try starting
an app from a shortcut that has its "Start In" property set to some other
directory.

If you look at the IL using IL DSM, you'll see that
Environment.CurrentDirectory actually calls System.IO.GetCurrentDirectory.

Use System.Reflection.Assembly.GetEntryAssembly.Locati on to get the full
path (including filename) of the directory.

Hope this helps,

Trev.

"Fabricio" <fg*************@yahoo.com> wrote in message
news:0a****************************@phx.gbl... You're absolutely right! Your service is started by the
system service manager.

Try using System.IO.Directory.GetCurrentDirectory, this
should return your applications working directory and not
C:\WINNT\SYSTEM32.

-Fabricio
-----Original Message-----
Hi,

i created a windows service. This service is installed in

some c:\program
files\x directory
when started it needs the directory in which it is

started.

when i use the system.environment.currentdirectory i get

the
C:\WINNT\SYSTEM32 in stead of the
c:\program files\x.

i think the windows service is started by another program

out of the
system32 dir.
Is there a (simple) way to get the c:\program files\x

direcotry where the
executable is located.

thanks.

.

Nov 20 '05 #4
* "Willie wjb" <wj****@nomail.nl> scripsit:
i created a windows service. This service is installed in some c:\program
files\x directory
when started it needs the directory in which it is started.

when i use the system.environment.currentdirectory i get the
C:\WINNT\SYSTEM32 in stead of the
c:\program files\x.

i think the windows service is started by another program out of the
system32 dir.
Is there a (simple) way to get the c:\program files\x direcotry where the
executable is located.


\\\
Imports System.IO
Imports System.Reflection
..
..
..
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
///

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

Cheers for the tip about the path object. I learn something new every day ;)
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
Don't forget that GetExecutingAssembly.Location returns the location of the
Assembly that is excuting (which could be a DLL in another location than the
main exe). IMHO, GetEntryAssembly.Location is a better bet.

Trev.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ec**************@tk2msftngp13.phx.gbl... * "Willie wjb" <wj****@nomail.nl> scripsit:
i created a windows service. This service is installed in some c:\program files\x directory
when started it needs the directory in which it is started.

when i use the system.environment.currentdirectory i get the
C:\WINNT\SYSTEM32 in stead of the
c:\program files\x.

i think the windows service is started by another program out of the
system32 dir.
Is there a (simple) way to get the c:\program files\x direcotry where the executable is located.


\\\
Imports System.IO
Imports System.Reflection
.
.
.
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)
End Function
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #6
this works fine!!!

thanks.

"Codemonkey" <hu*********@hotmail.com> wrote in message
news:O2**************@TK2MSFTNGP11.phx.gbl...
In short, use:

System.Reflection.Assembly.GetEntryAssembly.Locati on

See my post "Re: AppPath() Replacement" for more information

Hope this helps,

Trev.
"Willie wjb" <wj****@nomail.nl> wrote in message
news:uu*************@TK2MSFTNGP11.phx.gbl...
Hi,

i created a windows service. This service is installed in some c:\program files\x directory
when started it needs the directory in which it is started.

when i use the system.environment.currentdirectory i get the
C:\WINNT\SYSTEM32 in stead of the
c:\program files\x.

i think the windows service is started by another program out of the
system32 dir.
Is there a (simple) way to get the c:\program files\x direcotry where the executable is located.

thanks.


Nov 20 '05 #7

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

Similar topics

0
by: RiteshDotNet | last post by:
I have develop a window service in vb.net in window service, i am running executeing exe which is reside on same system its gives error while running that exe file I am pasting error below "...
0
by: praba kar | last post by:
Dear All, I am using Python 2.4 in the linux platform. At present I am working on webbased file manager. When I try to upload a file from the linux cgi script easily fetch the file name by the...
4
by: utkarsh | last post by:
Hi, I want to develop a Window Service in C# that should be capable of sisplaying the a icon in the window tray. Based on some logic in service, icon should be changed to some other...
3
by: Li Pang | last post by:
Hi, I wrote a window service in VB6, where I used a loop to continue check something. Now, I transfer it into vb.NET. I can setup service with a mis file, but when I start the service, it takes...
0
by: Wali Khan | last post by:
HI, I have developed a window service in VB.NET to connect to VSS and some operations are followed. Problem is i am unable to connect to VSS when i install the Service.When i m debugging as an...
3
by: Cylix | last post by:
I have create and finished a windows service project. I test and debug the project in my computer by just rebuild the file, and so the service is installed in my computer before. Now, I need to...
9
by: =?Utf-8?B?UG90c2FuZw==?= | last post by:
Hi, I have a window service program created in c#. The window service program is installed and running. In the mean time, I have another c# application, I would like to know if there is a way to...
0
by: henkya | last post by:
Language Used: C# Project Typed: Setup Project (for .NET Window Service) Hi Bump into this issue and seriously have a hunch that this is a bug in the .NET setup project. These are the scenario:...
8
by: Lemune | last post by:
Hi, I'm developing window service application on C# 2005. The service is to read a new excel file on certain directory, and process it to database. The service work find on XP. But when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.