Relative paths in Windows Service?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stevenson
    New Member
    • Mar 2010
    • 2

    Relative paths in Windows Service?

    Hello,

    I'm developing a C# application that will be used over a network. Eventually, I want to run it as a service so that the user does not see that the program is running.

    While converting a test application into a service I ran into the problem that the relative paths I defined in my code crash the service because it cannot find the files it is supposed to load.
    I tried Application.Exe cutablePath instead, but no luck, the service's ExecutablePath is system32, which is not where the files are.

    Does anyone know what to use instead? Or will I have to use absolute paths?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    problem that the relative paths I defined in my code crash
    Let's see what you've done and maybe someone can point you in the right direction

    Comment

    • stevenson
      New Member
      • Mar 2010
      • 2

      #3
      Nevermind, I found an old forum post where someone suggested Assembly.GetExe cutingAssembly and then work out the paths from there. The link is here: http://bytes.com/topic/c-sharp/answe...indows-service

      However, I've run into another problem. My service calls a method in another class that uses System.Windows. Forms, but when I compile the project, I get the error message "The namespace 'Windows' does not exist in 'System' (is there an assembly missing?)."
      The class with the System.Windows. Forms using statement needs Application.Sta rtupPath. I need to do something like this:

      String fileName = "blah.txt";
      String fullPath = Application.Sta rtupPath + fileName;

      Is there something like Application.Sta rtupPath that I can use in a Windows Service to get the path used to start the application?

      Comment

      Working...