When i run the following code to create a cmd.exe process in windows 10, the console application opens and then closes immediately. In windows 7 this is working fine.
If i run calc.exe, this process does not closes immediately, this just happens with cmd.exe.
Const NORMAL_PRIORITY_CLASS = &H20&
Dim lSuccess As Long
Dim sApplicationName As String
Dim sCommandLine As String
Dim wCurrentDirectory As String
Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO
sApplicationName = "C:\Windows\system32\cmd.exe"
sCommandLine = ""
wCurrentDirectory = "C:\Windows\system32"
lSuccess = CreateProcess(sApplicationName, _
sCommandLine, _
ByVal 0&, _
ByVal 0&, _
0&, _
NORMAL_PRIORITY_CLASS, _
ByVal 0&, _
wCurrentDirectory, _
sInfo, _
pInfo)
EDIT:
After some debug i have found the problem, when its invoked SetParent function (after Create Process) the cmd.exe closes, but not calc.exe.
This SetParent function is declared in this way
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
hWndChild is the window handle ID of cmd.exe or calc.exe, and hWndNewParent is the window handle ID of the parent in this case the application that (indirectly) runs this code.