Results 1 to 3 of 3

Thread: Track of an idle application called

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    1

    Track of an idle application called

    Hi,
    I want to do this using VB.
    I have executed a command prompt through VB.
    After the command prompt completes its process, say in 10-20 minutes time, I want this to be communicated to my VB program.
    How can this be done? Moreover, I came across a UIAutomationprovider.dll in .Net which lets this happen via a 'WaitForInputIdle" method.
    But I don't want to use .Net.
    Can somebody help me out?
    Thanks in advance.

  2. #2
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: Track of an idle application called

    Quote Originally Posted by simplyans
    I want to do this using VB.
    I have executed a command prompt through VB.
    After the command prompt completes its process, say in 10-20 minutes time, I want this to be communicated to my VB program.
    How can this be done? Moreover, I came across a UIAutomationprovider.dll in .Net which lets this happen via a 'WaitForInputIdle" method.
    But I don't want to use .Net.
    Can somebody help me out?
    I think you can do it, but unfortunately, I don't think that you will have a simple, graceful way of achieving this desired goal. Here are a few ideas, and we can build upon it later after you decide to use one of these ideas.

    If you want to communicate between programs/processes, you have roughly two choices:

    * File I/O
    * Memory I/O

    File I/O would be for your first program to write to a file when it is done, and the information that you want transferred to be written to the file. Your second (VB) program would periodically look in a pre-determined location for this file. If it isn't found, it will go to sleep for a while and then look for it again. If the file is found, it would open the file, read & parse the contents of the file, and continue its work from there.

    Memory I/O would be to run as an ActiveX Service or use a shared DLL with your VB program. At a certain time, it would poll the other processes that were running when it is done, and if it found your VB program, it would transfer the information via Event/Messages to your VB program. Using a shared DLL would be similar, and it would act like the File I/O option stated above.

    As I said, there isn't a simple, easy, graceful way to pull off what you want in VB 6.0, but with the right design and use of the Windows API, you can make it happen.

  3. #3
    Member
    Join Date
    Oct 2006
    Location
    Noida,India
    Posts
    49

    Re: Track of an idle application called

    Write ActiveX Exe to Execute you command with the code given below
    Create some events in this ActiveX Exe like CommandFinished

    In Your VB.6 Application Create withevent Object of this ActiveX Exe and call its execute menthos to execute you Command.For Asc. Call first set your command and parameters and then call timer to trigger your command.When you call timer the control will immediately return to your vb.6 application and you can contuniue with your application (Doing other things) IN the mean time timer will kick the execute method to start executing your command.When the command is exected the ActiveX exe will raise Event which is trapped by your Vb.6 Application and hence your Vb.6 application cam to know that the command is finished.You can also pass paraments to CommandFinished Event like return code of you command..

    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
    wShowWindo As Integer
    cbReserved2 As Integer
    lpReserved2 As Byte
    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

    'constant flags for the kernel32 functions
    Private Const STATUS_PENDING = &H103&
    Private Const PROCESS_QUERY_INFORMATION = &H400
    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const HIGH_PRIORITY_CLASS = &H80&
    Private Const GWL_WNDPROC = (-4)

    Private pInfo As PROCESS_INFORMATION
    Private sInfo As STARTUPINFO
    Private sNull As String

    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
    Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Private Const STATUS_WAIT_0 As Long = &H0
    Private Const WAIT_TIMEOUT As Long = 258&
    Private Const WAIT_OBJECT_0 As Long = (STATUS_WAIT_0 + 0)
    Private Const WAIT_FAILED As Long = &HFFFFFFFF



    pRetCode = CreateProcess(sNull, "Your Command"& " " & "Parameters", ByVal 0&, _
    ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)

    If pRetCode = 0 Then
    'Report Error
    End If
    pRetCode = WaitForSingleObject(pInfo.hProcess, 1)
    pCurrentTime = 1
    Do While pRetCode = 258
    Sleep 550
    pRetCode = WaitForSingleObject(pInfo.hProcess, 1)
    DoEvents
    If pToBeTerninated Then
    pCurrentTime = pCurrentTime + 550
    If pCurrentTime > pTimeOut Then
    pRetCode = WAIT_TIMEOUT
    Exit Do
    End If
    End If
    Loop
    Call TerminateProcess(pInfo.hProcess, vbNull) ' This line here will close the program
    CloseHandle (pInfo.dwProcessId)
    CloseHandle (pInfo.dwThreadId)

    Please rate if this helps you

    Regards
    Rajneesh
    Rajneesh

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