I'm running the following through a remote PHP script that connects to SSH:
cmd /C start "" /MAX /b "C:\Windows\System32\notepad.exe"
The process does start however it remains in the background and will not open fully on the remote desktop. Is there any way to get it to work interactively (like how PSExec has the -i flag)?
Edit:
So the PHP connects to SSH with ssh2_connect
then uses ssh2_exec
in the following manner:
if (!($stream = ssh2_exec($con, $shcom ))) {
where $shcom
is the command passed to the SSH, such as:
$shcom = 'cmd.exe /C start "" /MAX "%SystemRoot%\System32\calc.exe"';
I have previously used PSExec and PuTTY (note not via the PHP script) to manually open notepad.exe on a remote machine via the following:
cd "C:\Program Files\PSExec\" & psexec \\localhost -i 2 -ds "C:\Windows\System32\notepad.exe"
which did successfully work however this also does not properly function via PHP. At present neither CMD nor PSExec can bring up an interactive application in the foreground automatically.
Open a command prompt window and run first cmd /?
and second start /?
and read both times the output help.
cmd /C
starts a new Windows command process which is closed automatically because of /C
when additionally applied command to execute in the command process terminated.
The command start "" /MAX /B
starts one more command process with an empty string as window title and starting in this command process the GUI application Windows Notepad which should be started with a maximized window because of /MAX
but which should run in background (= without visible window) because of /b
.
So the mistake is using /b
as really wanted is starting Notepad in foreground with maximized window instead of in background with no window.
And Windows must not be installed inevitably on drive C: in a directory named Windows
. Therefore it is better to use one of those two commands:
cmd.exe /C start "" /MAX "%SystemRoot%\System32\notepad.exe"
cmd.exe /C start "" /MAX "%windir%\System32\notepad.exe"
The environment variable windir
is an environment variable existing by default since Windows 95 with the path to the directory of running Windows.
The environment variable SystemRoot
is an environment variable predefined by all Windows versions based on Windows NT with path to Windows directory.
Nowadays it is better to use SystemRoot
as this environment variable is Windows built-in while windir
is just predefined in the system environment variables list and therefore could be also removed.
See Wikipedia article about Windows Environment Variables for a list of predefined environment variables with description.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With