problem with relative paths inside windows service?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Julia

    problem with relative paths inside windows service?


    Hi,

    I have two application which 'evaluate'( New FileStream(path ....) relative
    path,
    when evaluating the path inside a window service it always return something
    like

    C:\\WINNT\SYSTE M32\MyPath

    While when evaluating it in a window application I get the correct path

    both run from the same folder!!

    Thanks.



  • Ranjan

    #2
    Re: problem with relative paths inside windows service?

    Julia,
    This is because a windows service does not run from the folder you have
    placed. The current directory for a Windows service is the
    C:\Windows\Syst em32.
    Try using exact paths if possible.
    --





    "Julia" <codewizard@012 .net.il> wrote in message
    news:#Szjo5hAFH A.3492@TK2MSFTN GP12.phx.gbl...[color=blue]
    >
    > Hi,
    >
    > I have two application which 'evaluate'( New FileStream(path ....) relative
    > path,
    > when evaluating the path inside a window service it always return[/color]
    something[color=blue]
    > like
    >
    > C:\\WINNT\SYSTE M32\MyPath
    >
    > While when evaluating it in a window application I get the correct path
    >
    > both run from the same folder!!
    >
    > Thanks.
    >
    >
    >[/color]


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: problem with relative paths inside windows service?

      Julia,

      If you want to get the path that the executing assembly is in, you
      should get either the executing assembly (through a call to the static
      GetExecutingAss embly method on the Assembly class) or the entry point (which
      is your executable, I believe, obtained through a call to the static
      GetEntryAssembl y method on the Assembly class).

      Once you have the Assembly instance, you can get the location through
      the Location property on the assembly. From there, you can use the methods
      on the Path class (in System.IO) to get the path of your files using a base
      and a relative path.

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Julia" <codewizard@012 .net.il> wrote in message
      news:%23Szjo5hA FHA.3492@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      >
      > Hi,
      >
      > I have two application which 'evaluate'( New FileStream(path ....) relative
      > path,
      > when evaluating the path inside a window service it always return
      > something
      > like
      >
      > C:\\WINNT\SYSTE M32\MyPath
      >
      > While when evaluating it in a window application I get the correct path
      >
      > both run from the same folder!!
      >
      > Thanks.
      >
      >
      >[/color]


      Comment

      • Julia

        #4
        Re: problem with relative paths inside windows service?

        Can I use the SetCurrentDirec tory to set the running directory AFTER the
        service was started
        so all my relative paths function will work either in windows service or
        window application?


        "Ranjan" <ranjan.listser v@gmail.com> wrote in message
        news:Oo%23PHBiA FHA.3492@TK2MSF TNGP12.phx.gbl. ..[color=blue]
        > Julia,
        > This is because a windows service does not run from the folder you have
        > placed. The current directory for a Windows service is the
        > C:\Windows\Syst em32.
        > Try using exact paths if possible.
        > --
        > http://dotnetjunkies.com/weblog/dotnut
        >
        >
        >
        >
        > "Julia" <codewizard@012 .net.il> wrote in message
        > news:#Szjo5hAFH A.3492@TK2MSFTN GP12.phx.gbl...[color=green]
        > >
        > > Hi,
        > >
        > > I have two application which 'evaluate'( New FileStream(path ....)[/color][/color]
        relative[color=blue][color=green]
        > > path,
        > > when evaluating the path inside a window service it always return[/color]
        > something[color=green]
        > > like
        > >
        > > C:\\WINNT\SYSTE M32\MyPath
        > >
        > > While when evaluating it in a window application I get the correct path
        > >
        > > both run from the same folder!!
        > >
        > > Thanks.
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Ranjan

          #5
          Re: problem with relative paths inside windows service?

          It will not work out I am afraid once the Service has started. I will try
          to research on this and find out. Thanks for giving me something to brood
          overnight

          Ranjan
          --





          "Julia" <codewizard@012 .net.il> wrote in message
          news:OiDH$hjAFH A.1564@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Can I use the SetCurrentDirec tory to set the running directory AFTER the
          > service was started
          > so all my relative paths function will work either in windows service or
          > window application?
          >
          >
          > "Ranjan" <ranjan.listser v@gmail.com> wrote in message
          > news:Oo%23PHBiA FHA.3492@TK2MSF TNGP12.phx.gbl. ..[color=green]
          > > Julia,
          > > This is because a windows service does not run from the folder you have
          > > placed. The current directory for a Windows service is the
          > > C:\Windows\Syst em32.
          > > Try using exact paths if possible.
          > > --
          > > http://dotnetjunkies.com/weblog/dotnut
          > >
          > >
          > >
          > >
          > > "Julia" <codewizard@012 .net.il> wrote in message
          > > news:#Szjo5hAFH A.3492@TK2MSFTN GP12.phx.gbl...[color=darkred]
          > > >
          > > > Hi,
          > > >
          > > > I have two application which 'evaluate'( New FileStream(path ....)[/color][/color]
          > relative[color=green][color=darkred]
          > > > path,
          > > > when evaluating the path inside a window service it always return[/color]
          > > something[color=darkred]
          > > > like
          > > >
          > > > C:\\WINNT\SYSTE M32\MyPath
          > > >
          > > > While when evaluating it in a window application I get the correct[/color][/color][/color]
          path[color=blue][color=green][color=darkred]
          > > >
          > > > both run from the same folder!!
          > > >
          > > > Thanks.
          > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          Working...