Search code examples
perlwindows-servicescmdwin32-process

why does my cmd.exe process doesn't have the "title" property set when launched as a service through perl?


I'm making my Perl soft runing as a service on windows.

For this purpose I'm using the Win32::Daemon module to manipulate SCM (service configuration manager) and start/stop my service.

To launch my service, I use the system() perl command.

The command looks like:

START \"title\" /Dc:\\path\\to\\bat\\script\\dir\\ \"script.bat\"

When I launch this command directly from cmd.exe, the title of the process is well set.

When the command is launched through the service I start, the process has an empty title. Task manager says that the launched command is:

cmd /c ""C:\path\to\script.bat" "

Am I missing something?

note: I'm definitly trying to set a title to my service, because I didn't find a cleaner way to stop it than launching a "taskkill" command in the stop hook of the service, with the title name as a parameter (don't know how to catch the PID of the generated process)

Thanks.


Solution

  • I'm not 100% sure what your issue is, but the title command may help.

    When a cmd process starts in Windows, it gets a default widow title. The DOS "title" command can set the window title to whatever you like.

    The DOS "start" command is used to split (fork?) the command to a new window, which separates it from the calling DOS/cmd window (unless you use the correct start parameters to keep it in the same window). Part of the start command is the optional "title" parameter which sets the window title for you.

    But you mentioned running as a service... services don't generally have windows or GUIs, so I'm not sure why you're so interested in the window title.

    In the end, you can put

    title "The title of the window"
    

    in your batch script... or if you're in a Perl program, doing

    system "title \"Window title\"";
    

    will also work.