Hello guys,
I know this is too old topic and there is no robust solutions. I remember that it has been discussed here but haven't found any methods mentioning the similar way. Anyway I'd like to share some finding with you.
Googling one question that not having to do with the current topic I payed my attention on the link to this page
http://steve-jansen.github.io/guides/wi ... ricks.html. At the end of this article the author shortly discusses the way how to detect if some script is launched by double click in Explorer. I performed some tests and extended his solution.
Method coverage
-- double click in Explorer
-- direct launch of the script from "Start/Run..." menu
Code: Select all
@echo off
echo:%CMDCMDLINE%
echo:%COMSPEC%
echo:%CMDCMDLINE%|findstr /b /l /c:"%COMSPEC% /c" && (
echo:
echo:Explorer Launcher
echo:
pause
)
pause
When the script is launched via the "Start/Run..." menu or double clicking the script in Explorer, the beginning of the
%CMDCMDLINE% exactly matches the string
%COMSPEC% /c with the only space between the command and the option. The rest of the invoking string doesn't matter. Any other invocation of batch files have double space before the
/c option and could have double quotes surrounding the
cmd.exe.
Unfortunately there is no reliable way to determine the script execution from "Start/Run" menu in the forms as below, because
-- a user could put more than one spaces in the invoking string before
/c option
-- the full path to cmd.exe could be surrounded with double quotes
Code: Select all
cmd /c batchfile
fullpath\to\cmd.exe /c batchfile
%comspec% /c batchfile