Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run DOS program minimised from VBA (Win2000)

    (Edited by HansV to provide link to MSKB article using <!t>[mskb=129796]<!/t>)

    I'm using VBA to provide some extra functionality in an Excel spreadsheet. As part of this I'm using the ExecCmd facility (see <!mskb=129796>Microsoft Knowledge Base Article 129796<!/mskb> for details) in order to run a DOS program which has parameters, eg ExecCmd("GenDos /c12 /s23"). This works fine, but the DOS box does show itself onscreen, which is a little annoying. Is there any way that I can use ExecCmd and run the DOS program minimised? I guess I'm asking how you run a DOS program from the command line minimised, as the parameter for ExecCmd is essentially the command line string. I've seen that 'START GenDos /MIN' is supposed to do the trick, but I can't get that to work, especially where the DOS program also has parameters of its own.

    Any ideas anyone? Thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run DOS program minimised from VBA (Win2000)

    Add the following to the declarations section of the module (at the top):
    <code>
    Const SW_HIDE = 0
    Const SW_NORMAL = 1
    Const SW_MAXIMIZE = 3
    Const SW_MINIMIZE = 6
    </code>
    Use one of these constants in the ExecCmd function as follows:
    <code>
    Public Function ExecCmd(cmdline$)
    Dim proc As PROCESS_INFORMATION
    Dim start As STARTUPINFO
    ' Initialize the STARTUPINFO structure:
    start.cb = Len(start)
    ' *** Added: window size ***
    start.wShowWindow = SW_HIDE
    ' Start the shelled application:
    ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
    ' Wait for the shelled application to finish:
    ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    Call GetExitCodeProcess(proc.hProcess, ret&)
    Call CloseHandle(proc.hThread)
    Call CloseHandle(proc.hProcess)
    ExecCmd = ret&
    End Function</code>

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run DOS program minimised from VBA (Win2000)

    Hi Hans, thanks for that. I can see what you're doing and it looks fine to me. HOWEVER it didn't work! No matter what value I gave to cb.wShowWindow, the darn DOS box still appeared! It can be minimised manually from the title bar, but refuses to be hidden or minimised via the StartInfo information. I'm at a loss now? Any further ideas?

    Thanks again.

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run DOS program minimised from VBA (Win2000)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    In fact, Hans, I ran across this item on the web, http://www.experts-exchange.com/Programmin...Q_20990855.html, that seems to indicate that someone else has had the same problem as me, i.e the window refuses to hide or minimise. Unfortunately, I'm not signed up to Experts Exchange so I can't access the solution. Mean anything to you? Thanks again.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run DOS program minimised from VBA (Win2000)

    Despite the "Sign Up to See This Solution" link below the question in Experts Exchange, you can scroll down to see the replies. There is a lengthy piece of code that appears to have solved it. Let me know if you can't scroll to it.

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run DOS program minimised from VBA (Win2000)

    Mmmm! Next time I'll remember to scroll down past all the ads! Looks promising, but I haven't got time to try it today now, so it'll have to be next week. I'll let you know if it works for me! Thanks again.

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run DOS program minimised from VBA (Win2000)

    Ok, change of plan, meeting called off. So I did have time to try it - and it works!! So thanks for all your help, Hans - and I did need your input. It was the mention of the enums SW_HIDE etc that led me to that q&a in Experts Exchange, so it IS down to you! Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •