11 个解决方案
#1
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 Command2_Click()
' Shell传回Process ID,运行的程序是CALC.EXE
pId = Shell("C:\aa.bat", 1)
' 取得 Process Handle
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
' TerminateProcess 所传入的是 Process Handle
Call TerminateProcess(pHnd, 0) '关闭"C:\aa.bat"
Call CloseHandle(pHnd)
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 Command2_Click()
' Shell传回Process ID,运行的程序是CALC.EXE
pId = Shell("C:\aa.bat", 1)
' 取得 Process Handle
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
' TerminateProcess 所传入的是 Process Handle
Call TerminateProcess(pHnd, 0) '关闭"C:\aa.bat"
Call CloseHandle(pHnd)
End Sub
#2
你是怎么调用的?看看代码先!
#3
用这个按钮调用的:ShellExecute 0, "open", "c:\exam.bat", vbNullString, vbNullString, SW_SHOWMINNOACTIVE ,这个虽然看不到DOS窗口,但是关机是总要提示有个窗口还没关闭.
还有能不能给个简单的答案或者例子发给我spring2121@163.net,因为我刚学用VB,很多都看不动.
还有能不能给个简单的答案或者例子发给我spring2121@163.net,因为我刚学用VB,很多都看不动.
#4
@http://www.codeoftheweek.com/bonus/mstipoftheweek.html
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
#5
@http://www.codeoftheweek.com/bonus/mstipoftheweek.html
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
#6
要实现目的,可以试一下这个,看看合你的意不!
shell("cmd /c c:\exam.bat")
命令串“cmd /c c:\exam.bat”是可以在DOS状态下运行的命令。你试一下就知道了(用运行对话框)。cmd命令的相关参数你可以去查系统帮助里的命令参考。
而shell("cmd /c c:\exam.bat")可以放在某个命令事件里,如CommandButton_Click().
shell("cmd /c c:\exam.bat")
命令串“cmd /c c:\exam.bat”是可以在DOS状态下运行的命令。你试一下就知道了(用运行对话框)。cmd命令的相关参数你可以去查系统帮助里的命令参考。
而shell("cmd /c c:\exam.bat")可以放在某个命令事件里,如CommandButton_Click().
#7
写成这样就报错:实时错误53
文件没找到
是不是SHELL参数不能这么写?
Private Sub Command1_Click()
'ShellExecute 0, "open", "c:\exam.bat", vbNullString, vbNullString, SW_SHOW
Shell ("command /c c:\exam.bat")
End Sub
文件没找到
是不是SHELL参数不能这么写?
Private Sub Command1_Click()
'ShellExecute 0, "open", "c:\exam.bat", vbNullString, vbNullString, SW_SHOW
Shell ("command /c c:\exam.bat")
End Sub
#8
ShellExecute 0, "open", "command", " /c c:\exam.bat", vbNullString, SW_SHOW
你的意思是这样写吗?我真的才学用,还有上面第一位写的,为什么复制过来没用,窗口仍然在。
第二位写的没看懂,能不能中文说明一下,还有我怎么才能看懂,要看什么书才好,谢谢各位帮助一定会给分。
你的意思是这样写吗?我真的才学用,还有上面第一位写的,为什么复制过来没用,窗口仍然在。
第二位写的没看懂,能不能中文说明一下,还有我怎么才能看懂,要看什么书才好,谢谢各位帮助一定会给分。
#9
你要是98
Shell ("command /c c:\exam.bat"),vbHide
你要是2000
Shell ("cmd /c c:\exam.bat"),vbHide
Shell ("command /c c:\exam.bat"),vbHide
你要是2000
Shell ("cmd /c c:\exam.bat"),vbHide
#10
study
#11
1.按住Alt不放,双击BAT文件图标,出现 XXX.BAT“属性(Properties)”;
2.将“正常窗体(Normal windows)”改成“最小化(Minimized).”
2.将“正常窗体(Normal windows)”改成“最小化(Minimized).”
#1
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 Command2_Click()
' Shell传回Process ID,运行的程序是CALC.EXE
pId = Shell("C:\aa.bat", 1)
' 取得 Process Handle
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
' TerminateProcess 所传入的是 Process Handle
Call TerminateProcess(pHnd, 0) '关闭"C:\aa.bat"
Call CloseHandle(pHnd)
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 Command2_Click()
' Shell传回Process ID,运行的程序是CALC.EXE
pId = Shell("C:\aa.bat", 1)
' 取得 Process Handle
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
' TerminateProcess 所传入的是 Process Handle
Call TerminateProcess(pHnd, 0) '关闭"C:\aa.bat"
Call CloseHandle(pHnd)
End Sub
#2
你是怎么调用的?看看代码先!
#3
用这个按钮调用的:ShellExecute 0, "open", "c:\exam.bat", vbNullString, vbNullString, SW_SHOWMINNOACTIVE ,这个虽然看不到DOS窗口,但是关机是总要提示有个窗口还没关闭.
还有能不能给个简单的答案或者例子发给我spring2121@163.net,因为我刚学用VB,很多都看不动.
还有能不能给个简单的答案或者例子发给我spring2121@163.net,因为我刚学用VB,很多都看不动.
#4
@http://www.codeoftheweek.com/bonus/mstipoftheweek.html
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
#5
@http://www.codeoftheweek.com/bonus/mstipoftheweek.html
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
May 13, 1997
Closing a DOS prompt window
by Chuck Kraatz
After you run a DOS application in Windows 95, the MS-DOS Prompt window doesn't close. To prevent this behavior, you can use the API to find the Window handle for the DOS prompt window, wait for the program to finish running, then zap the DOS prompt window into oblivion.
This technique doesn't require any forms. It's just a simple VB 4.0 DLL with two properties: the EXE name of the DOS program and the text that will appear as the caption of the DOS prompt window displaying this application. The core of this app lies in three API calls. Place the following code in a standard module:
Declare Function FindWindow& Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Const WM_CLOSE = &H10
The rest of the code goes in the following class module, named Cclose:
Private m_sEXEName As String
Private m_sDosCaption As String
Public Sub RunDosApp()
Dim vReturnValue As Variant
Dim lRet As Long
Dim i As Integer
vReturnValue = Shell(m_sEXEName, 1) ' Run EXE
AppActivate vReturnValue ' Activate EXE Window
Do
Sleep (10000)
lRet = FindWindow(vbNullString, m_sDosCaption)
If (lRet <> 0) Then
vReturnValue = SendMessage(lRet, WM_CLOSE, &O0, &O0)
Exit Do
End If
Loop
End Sub
#6
要实现目的,可以试一下这个,看看合你的意不!
shell("cmd /c c:\exam.bat")
命令串“cmd /c c:\exam.bat”是可以在DOS状态下运行的命令。你试一下就知道了(用运行对话框)。cmd命令的相关参数你可以去查系统帮助里的命令参考。
而shell("cmd /c c:\exam.bat")可以放在某个命令事件里,如CommandButton_Click().
shell("cmd /c c:\exam.bat")
命令串“cmd /c c:\exam.bat”是可以在DOS状态下运行的命令。你试一下就知道了(用运行对话框)。cmd命令的相关参数你可以去查系统帮助里的命令参考。
而shell("cmd /c c:\exam.bat")可以放在某个命令事件里,如CommandButton_Click().
#7
写成这样就报错:实时错误53
文件没找到
是不是SHELL参数不能这么写?
Private Sub Command1_Click()
'ShellExecute 0, "open", "c:\exam.bat", vbNullString, vbNullString, SW_SHOW
Shell ("command /c c:\exam.bat")
End Sub
文件没找到
是不是SHELL参数不能这么写?
Private Sub Command1_Click()
'ShellExecute 0, "open", "c:\exam.bat", vbNullString, vbNullString, SW_SHOW
Shell ("command /c c:\exam.bat")
End Sub
#8
ShellExecute 0, "open", "command", " /c c:\exam.bat", vbNullString, SW_SHOW
你的意思是这样写吗?我真的才学用,还有上面第一位写的,为什么复制过来没用,窗口仍然在。
第二位写的没看懂,能不能中文说明一下,还有我怎么才能看懂,要看什么书才好,谢谢各位帮助一定会给分。
你的意思是这样写吗?我真的才学用,还有上面第一位写的,为什么复制过来没用,窗口仍然在。
第二位写的没看懂,能不能中文说明一下,还有我怎么才能看懂,要看什么书才好,谢谢各位帮助一定会给分。
#9
你要是98
Shell ("command /c c:\exam.bat"),vbHide
你要是2000
Shell ("cmd /c c:\exam.bat"),vbHide
Shell ("command /c c:\exam.bat"),vbHide
你要是2000
Shell ("cmd /c c:\exam.bat"),vbHide
#10
study
#11
1.按住Alt不放,双击BAT文件图标,出现 XXX.BAT“属性(Properties)”;
2.将“正常窗体(Normal windows)”改成“最小化(Minimized).”
2.将“正常窗体(Normal windows)”改成“最小化(Minimized).”