djw1999 发表于 2005-3-7 21:35:58

帮忙~!startbrowser打开IE,然后我要关闭IE,用什么命令啊?

帮忙~!startbrowser打开IE,然后我要关闭IE,用什么命令啊?
有没有命令可以实现,版主帮忙

pcl2004_27 发表于 2005-3-8 09:38:20

SQABasic中没有提供你需要的简单的命令!

Try the following, just copy/paste into a new .rec file set to terminate all iexplore.exe processes.


Const PROCESS_QUERY_INFORMATION = 1024
Const PROCESS_VM_READ = 16
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long ' This process
th32DefaultHeapID As Long
th32ModuleID As Long ' Associated exe
cntThreads As Long
th32ParentProcessID As Long ' This process's parent process
pcPriClassBase As Long ' Base priority of process threads
dwFlags As Long
szExeFile As String * 260 ' MAX_PATH
End Type

Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Declare Function TerminateProcess& Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)
Declare Function CreateToolhelp32Snapshot Lib "Kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Declare Function Process32First Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Declare Function Process32Next Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)

Sub Main

Dim lProcID as long
Dim Result
Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim sApplication as String

sApplication = "IEXPLORE.EXE"
'Takes a snapshot of the processes
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)

'set the length
uProcess.dwSize = Len(uProcess)

'Get the first process in snapshot
Result = Process32First(hSnapShot, uProcess)

Do While Result

If InStr(1, uProcess.szExeFile, Chr$(0)) > 0 Then

'Is this the application we're looking for?
If InStr(1, uProcess.szExeFile, sApplication) Then
'If so, then open the process and get it's Proc ID so we can KILL IT
lProcID = OpenProcess(PROCESS_QUERY_INFORMATION Or _
PROCESS_VM_READ, 0, uProcess.th32ProcessID)

'KILL IT
TerminateProcess lProcID, 0
End If
End If

'Just writing to console for prosperity
sqaconsolewrite uProcess.szExeFile

'Get the next process in snapshot
Result = Process32Next(hSnapShot, uProcess)

Loop

'close our snapshot handle
CloseHandle hSnapShot
End Sub

司空公子 发表于 2005-3-8 09:51:16

哦,你这是单独的关闭脚本吗

pcl2004_27 发表于 2005-3-8 10:05:27

我这段代码比较复杂!是关闭所有IE浏览器的代码!
其实还有简单的代码,就是通过WSH代码实现的!

还有就是通过窗体标题关闭IE的实现方式!
这要看楼主的需求是什么!
我利用的代码是Toolhelp32库实现的,在各个平台都可以实现关闭
而且其他代码比如WSH的代码,可能有平台限制!所以没有选择作为实现方式!

guirongb 发表于 2005-3-8 11:04:20

搞这么复杂干吗?   
这样不就行了?
Window SetContext, "WindowTag=WEBBrowser", ""
Window CloseWin, "", ""

djw1999 发表于 2005-3-8 11:54:32

谢谢各位朋友这么帮助,谢谢拉~!!

pcl2004_27 发表于 2005-3-8 12:58:12

其实 不同的环境需要不同的解决方式

楼上的解决方法也可以,不过关闭IE,不能从根本上关闭,
楼主的问题我觉得根本解决,杀死进程才是最好的解决方法!
如果进程不杀死,又可能造成资源泄漏,如果在多次启动之后会出现脚本执行不下去的情况
当然我说的是特例!欢迎大家讨论

司空公子 发表于 2005-3-8 13:32:38

呵呵,关闭一个IE居然有这么多情况,开阔眼界了。
页: [1]
查看完整版本: 帮忙~!startbrowser打开IE,然后我要关闭IE,用什么命令啊?