Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call a windows pgm and pass parameters. 1

Status
Not open for further replies.

CooterBrown

IS-IT--Management
Aug 17, 2001
125
US
Right now to run my software I have to click start, run and type the command: C:/dir/application.exe AUTOILLUS C:\inputfile
with AUTOILLUS and C:\inputfile being parameters necessary for the application to run the correct function and pick up the data from the correct input file in a specified directory. Does anyone have any code to all a program and pass the parameters? Ex being a drop down box with a list of input files so that my users don't have to enter the command line every time. I want them to be able to dbl click an icon, have a list box or some check boxes to select an environment to parse data file from and run.
any one have any ideas?
 
Shell it?

Select options
case option1
shell "Program.exe /option1"
case option2
shell "Program.exe /option2"
end select
 
Is there a way to determine when that application is finished running?
 
Hi,

There are a number of ways of doing this ... here's one ...

Code:
Private Declare Function IsWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Dim hWndCalc As Long

Private Sub Command1_Click()
    Shell "c:\winnt\system32\calc.exe", vbNormalFocus
    hWndCalc = FindWindow(vbNullString, "Calculator")
    Do
        DoEvents
    Loop While IsWindow(hWndCalc) <> 0
    MsgBox &quot;Program finished&quot;
End Sub

Depending on how long your process runs for, you may want to improve on the loop a bit - this way is processor intensive - you could use the SleepEx windows API, or put this check in a timer control for example.

The FindWindow command needs to have the title bar text exactly as it appears on the program. The first parameter is the Classname for the window. If the title bar title changes depending on other factors (like Internet Explorere does), then you need to use the classname (identify this with Spy++), and then you use EnumWindows, GetClassName and GetWindowText to track down your running Window.




Hope this helps ...
 
This code will pause your app's thread until the shelled app closes.
Code:
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

Type PROCESS_INFORMATION
 hProcess As Long
 hThread As Long
 dwProcessID As Long
 dwThreadID As Long
End Type

Const NORMAL_PRIORITY_CLASS = &H20&
Const INFINITE = -1&

Declare Function WaitForSingleObject Lib &quot;kernel32&quot; _
(Byval hHandle As Long, _
Byval dwMilliseconds As Long) As Long

Declare Function CreateProcessA Lib &quot;kernel32&quot; _
(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

Declare Function GetExitCodeProcess Lib &quot;kernel32&quot; _
(Byval hProcess As Long, lpExitCode As Long) As Long
'________________________________________

Function fShellWait(strCmdLine As String) As Long

  '--- Shells the passed command line and waits for the process to finish
  '--- Returns the exit code of the shelled process

  Dim udtProc As PROCESS_INFORMATION
  Dim udtStart As STARTUPINFO
  Dim lngRtn As Long

  'Initialize the STARTUPINFO structure
  udtStart.cb = Len(udtStart)

  'Launch the shelled application and yield to it
   lngRtn = CreateProcessA(Clng(0), strCmdLine, CLng(0), _
   CLng(0), CLng(1), NORMAL_PRIORITY_CLASS, CLng(0), _
   CLng(0), udtStart, udtProc)
   DoEvents

  'Wait for the shelled application to finish
  lngRtn = WaitForSingleObject(udtProc.hProcess, INFINITE)
  GetExitCodeProcess udtProc.hProcess, lngRtn
  CloseHandle udtProc.hThread
  CloseHandle udtProc.hProcess
  fShellWait = lngRtn

End Function
'_________________________________


 Dim lngRtn As Long

 lngRtn = fShellWait( _
 &quot;C:\dir\application.exe AUTOILLUS C:\inputfile&quot;)

Paul Bent
Northwind IT Systems
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top