[Original] Flexible use of batch files in programming

xiaoxiao2021-03-06  19

We often encounter such problems, such as executing several programs in order, not simultaneous implementation, not in turn, but when the first program is executed, then execute the second, then the third, etc. wait wait wait. In the 9CBS community, users WW111222 have encountered such a problem: how to perform 4 EXE programs in order. One solution is to start a program using a specific API, monitor it, keep monitoring it until it is closed, and then execute the second. This method is indeed feasible: If you have seen some installer, you will find that they will execute a program during the installation process, waiting for the process to continue the installation process, but obviously this method is more troublesome. At the same time, if you still remember the concept of a batch of processes in the DOS era (actually, this concept still exists), you might want to use the batch to solve this problem like I. In this post, I replied: Suppose 4 DOS programs are 1.exe, 2.exe, 3.exe, 4.exe, are placed in C: / Next: Private Sub Form_Load () DIM SCMD AS Stringscmd = "C:" & VBCRLF & "CD /" & VBCRLF & "1.exe" & Vbcrf & "3.exe" & Vbcrlf & "4.exe" Open "C: / 1.BAT "for Output As # 1 Print # 1, SCMDClose # 1SHELLEXECUTE 0," Open "," C: /1.bat ", VBnullString, VBnullString, VBnullend Sub

The logic of the program is simple, write a BAT file, then save it to C: / Next, use the shellexecute API (if you don't understand, refer to the MSDN) to execute it. Later I learned that directly using the shell statement can also achieve the same effect (executing the bat file) and is more simple. Then the owner proposed, each program has their parameters. I have modified the program: assuming that 4 DOS programs are 1.exe, 2.exe, 3.exe, 4.exe, are placed in C: / lower; parameters are PARAM1, PARAM2, PARAM3, PARAM4: Private Declare Function ShellExecute Lib "shell32.dll" Alias ​​"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPrivate Sub Form_Load () DIM SCMD AS STRINGSCMD = "C:" & VBCRLF & "CD /" & VBCRLF & "1.EXE /" & PARAM1 & VBCRLF & "2.exe /" & param2 & vbcrf & "3.exe /" & param3 & " VBCRLF & "4.exe /" & param4open "C: /1.bat" for output as # 1 print # 1, scmdclose # 1SHELLEXECUTE 0, "Open", "c: /1.bat", vbnullstring, vbnullstring, vbnullend Sub Next User Terry6394 "Dog Tail Surpe": If you want to run, leave the command line window, you can do this:

转载请注明原文地址:https://www.9cbs.com/read-68189.html

New Post(0)