EXCEL VBA CreateProcessA not starting process under Windows 11

67 views Asked by At

I have macros in a .XLAM file that is loaded when EXCEL starts. They work fine on my current laptop running Windows 10. The CreateProcessA call/function starts a BAT file on the computer just fine. When I put that same XLAM file on a new Windows 11 laptop, the CreateProcessA call/function never starts the BAT file. There is no error. I don't know this call at all as I "inherited" the code a number of years back. I've put in the PtrSave and LongPtr stuff but no difference.

'''

Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As LongPtr, ByVal dwMilliseconds As Long) As Long

Private Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As LongPtr, _
    ByVal lpCommandLine As String, ByVal lpProcessAttributes As LongPtr, ByVal lpThreadAttributes As LongPtr, _
    ByVal bInheritHandles As LongPtr, ByVal dwCreationFlags As LongPtr, ByVal lpEnvironment As LongPtr, _
    ByVal lpCurrentDirectory As LongPtr, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As LongPtr

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 Byte
    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


This is the sub where i try to run command.

    Dim executePath As String
    Dim procInfo As PROCESS_INFORMATION
    Dim retVal As LongPtr
    Dim startInfo As STARTUPINFO
    Dim thePieces() As String
    
' Initialize the Startup structure.
    startInfo.cb = Len(startInfo)
    startInfo.dwFlags = &H1
    startInfo.wShowWindow = 0

' Build command string.
    thePieces = Split(MyListFile, "\")
    executePath = FILEHOLDBATCH & " " & thePieces(UBound(thePieces)) & " " & MyEnvironment
    
' Start FileHold.
    retVal = CreateProcessA(0&, executePath, 0&, 0&, 1&, HIGH_PRIORITY_CLASS, 0&, 0&, startInfo, procInfo)
0

There are 0 answers