Solved

Exe & Com

Posted on 1998-10-31
6
266 Views
Last Modified: 2010-04-30
How can I run all Exe and com files in the current dir?

VB3
0
Comment
Question by:marka64
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
mark2150 earned 20 total points
ID: 1442728
Seems kind of silly, but is not a real problem.

DIR command will give you files. Save into list and then execute each one with

SHELL( progname )

This will run all files found by the DIR command. Naturally you'll have to do two DIR's, one with *.COM and one with *.EXE as first argument. SHELL() runs async so will spawn several children at once. I have code for ExecCmd that waits for child to finish, but don't know if it will work on VB3 (is VB5).

M

0
 

Author Comment

by:marka64
ID: 1442729
Mark2150 Thanks but i still have a problem im new to  vb and i wondered if you could give me the sorce code or tell me in detail what to do?
Thanks
0
 

Author Comment

by:marka64
ID: 1442730
Mark2150 Thanks but i still have a problem im new to  vb and i wondered if you could give me the sorce code or tell me in detail what to do?
Thanks
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 12

Expert Comment

by:mark2150
ID: 1442731
Ok, DIR command takes param on the *FIRST* call only that specifies what file it should look for.

Assume you have a list control:

List1.Clear       'Clear list
File = DIR( "*.EXE" )    'Search for first .EXE file
'
DO WHILE LEN( file ) > 0
    List1.Additem file
    File = DIR()     ' No param on 2nd & subsequient calls
LOOP

Ok, List1 now has all .EXE files in current directory. Repeat above (except List1.Clear) for *.COM.

FOR ndx = 0 to List1.ItemCount -1   ' Go thru all elements of array (remember, list is 0 based)
    SHELL( List1.Item(ndx) ), 1    ' Spawn child task
NEXT ndx    'Repeat until all programs have been run.

The drawback of this is that the SHELL() command doesn't wait for any of the child tasks to complete. If you have a *LOT* of .EXE/.COM files in the directory you should see an *explosion* of windows as they *ALL* fire more-or-less at once. This can lead to your resources rapidly dropping and to an eventual crash.

End run around this problem is to use ExecCmd command instead of SHELL. This will *WAIT* for each child to finish before starting the next. ExecCmd is not an internal, rather it is a user function.

'
' These data type declarations are required to support the obscure windows
' function to spawn a child task and wait for it to finish before continuing
'
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 Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long) As Long
'
Private Declare 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 Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'
Const NORMAL_PRIORITY_CLASS = &H20&
Const INFINITE = -1&
'
' I don't really understand the above declares, but they do work so DON'T MESS WITH THEM!

Public Sub ExecCmd(cmdline$)
'
' This executes an external windows program and waits for it to complete
'
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
'
' 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:
'
holdhere:
    DoEvents
    ret& = WaitForSingleObject(proc.hProcess, 5000)
    If ret& <> 0 Then GoTo holdhere
'
ret& = CloseHandle(proc.hProcess)
End Sub

M

0
 

Author Comment

by:marka64
ID: 1442732
mark2150
Thanks but there is still a problem when i try to run my program it gets to the shell command and says:
Excepted: Statement
Can you help?
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1442733
Dunno. Should work. List code was written off the top of my head. When you hover cursor over List1.List(n) statement does the program name show up?

M

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question