Solved

Exe & Com

Posted on 1998-10-31
6
264 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

828 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