Results 1 to 4 of 4
  1. #1
    ThierryA is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Posts
    2

    Angry Function Shell&Wait, used to work with access 2007, doesn't with 2013

    Hello,

    I have this big database with my pictures and I use a lot of desktop interaction: running external programs to view, export, batch modify pictures.
    I just migrated to Access 2013 (64bit under win 8) and I lost a lot of these capabilities


    Most of the commands were launched via a function that has several purposes:
    • run the command and wait for it to finish before going on
    • send various parameters to the function (command line for the program tu launch + separate string for parameters + 0 or 5 to show or hide the command window)

    Now this command does just nothing: no error but the target program does not execute...

    I searched the web a lot, tried a solution recommended by MS here : http://msdn.microsoft.com/en-us/libr.../ff845544.aspx
    Didn't work: the app launches OK but the code doesn't even wait for the app to finish...

    This is the code I have:
    Code:
    Option Explicit
     
    Public Const SEE_MASK_DOENVSUBST As Long = &H200
    Public Const SEE_MASK_IDLIST As Long = &H4
    Public Const SEE_MASK_NOCLOSEPROCESS As Long = &H40
    Public Const SW_HIDE As Long = 0
    Public Const SW_SHOW As Long = 5
    Public Const WAIT_TIMEOUT As Long = 258&
    Public Type SHELLEXECUTEINFOA
        cbSize As Long
        fMask As Long
        hwnd As Long
        lpVerb As String
        lpFile As String
        lpParameters As String
        lpDirectory As String
        nShow As Long
        hInstApp As Long
        lpIDList As Long
        lpClass As String
        hkeyClass As Long
        dwHotKey As Long
        hIcon As Long
        hProcess As Long
    End Type
    Public Declare PtrSafe Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
    Public Declare PtrSafe Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long
    Public Declare PtrSafe Function ShellExecuteEx Lib "shell32.dll" (ByRef lpExecInfo As SHELLEXECUTEINFOA) As Long
    Public Declare PtrSafe Function WaitForSingleObject Lib "kernel32.dll" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
     
    Public Function ShellWait(ByRef vsCmdLine As String, Optional ByRef vsParameters As String, Optional ByRef vsCurrentDirectory As String = vbNullString, Optional ByVal vnShowCmd As Long = SW_SHOW, Optional ByVal vnTimeOut As Long = 200) As Long
    Dim lpShellExInfo As SHELLEXECUTEINFOA
        With lpShellExInfo
            .cbSize = Len(lpShellExInfo)
            .lpDirectory = vsCurrentDirectory
            .lpVerb = "open"
            .lpFile = vsCmdLine
            .lpParameters = vsParameters
            .nShow = vnShowCmd
            .fMask = SEE_MASK_DOENVSUBST Or SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_IDLIST
        End With
        If ShellExecuteEx(lpShellExInfo) Then
            Do While WaitForSingleObject(lpShellExInfo.hProcess, vnTimeOut) = WAIT_TIMEOUT
                DoEvents
            Loop
            GetExitCodeProcess lpShellExInfo.hProcess, ShellWait
            CloseHandle lpShellExInfo.hProcess
        Else
            ShellWait = vbError
        End If
    End Function
    the only modification I made was adding the PtrSafe statement to the declarations.
    I tried to pinpoint the problem: It seems that execution doesn't even enter the
    Code:
    If ShellExecuteEx(lpShellExInfo) Then
    Please help: I'm getting mad with this !

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I am going to guess the application(s) you are looking at do not rely on the shell32.dll. Not sure what the solution would be. I have yet to integrate any 64 bit API's.

  3. #3
    ThierryA is offline Novice
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Posts
    2

    Thumbs up Problem solved !

    Problem solved: API calls in 64bit are different.
    Code below works: appli is launched and the code waits for it to finish before going further.
    Best of all: a parameter controls the visibility of the app window: very useful to run a background batch of command line processes without poisoning the display or the focus.

    Code:
    Private Const STARTF_USESHOWWINDOW& = &H1
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const INFINITE = -1&
    
    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 Long
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
    End Type
    
    Private Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessID As Long
        dwThreadID As Long
    End Type
    
    Private Declare PtrSafe Function WaitForSingleObject Lib "kernel32" (ByVal _
        hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Private Declare PtrSafe Function CreateProcessA Lib "kernel32" (ByVal _
        lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
        lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
        ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
        ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
        lpStartupInfo As STARTUPINFO, lpProcessInformation As _
        PROCESS_INFORMATION) As Long
    
    Private Declare PtrSafe Function CloseHandle Lib "kernel32" (ByVal _
        hObject As Long) As Long
    
    Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
        Dim proc As PROCESS_INFORMATION
        Dim start As STARTUPINFO
        Dim ret As Long
        ' Initialize the STARTUPINFO structure:
        With start
            .cb = Len(start)
            If Not IsMissing(WindowStyle) Then
                .dwFlags = STARTF_USESHOWWINDOW
                .wShowWindow = WindowStyle
            End If
        End With
        ' Start the shelled application:
        ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
                NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
        ' Wait for the shelled application to finish:
        ret& = WaitForSingleObject(proc.hProcess, INFINITE)
        ret& = CloseHandle(proc.hProcess)
    End Sub

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Thanks for posting. This is good info.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 06-19-2013, 04:45 PM
  2. Replies: 1
    Last Post: 05-02-2012, 11:40 AM
  3. wait and shell
    By maxbre in forum Programming
    Replies: 19
    Last Post: 11-03-2011, 11:10 AM
  4. Replies: 2
    Last Post: 01-03-2011, 05:17 PM
  5. 2007 doesn't work in Windows 7
    By InvGrp in forum Access
    Replies: 2
    Last Post: 05-24-2010, 03:23 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums