Const SYNCHRONIZE = & H100000
Const INFINITE = & HFFFFFFFF
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
' 分别声明 Process ID 及 Process Handle 变数
Dim pId As Long, pHnd As Long
Dim Flag As Boolean
Private Sub Command1_Click()
If Flag = True Then
' TerminateProcess 所传入的是 Process Handle
Call TerminateProcess(pHnd, 0)
Call CloseHandle(pHnd)
Flag = False
Else
Flag = True
End If
' Shell传回Process ID,运行的程序是CALC.EXE
pId = Shell("CALC.EXE", 1)
' 取得 Process Handle
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
End Sub
Const INFINITE = & HFFFFFFFF
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
' 分别声明 Process ID 及 Process Handle 变数
Dim pId As Long, pHnd As Long
Dim Flag As Boolean
Private Sub Command1_Click()
If Flag = True Then
' TerminateProcess 所传入的是 Process Handle
Call TerminateProcess(pHnd, 0)
Call CloseHandle(pHnd)
Flag = False
Else
Flag = True
End If
' Shell传回Process ID,运行的程序是CALC.EXE
pId = Shell("CALC.EXE", 1)
' 取得 Process Handle
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
End Sub
改为pId = Shell("ARJ.exe", 1)
主 题: 用ShellExecute调用计算器程序,如何只让它启动一次? 是不是要达到这个要求??
用Shell "Command.com arj.exe"行不行?
Shell(Parameter(0) & "Command.com /c arj.exe x -y " & Parameter(1) & "*.arj" & " " & Parameter(2), 1)
这样是对的吗?但是如果这样的话,程序会报错啊!提示File not found!
Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Const WM_CLOSE = &H10
Dim hArjWnd as longhArjWnd=FindWindow(vbNullString,"Arj.exe")
Do While hArjWnd
SendMessage hArjWnd,WM_CLOSE,0,Byval 0&
hArjWnd=FindWindow(vbNullString,"Arj.exe")
Loop
Call SetForegroundWindow(hwnd)
Call PostMessage(hwnd, WM_CLOSE, 0, 1)
SendKeys "Y"
command.com在windows安装目录下,本来可以直接运行,你在前面加东西,当然提示File not found!
你可以去msdn看看一篇文章,好像VB中无法解决这个问题
解决方法如下:
右击打开arj.exe的属性窗口-->点击程序-->选中“退出时关闭”-->确定
按以上操作后,执行完arj.exe程序后Dos窗口就会自动关闭。
Shell "Command.com /c a:\arj.exe a c:\aa.arj c:\abc.txt"