5

When running an ISAPI application on IIS, if we call ParamStr(0) or Application.ExeName inside our ISAPI we will get the folder that IIS is installed (C:\windows...).

Is there any way of getting the folder path which contains my ISAPI instead of IIS's application folder?

Rafael Colucci
  • 6,018
  • 4
  • 52
  • 121
  • possible duplicate http://stackoverflow.com/questions/4041492/finding-out-the-physical-path-of-an-isapi-dll should I say exactly duplicate? – RBA Oct 17 '11 at 15:27

1 Answers1

6

Your ISAPI application is a library (DLL), therefore you can use this approach to get its folder:

ExtractFilePath(GetModuleName(HInstance))

Use ExtractFileDir() instead of ExtractFilePath() if you don't need the last backslash.

Rationale: According to Delphi docs,

Several variables declared in the System unit are of special interest to those programming libraries. ... During a library's lifetime, HInstance contains its instance handle.

Using GetModuleName() you get that DLL's file name. ParamStr(0), on the other hand, contains the name of the main EXE where this DLL has been loaded to.

haimg
  • 4,547
  • 35
  • 47
  • Yeah .. it seems to work, but I am getting some characters in the beginning of the path that was not supposed to be there, like `\\?\C:\inetpub\wwwroot\`. – Rafael Colucci Oct 17 '11 at 13:07
  • You can go ahead and use this path as is. It will work for all intents and purposes. You can also try to use ExpandFileName() and see if it changes the path to the more usual variant. – haimg Oct 17 '11 at 13:10