-
Ok, first of all how do you terminate a program with the push of a button?
How do you launch a program independant of yours (if you know the path)
And last of all, is there any way to give the ie web browser a pre set background to use if one's not specified? I'm doing virtual desktops and I'd like to be able to add backgrounds.
Thanks
-
Q1:
If you want to close an application by knowing it's exe file path name:
Code:
Private Declare Function ProcessFirst Lib "kernel32" _
Alias "Process32First" (ByVal hSnapshot As Long, uProcess _
As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" _
Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As _
PROCESSENTRY32) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" _
Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, _
lProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal _
dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * MAX_PATH
End Type
Public Function KillApp(myName As String) As Boolean
Const PROCESS_ALL_ACCESS = 0
Dim uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim hSnapshot As Long
Dim szExename As String
Dim exitCode As Long
Dim myProcess As Long
Dim AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error GoTo Finish
appCount = 0
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szexeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
If Right$(szExename, Len(myName)) = LCase$(myName) Then
KillApp = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = ProcessNext(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function
Usage
Call KillApp("C:\program.exe")
Q2:
Use the Shell function.
Code:
Shell "C:\program.exe", 1
Or you can use the ShellExecute API function to launch a file with it's associated application.
Code:
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 Long
Private Const SW_SHOWNORMAL = 1
Usage
ShellExecute Me.hwnd, vbNullString, "C:\program.exe", _
vbNullString, "c:\", SW_SHOWNORMAL
-
1.
Code:
Private Sub Command1_Click()
dim f as Form
For Each f in Forms
Unload f
Next f
End sub
2.
Code:
Shell "C:\Windows\Notepad.exe"
3. Not sure what exactly you are asking, but don't think I would know the answer anyway. ;)
-
1. to terminate a program with the push of a button:
In the click event of the button:
Code:
Dim MyForm as Form
For each MyForm in Forms
Unload MyForm
Set MyForm = Nothing
Next ' MyForm
2. to launch a program independent of yours:
Code:
Shell ("application_path_and_name")
Shell ("C:\WINNT\system32\Notepad.exe")
2b. to launch a file with a program
Code:
Shell ("file_path_and_name application_path_and_name")
Shell ("C:\My Documents\MyFile.txt C:\WINNT\system32\Notepad.exe")
Don't know about #3
Hope that helps!
[Edited by seaweed on 01-04-2001 at 08:40 PM]