Posted May 10, 200520 yr 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
May 10, 200520 yr 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!
May 10, 200520 yr Sorted it now thanks for your replys. It was easy really didnt need to use ShellExecute.I just did this instead.ChDir LM2ServerShell ("C:\mirserver\mir200\m2server.exe")Thanks again.Just proves how somethings are so simple yet i never think of them.
May 11, 200520 yr 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.
May 19, 200619 yr The "Kill" function deletes the file. Don't use it unless you want to delete a file...obviously.
May 19, 200619 yr 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 LongPrivate Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As LongPrivate Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As LongPrivate Declare Function ProcessTerminate Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As Long, ByVal uExitCode As Long) As LongPrivate Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate 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 LongConst FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000Const LANG_NEUTRAL = &H0Const SUBLANG_DEFAULT = &H1Const TH32CS_SNAPHEAPLIST = &H1Const TH32CS_SNAPPROCESS = &H2Const TH32CS_SNAPTHREAD = &H4Const TH32CS_SNAPMODULE = &H8Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)Const TH32CS_INHERIT = &H80000000Const MAX_PATH As Integer = 260Const SW_SHOWNORM = 1Const SW_SHOWMIN = 2Const SW_SHOWMAX = 3Private Type ProcessInfo PName As String PID As Long iIndex As IntegerEnd TypePrivate 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_PATHEnd TypeDim 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 snapEnd 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 hereEnd SubPrivate Function StartProgram(ByVal sFilePath As String) Call ShellExecute(&O0, "Open", sFilePath, vbNullString, vbNullString, SW_SHOWNORM)End Function Edited May 19, 200619 yr by lorothrigs
Create an account or sign in to comment