Jump to content
Tuts 4 You

Vb6 Help


Guest Rhys2002

Recommended Posts

Guest Rhys2002

Any ideas how i can close exe's down when opened with shellexecute.

Or is there another way i can open and close these exe's but keep the default exe directory path.

Thanks again

Link to comment
Guest Chaser

currently i don't have much time. but this is how it works: the shellexecute is able to give you back the handle of the started program:

my_handle = shellexecute ....

with this Handle you are able to shutdown the program!! do a google on handle + visual basic + exit - you will propably suceed - if not i have to look into it once more - may however take some days!

Link to comment
Guest Rhys2002

Sorted it now thanks for your replys. It was easy really didnt need to use ShellExecute.

I just did this instead.

ChDir LM2Server

Shell ("C:\mirserver\mir200\m2server.exe")

Thanks again.

Just proves how somethings are so simple yet i never think of them.

Link to comment
Guest Rhys2002

Yes i did, but i could shutdown with normal SHELL command but couldnt figure out how to get the exe to run from the exe directory and not from the vb project directory.

Thats why i went to shellexecute command.

Sorry if im confusing u here.

Link to comment
  • 11 months later...
  • 3 weeks later...
Guest lorothrigs

ugh...why is editing disabled for me?

Anyways, here's something I made to help you.

Option ExplicitPrivate Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessTerminate Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode 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 Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
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
Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Const LANG_NEUTRAL = &H0
Const SUBLANG_DEFAULT = &H1
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)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
Const SW_SHOWNORM = 1
Const SW_SHOWMIN = 2
Const SW_SHOWMAX = 3Private Type ProcessInfo
PName As String
PID As Long
iIndex As Integer
End Type
Private 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
Dim Process(99999) As ProcessInfoPrivate Sub cmdKillProcesses_Click()
Dim i As Long
Dim TheLoopingProcess
Dim proc As PROCESSENTRY32
Dim snap As Long
snap = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0)
proc.dwSize = Len(proc)
TheLoopingProcess = Process32First(snap, proc)
i = -1
While TheLoopingProcess <> 0
i = i + 1
Process(i).PName = Left$(proc.szExeFile, IIf(InStr(1, proc.szExeFile, Chr$(0)) > 0, InStr(1, proc.szExeFile, Chr$(0)) - 1, 0))
Process(i).PID = proc.th32ProcessID
Process(i).iIndex = i
TheLoopingProcess = Process32Next(snap, proc)
If Process(i).PName = "explorer.exe" Then KillProcessById (Process(i).PID) 'Files to kill here
Wend
CloseHandle snap
End SubPublic Sub KillProcessById(p_lngProcessId As Long)
Dim lnghProcess As Long
Dim lngReturn As Long
lnghProcess = OpenProcess(1&, -1&, p_lngProcessId)
lngReturn = ProcessTerminate(lnghProcess, 0&)
End SubPrivate Sub cmdStartProcesses_Click()
StartProgram ("C:\WINDOWS\explorer.exe") 'File Path here
End SubPrivate Function StartProgram(ByVal sFilePath As String)
Call ShellExecute(&O0, "Open", sFilePath, vbNullString, vbNullString, SW_SHOWNORM)
End Function
Edited by lorothrigs
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...