4

I have a Python application that uses ConfigParser.ConfigParser() to access a configuration file. I have created a windows service of the Python application using py2exe. The problem that I have is that the service can only find the configuration file if I place it in windows/system32 folder. I would like to have the configuration file in the same folder where the service was installed. For example, after using py2exe I have the following folder:

c:/temp/dist/winservice.exe
c:/temp/dist/configfile.cfg

Then I do:

winservice.exe install

But the service does not look for the configfile.cfg in path: c:/temp/dist/ but in path: c:/windows/system32/

Is there any way to change that?

Thanks!

Andrew
  • 2,046
  • 1
  • 24
  • 37

1 Answers1

0

You can use Inspect module to get the name of the file in which this code object was created. So to get the path of the file you will use : inspect.currentframe().f_code.co_filename

So, to get a directory name where your winservice.exe is:

dirPath = os.path.dirname(inspect.currentframe().f_code.co_filename)

hope it helps

Aelius
  • 1,029
  • 11
  • 22
Alexander
  • 12,424
  • 5
  • 59
  • 76
  • Thanks for your answer @Alexander. I have already tried your suggestion and `dirPath` is empty. I am doing `configFile = os.path.join(os.path.dirname(dirPath),'config.cfg')` and configFile is equal to "config.cfg". The thing is that the service only find the file if I place it inside c:/windows/system32/ path. – Edmond Dantes Dec 19 '12 at 16:11