Results 1 to 2 of 2

Thread: Run hidden!

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 1999
    Location
    Luxembourg
    Posts
    2

    Post

    I am using this code, but it runs in the foreground when I want it to be hidden can anyone tell me the correct syntax to do this.


    Dim CmdLine$

    If Not IsMissing(CommandLine) Then
    CmdLine$ = ToRun & " " & CommandLine
    Else
    CmdLine$ = ToRun
    End If

    Dim proc As PROCESS_INFORMATION
    Dim Start As STARTUPINFO
    Dim Ret&
    wShowWindow = sw_hide
    ' Initialize the STARTUPINFO structure:
    Start.cb = Len(Start)

    ' Start the shelled application:
    Ret& = CreateProcessA(0&, CmdLine$, 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)


    Thanks.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try this:
    Code:
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function WaitForSingleObjectEx Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long, ByVal bAlertable As Long) As Long
    Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    
        Dim lPID As Long
        lPID = Shell(CmdLine$, vbHide)
        lPID = OpenProcess(PROCESS_ALL_ACCESS, 0, lPID)
        Call WaitForSingleObjectEx(lPID, -1, 1)

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

Posting Permissions

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



Click Here to Expand Forum to Full Width