Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

stdProcess - Use CreateProcess() instead of Shell()

Aperta
#18 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Refactoring
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
visualbasic

Direzione di ricerca

Start with the existing stdProcess implementation and the WinApi_CreateProcess example in the issue, then compare CreateProcess behavior for cmd.exe, mspaint.exe, explorer.exe, calc.exe, and notepad.exe. Determine what prevents the affected applications from opening and integrate the working process creation behavior into stdProcess, with all listed applications launching successfully.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement lib-stdProcess

Currently we are using Shell() for simplicity. We have built some (bodge) 64-bit code as follows:

Private Type SECURITY_ATTRIBUTES
    nLength              As Long
    lpSecurityDescriptor As LongPtr
    bInheritHandle       As Long
End Type

Private Type STARTUPINFO
    cb              As Long
    lpReserved      As String
    lpDesktop       As String
    lpTitle         As String
    dwX             As Long
    dwY             As Long
    dwXSize         As Long
    dwYSize         As Long
    dwXCountChars   As Long
    dwYCountChars   As Long
    dwFillAttribute As Long
    dwFlags         As Long
    wShowWindow     As Integer
    cbReserved2     As Integer
    lpReserved2     As LongPtr
    hStdInput       As LongPtr
    hStdOutput      As LongPtr
    hStdError       As LongPtr
End Type

Private Type PROCESS_INFORMATION
    hProcess    As LongPtr
    hThread     As LongPtr
    dwProcessId As Long
    dwThreadId  As Long
End Type

Public Enum ECreationFlags
    CREATE_BREAKAWAY_FROM_JOB = &H1000000
    CREATE_DEFAULT_ERROR_MODE = &H4000000
    CREATE_NEW_CONSOLE = &H10&
    CREATE_NEW_PROCESS_GROUP = &H200&
    CREATE_NO_WINDOW = &H8000000
    CREATE_PROTECTED_PROCESS = &H40000
    CREATE_PRESERVE_CODE_AUTHZ_LEVEL = &H2000000
    CREATE_SECURE_PROCESS = &H400000
    CREATE_SEPARATE_WOW_VDM = &H800&
    CREATE_SHARED_WOW_VDM = &H1000&
    CREATE_SUSPENDED = &H4&
    CREATE_UNICODE_ENVIRONMENT = &H400&
    DEBUG_ONLY_THIS_PROCESS = &H2&
    DEBUG_PROCESS = &H1&
    DETACHED_PROCESS = &H8&
    EXTENDED_tStartupInfo_PRESENT = &H80000
    INHERIT_PARENT_AFFINITY = &H10000
    PRIORITY_CLASS_NORMAL = &H20&
    PRIORITY_CLASS_IDLE = &H40&
    PRIORITY_CLASS_HIGH = &H80&
End Enum

Public Enum EStartupFlags
    STARTF_FORCEONFEEDBACK = &H40&
    STARTF_FORCEOFFFEEDBACK = &H80&
    STARTF_PREVENTPINNING = &H2000&
    STARTF_RUNFULLSCREEN = &H20&
    STARTF_TITLEISAPPID = &H1000&
    STARTF_TITLEISLINKNAME = &H800&
    STARTF_UNTRUSTEDSOURCE = &H8000&
    STARTF_USECOUNTCHARS = &H8&
    STARTF_USEFILLATTRIBUTE = &H10&
    STARTF_USEHOTKEY = &H200&
    STARTF_USEPOSITION = &H4&
    STARTF_USESHOWWINDOW = &H1&
    STARTF_USESIZE = &H2&
    STARTF_USESTDHANDLES = &H100&
End Enum

Private Declare PtrSafe Function CreateProcess Lib "kernel32" Alias "CreateProcessA" ( _
       ByVal lpApplicationName As String, _
       ByVal lpCommandLine As String, _
       ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, _
       ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, _
       ByVal bInheritHandles As Long, _
       ByVal dwCreationFlags As Long, _
       ByRef lpEnvironment As Any, _
       ByVal lpCurrentDirectory As String, _
       ByRef lpStartupInfo As STARTUPINFO, _
       ByRef lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare PtrSafe Function SuspendThread Lib "kernel32" (ByVal hThread As LongPtr) As Long
Private Declare PtrSafe Function ResumeThread Lib "kernel32" (ByVal hThread As LongPtr) As Long
Private Declare PtrSafe Function CloseHandle Lib "kernel32.dll" (ByVal hObject As LongPtr) As Long
Private Declare PtrSafe Function DebugActiveProcess Lib "kernel32" (ByVal dwProcessId As Long) As Long
Private Declare PtrSafe Function DebugActiveProcessStop Lib "kernel32" (ByVal dwProcessId As Long) As Long
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Public Function WinApi_CreateProcess(strCommandLine As String, Optional strCurrentDirectory As String = vbNullString) As Long
    If strCurrentDirectory = vbNullString Then
        strCurrentDirectory = ThisWorkbook.Path
    End If
    Dim sap As SECURITY_ATTRIBUTES: sap.nLength = Len(sap)
    Dim sat As SECURITY_ATTRIBUTES: sat.nLength = Len(sat)
    Dim si As STARTUPINFO: si.cb = Len(si)
    si.wShowWindow = STARTF_USESHOWWINDOW
    Dim pi As PROCESS_INFORMATION
    Debug.Print Err.LastDllError ' 0 => ERROR_SUCCESS
    Dim dwResult As Long: dwResult = CreateProcess(vbNullString, strCommandLine, sap, sat, 0, PRIORITY_CLASS_NORMAL, 0, strCurrentDirectory, si, pi)
    WinApi_CreateProcess = pi.dwProcessId
End Function

which appears to be able to create cmd.exe processes correctly, however any application with UI like mspaint.exe, explorer.exe and calc.exe are all unopenable using this function...

Need to figure out what we are missing and integrate this into stdProcess

Edit: Actually, notepad.exe works fine! Still not sure about the others...

Lingua principale
VBA
Stelle
412
Fork
70
Merge medio
1g 3h
PR unite (30g)
4

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sancarn/stdVBA

Tutte le issue di sancarn/stdVBA

Issue simili

Altre issue su Operating Systems

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.