computing
  • 2

changing a batch files process name

  • 2

Hi,
I am trying to find a way to rename, or set
the name of the process of a batch file. By
default the process name is just cmd.exe. I
would like to change the name for easier
recognition. Any suggestions would be
helpful.
~Eric

The only way I can think of would be:

1. Start the script normally.
2. Copy cmd.exe to the current directory with the desired name.
3. Restart the script with the copied exexutable.

<untested>

@echo off
if not "%~1"=="iamsecond" (
    For %%a in (cmd.exe) do copy "%%~$path:a" "desiredname.exe"
    start /b "" "desiredname.exe" /c "%~0" iamsecond %*
    goto :eof
)
shift

rem the script goes here

del "desiredname.exe"

 

Thank you for your quick response. I don’t completely
understand what you want me to do. I tried a few different
things, but could not get the exe to run my code. the exe does
have its own process name though. also, it would be a lot easier
if it were possible to change the name in the batch file inside
itself.

There is no way to change the process name under batch script, in fact I’m not sure if it’s even possible at all….

I gave it a quick test and it works fine to start the script as another process for me. I think a variation of this quick hack may be the only option…..

I tweaked it a little so it will actually delete the copy of cmd.exe.

@echo off
if not "%~1"=="iamsecond" (
    For %%a in (cmd.exe) do copy "%%~$path:a" "desiredname.exe">nul
    start /b "" "desiredname.exe" /c "%~0" iamsecond %*
    goto :eof
)
shift

rem the script goes here
echo Hello! I'm running Under the process name "desiredname.exe"
echo The title is a lie!
pause
title It was lying! No More!
pause


start /b cmd /c del "desiredname.exe"
goto :eof

 

Share