The beginning of CMD and the open interactive PSExec application in the foreground when using PHP to connect to SSH

I run the following through a remote PHP script that connects to SSH:

cmd /C start "" /MAX /b "C:\Windows\System32\notepad.exe" 

The process starts, however, it remains in the background and does not fully open on the remote desktop. Is there a way to make it work interactively (for example, how does PSExec have the -i flag)?

Edit:

So, PHP connects to SSH using ssh2_connect , and then uses ssh2_exec as follows:

  if (!($stream = ssh2_exec($con, $shcom ))) { 

where $shcom is the command passed to SSH, for example:

  $shcom = 'cmd.exe /C start "" /MAX "%SystemRoot%\System32\calc.exe"'; 

I previously used PSEXEC and putties (note not through a PHP script) to manually open notepad.exe on a remote computer using the following steps:

 cd "C:\Program Files\PSExec\" & psexec \\localhost -i 2 -ds "C:\Windows\System32\notepad.exe" 

which worked successfully, however it also does not work correctly through PHP. Currently, neither CMD nor PSExec can automatically open an interactive application in the foreground.

+5
source share
1 answer

Open a command prompt and run cmd /? First and second start /? and read both times using output help.

cmd /C starts a new Windows command process, which automatically closes due to /C when the optional command is executed at the end of the command process.

The start "" /MAX /B command starts another command process with an empty line as the window title and starts the Windows Notepad GUI process with this command, which should be started using the maximized window due to /MAX , but which should run in the background (= without a visible window) due to /b .

So the mistake is to use /b , since it really requires starting Notepad in the foreground with the maximum window, and not in the background without a window.

And Windows does not have to be installed on the C: drive in a directory named Windows . Therefore, it is better to use one of these two commands:

 cmd.exe /C start "" /MAX "%SystemRoot%\System32\notepad.exe" cmd.exe /C start "" /MAX "%windir%\System32\notepad.exe" 

The windir environment variable is the default environment variable starting from Windows 95 with the path to the Windows startup directory.

The SystemRoot environment variable is an environment variable predefined by all versions of Windows based on Windows NT with the path to the Windows directory.

At present, it is better to use SystemRoot , since this environment variable is built-in Windows, and windir simply predefined in the list of system environment variables and therefore can also be deleted.

See the Wikipedia article on Windows Environment Variables for a list of predefined environment variables for a description.

+1
source

Source: https://habr.com/ru/post/1257854/


All Articles