Solved

Exe & Com

Posted on 1998-10-31
6
260 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now