Results 1 to 4 of 4

Thread: Several Dumb Questions...

  1. #1

    Thread Starter
    Addicted Member Mage33's Avatar
    Join Date
    Aug 2000
    Location
    Petaluma, California
    Posts
    138

    Unhappy

    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
    Stephen Haney- 115 116 101 118 101 31 72 65 78 69 89
    -ShardsOfSilence.net- ^ My name in ASCII ^
    You forget something new every day
    | WinME | VB6 Pro | MSC++ | Lambda MOO |

  2. #2
    Guest
    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

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    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.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    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]
    ~seaweed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width