I have a built a Windows Service program. It runs fine with one exception.
The service .exe resides in a folder on the server.
When the service is started, it knows the location of that file, and works correctly.
I need to write to a log file, so I set a path. I use. curdrv() and curdir() plus "\data\" to create the path.
So it should come back with F:\MLS12\Data\
However, with the service executing, it uses the following path:
Path: C:\WINDOWS\system32\Data\
How can I detect, within a windows service, the proper path ? If I hardcode the path, it works fine, but I can't do that because installs will be different at various locations.
Thanks.
Windows Service - finding path
- TimStone
- Posts: 2955
- Joined: Fri Oct 07, 2005 1:45 pm
- Location: Trabuco Canyon, CA USA
- Has thanked: 25 times
- Been thanked: 2 times
- Contact:
Windows Service - finding path
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Re: Windows Service - finding path
What do you get when you run
Code: Select all | Expand
FWLOG hb_Arg(0)
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
- TimStone
- Posts: 2955
- Joined: Fri Oct 07, 2005 1:45 pm
- Location: Trabuco Canyon, CA USA
- Has thanked: 25 times
- Been thanked: 2 times
- Contact:
Re: Windows Service - finding path
I showed what the service is doing. Although the app is in a different drive and directory, once it runs it is doing it in c:\windows\system32. That is what the app is getting as s response. It is reporting that in the output log
I need it to know where the data files are kept which is a subdirectory of where the .exe resides.
Sent from my iPhone using Tapatalk
I need it to know where the data files are kept which is a subdirectory of where the .exe resides.
Sent from my iPhone using Tapatalk
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Re: Windows Service - finding path
hi,
what about
https://github.com/Petewg/harbour-core/wiki/hb_D
what about
hb_DirBase() ➜ cDirName
returns the application's executable base directory (program statrtup directory).
https://github.com/Petewg/harbour-core/wiki/hb_D
greeting,
Jimmy
Jimmy
Re: Windows Service - finding path
Tim, try with this
Code: Select all | Expand
#include "fivewin.ch"
Function Main()
local oWnd
DEFINE WINDOW oWnd TITLE "Test" FROM 10, 10 TO 410, 710 PIXEL
ACTIVATE WINDOW oWnd ;
ON INIT ( MsgInfo( cFilePath( PathRunService( "AnyDesk" ) ) ) )
Return nil
//----------------------------------------------------------------------------//
//
//----------------------------------------------------------------------------//
Function PathRunService( tcName, lTerminate )
local oLocator
local oWMI
local oProcesses
local oProcess
local cPath := ""
DEFAULT lTerminate := .F.
oLocator := CREATEOBJECT( "WBEMScripting.SWBEMLocator" )
oWMI := oLocator:ConnectServer()
oWMI:Security_:ImpersonationLevel := 3
oProcesses = oWMI:ExecQuery([SELECT PathName FROM Win32_Service WHERE Name = '] + tcName + ['])
if oProcesses:Count > 0
for EACH oProcess in oProcesses
cPath := oProcess:PathName
if lTerminate
oProcess:Terminate(0)
endif
Next
endif
Return cPath
//----------------------------------------------------------------------------//
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
- TimStone
- Posts: 2955
- Joined: Fri Oct 07, 2005 1:45 pm
- Location: Trabuco Canyon, CA USA
- Has thanked: 25 times
- Been thanked: 2 times
- Contact:
Re: Windows Service - finding path
Thanks
I will try both on Sunday ... have to travel all day tomorrow.
I will try both on Sunday ... have to travel all day tomorrow.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
- TimStone
- Posts: 2955
- Joined: Fri Oct 07, 2005 1:45 pm
- Location: Trabuco Canyon, CA USA
- Has thanked: 25 times
- Been thanked: 2 times
- Contact:
Re: Windows Service - finding path
I would like to thank both of you for your helpful responses.
The easier solution, using hb_DirBase() actually does exactly what I need. The service, when installed by the Installer software, knows where the file resides. That is in the same Root folder where the data directory is installed. Since the service calls for the DirBase(), once it receives that info, it knows the relevant path to the data folder where the log file is located, and also the relevant data files are that the service application needs to process "in the background".
It is actually nice to be able to build a service with Harbour/FWH, and have it run in the background regardless of who logs into the server. This is my auto backup, and auto program updater, utility. This will work nicely now.
The easier solution, using hb_DirBase() actually does exactly what I need. The service, when installed by the Installer software, knows where the file resides. That is in the same Root folder where the data directory is installed. Since the service calls for the DirBase(), once it receives that info, it knows the relevant path to the data folder where the log file is located, and also the relevant data files are that the service application needs to process "in the background".
It is actually nice to be able to build a service with Harbour/FWH, and have it run in the background regardless of who logs into the server. This is my auto backup, and auto program updater, utility. This will work nicely now.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit