Home > Net >  'The system cannot find the file specified' when starting conhost process
'The system cannot find the file specified' when starting conhost process

Time:11-11

When I use the code down below to start a cmd window and move it into a panel, everything works OK. But when I replace cmd with conhost, it fails with the following error: 'The system cannot find the file specified', even when I specify the complete path. By the way, the reason why I'm trying to start conhost instead of cmd is just for testing purposes, I'm trying to find a way to find the PID of the conhost process for a process running through cmd. Thanks for any help in advance!

Kind regards, Eric van Loon

Imports System.Runtime.InteropServices
Public Class Form1
    Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim proc As Process
        proc = Process.Start("cmd")
        proc.WaitForExit(600)
        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
        SendMessage(proc.MainWindowHandle, 274, 61488, 0)
    End Sub
End Class

CodePudding user response:

Like explained by Mofi:

%SystemRoot%\System32\conhost.exe exists on 64-bit Windows only as 64-bit application. There is no 32-bit %SystemRoot%\SysWOW64\conhost.exe. The application running the posted VB.Net code is obviously a 32-bit executable which means the Windows File System Redirector is active and therefore redirects each access to %SystemRoot%\System32 to %SystemRoot%\SysWOW64. That is the reason why conhost.exe cannot be found while 32-bit %SystemRoot%\SysWOW64\cmd.exe is found and executed by this code.

  • Related