[Klone-users] Windows service : change and know the execution path

Stefano Barbato barbato at koanlogic.com
Thu Nov 26 05:51:33 EST 2009


Hello Mickael,

if KLone has been started by the Service Manager the ctx->hServiceStatus will be set:

--------------------------------------------------
#include <klone/context.h>
if(ctx->hServiceStatus)
	; /* service mode */
else
	; /* application mode */
--------------------------------------------------


Also "GetModuleFileName(GetModuleHandle(NULL), buffer, bufsz)" should return the full path of the kloned executable; I'm not 100% sure that it works properly in service mode but it's worth a try :)

bye,
stefano


On 26/nov/2009, at 11.30, Mickael Auger wrote:

> Hi,
> 
> I agree with you.
> 
> For my issue, I don't know in advance the installation directory (it's a customer choice), so I cannot use the "chroot" key in internal kloned.conf and I want not use an external (visible/editable) kloned.conf.
> 
> When kloned is launched, the execution directory is either the installation directory (in application mode) or fixed by Windows (in service mode).
> So in the service mode, I must call SetCurrentDirectory() with the value of ImagePath key that I determine myself (without touch source code of kloned).
> 
> I want just know if kloned.exe is launched in application mode or service mode (as global boolean flag).
> 
> Greetings.
> 
> 2009/11/26 Steven Dorigotti <dorigotti at koanlogic.com>
> Dear Mickaël,
> 
>  what you are suggesting, to detect whether KLone is running in
> service mode or not, is definitely feasible but shouldn't be necessary
> for transparency. It's not usually the responsibility of an
> application to know how it was launched, rather such job could be done
> by a higher installation layer. It would also require more
> windows-specific code.
> 
>  If you set a fixed chroot path in the configuration file and let
> KLone change directory for you as with our last patch you have a
> generic solution for knowing where KLone is being executed which works
> under all environments.
> 
>  Or is your issue still out of sight?
> 
> let us know,
> sd
> 
> 2009/11/26 Mickael Auger <mickael.auger at gmail.com>:
> > Hi,
> >
> > thank you for your patch.
> >
> > Hovewer, in Windows service mode I will search the
> > "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\kloned\ImagePath" key in
> > Windows registry to know the kloned.exe installation directory and call
> > SetCurrentDirectory to it in "server_init" hook.
> >
> > So, I would like know the kloned execution mode (application or service).
> > Have you a solution to distinct this execution mode (kloned launched with
> > WinMain() or ServiceMain() functions in entry.c) ?
> >
> > Bye.
> >
> > 2009/11/25 Steven Dorigotti <dorigotti at koanlogic.com>
> >>
> >> Hi!
> >>
> >>  Ok, your problem is more clear to us now.
> >>
> >>  Please try the attached patch (using KLONE_TARGET_PATCH_FILE for
> >> local build or KLONE_HOST_PATCH_FILE for cross-compilation) and setup
> >> your base path in the kloned configuration file as follows:
> >>
> >>  chroot    c:/your/base/dir
> >>
> >>  The server will then do the SetCurrentDirectory() on MinGW as you
> >> suggested.
> >>
> >> cheers,
> >> sd
> >>
> >>
> >> 2009/11/25 Mickael Auger <mickael.auger at gmail.com>:
> >> > Hi Steven,
> >> >
> >> > thank you for response but it's my question (sorry :(  ).
> >> > For example, I have an installation folder "C:\ProgramFiles\KLoneApp"
> >> > what
> >> > contains :
> >> > - kloned.exe
> >> > - config.ini (this file will be modify by another application)
> >> >
> >> > If I launch "kloned.exe" as standard application in MS-DOS console, the
> >> > execution folder is "C:\ProgramFiles\KLoneApp".
> >> > But if I install kloned as a Windows service and I launch "kloned.exe"
> >> > with
> >> > "net start kloned" command line, the execution folder is
> >> > "C:\windows\system32".
> >> >
> >> > To read my "config.ini" file, I have this index.klx.
> >> >
> >> > ================================
> >> > <html>
> >> > <body>
> >> > <%
> >> > FILE *file;
> >> > file = fopen("config.ini","r); //local file in
> >> > "C:\ProgramFiles\KLoneApp"
> >> > if(file)
> >> > {
> >> >   ...
> >> >   fclose(file);
> >> > }
> >> > %>
> >> > </body>
> >> > </html>
> >> > ================================
> >> >
> >> > I would be known this installation directory which contains "kloned.exe"
> >> > to
> >> > change the execution path by calling SetCurrentDirectory() Windows
> >> > function.
> >> > This installation directory is stored in Windows registry (in ImagePath
> >> > key).
> >> >
> >> > This way, my KLone application could be execute regardless of standard
> >> > application or service mode.
> >> >
> >> > Can you have a function (or a solution) to know this installation
> >> > directory,
> >> > please ?
> >> >
> >> > 2009/11/25 Steven Dorigotti <dorigotti at koanlogic.com>
> >> >>
> >> >> Hi Mickaël,
> >> >>
> >> >>  so you managed to cross-compile or in this case did you also compile
> >> >> on
> >> >> win?
> >> >>
> >> >>  The win service should point to the directory from which you ran
> >> >> "kloned -i", so that should be your reference executable.
> >> >>
> >> >>  In order to access content on your local file system you need to
> >> >> make sure the sup fs was setup correcly upon build, so:
> >> >>
> >> >> KLONE_CONF_ARGS += --enable_fs
> >> >>
> >> >>  and make sure the document root is setup correctly in your
> >> >> configuration
> >> >> file:
> >> >>
> >> >> dir_root        /path/to/dir/www
> >> >>
> >> >>  where the path should be relative to the msys installation  (in this
> >> >> case for example c:\msys\1.0\path\to\dir\www)
> >> >>
> >> >>  Have you already done these steps and still have trouble?
> >> >>
> >> >> bye,
> >> >> Steven
> >> >>
> >> >>
> >> >> 2009/11/24 Mickael Auger <mickael.auger at gmail.com>:
> >> >> > Hi,
> >> >> >
> >> >> > I compile and execute KLone as a Windows service, but I need to two
> >> >> > informations.
> >> >> >
> >> >> > How can I know and / or change the run directory of kloned ?
> >> >> >
> >> >> > How can I know the folder containing the kloned binary ?
> >> >> >
> >> >> > Know this folders could me to manage a lot of personal file provided
> >> >> > with
> >> >> > kloned binary (in the install folder).
> >> >> >
> >> >> > Bye.
> >> >> > --
> >> >> > Mickaël AUGER
> >> >> >
> >> >> >
> >> >> > _______________________________________________
> >> >> > Klone-users mailing list
> >> >> > Klone-users at koanlogic.com
> >> >> > http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
> >> >> >
> >> >> >
> >> >>
> >> >> _______________________________________________
> >> >> Klone-users mailing list
> >> >> Klone-users at koanlogic.com
> >> >> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
> >> >
> >> >
> >> >
> >> > --
> >> > Mickaël AUGER
> >> >
> >> >
> >> > _______________________________________________
> >> > Klone-users mailing list
> >> > Klone-users at koanlogic.com
> >> > http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
> >> >
> >> >
> >>
> >> _______________________________________________
> >> Klone-users mailing list
> >> Klone-users at koanlogic.com
> >> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
> >>
> >
> >
> >
> > --
> > Mickaël AUGER
> >
> >
> > _______________________________________________
> > Klone-users mailing list
> > Klone-users at koanlogic.com
> > http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
> >
> >
> 
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
> 
> 
> 
> -- 
> Mickaël AUGER
> 
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users





More information about the klone-users mailing list