Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2004
    Posts
    6

    Unanswered: Shell Copmmand and Close/Exit

    Hi all!

    I have a problem with a command.
    I started at program with the Shell command. For instance
    “Shell "C:\My program\ Program.exe", vbMaximizedFocus”
    And that work OK.
    But how could I close it, or Exit the program?
    Witch code do I have to use?

    Thank you for help!!!


    Edvard.

  2. #2
    Join Date
    Aug 2002
    Location
    Northampton, England
    Posts
    266
    DoCmd.RunCommand acCmdExit

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Shelled applications run asynchronously in their own thread. What are you doing exactly? If it's a command line utility that you need to execute and resume code execution after the utility has completed, I have something for you.

    If you need to find a way to close the thread prematurely, that's a little more difficult.


    Also, one thread per question please. I understand if you accidentally post ONE duplicate, but FOUR? Cut me a little slack here...
    Last edited by Teddy; 01-25-06 at 11:36.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Sep 2004
    Posts
    6
    Thank you for answering, Teddy!

    I have a “program.exe” witch I want to start when I am loading an Access Base.
    I use as I told, the shell command.

    When I am starting another mdb I want this “program.exe” witch I have started, to exit or close.
    The reason is that this “program.exe” is linked to an Access Base and when I want to change any thing in the design window for this base, I can not save these changes because the “program.exe” is locking (or cage, clamp) the base. To save the changes I have to exit/close the “program.exe”.

    I the Dos you use the EXIT command, can I do the same? And how?

    Thank you for answering!!

    Edvard.



    Quote Originally Posted by Teddy
    Shelled applications run asynchronously in their own thread. What are you doing exactly? If it's a command line utility that you need to execute and resume code execution after the utility has completed, I have something for you.

    If you need to find a way to close the thread prematurely, that's a little more difficult.


    Also, one thread per question please. I understand if you accidentally post ONE duplicate, but FOUR? Cut me a little slack here...

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    If program.exe is linked to an access database, why not have program.exe check for a yes/no value in your database to see if it should close at scheduled intervals?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  6. #6
    Join Date
    Sep 2004
    Posts
    6
    Quote Originally Posted by Teddy
    If program.exe is linked to an access database, why not have program.exe check for a yes/no value in your database to see if it should close at scheduled intervals?
    Teddy!

    The Program.exe is not an Access Program and is not a program I have made.
    It is a telephone monitor linked to my database so it can find the name of who is ringing.
    So therefore I have to close it by a DOS command or Shell command.

    Edvard

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I suppose you could use SendKeys with ctrl+c...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Does it have an exposed interface with perhaps a quit or close method? If so perhaps you could try getting hold of it using GetObject and invoking the quit\ close\ turn me off method.

    What is the exe - is it commercially available or something rustled up in house?
    Last edited by pootle flump; 01-27-06 at 12:01.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    I make no guarentees or anything about the below code. I found it in my "code nicked from t'interweb that might be worth looking at one day" bin under "Identify and End Process". I have not run, tested, read through (in much detail) or done anything to verify its effectiveness. Looking at it it uses API to list the processes, stick the results into a listbox on a form (you will need to provide these) and then cancels the selected proces on the press of the button (again provided by you).

    If it works then a little adaptation should be sufficient.

    Mind how you go....

    Code:
    Module Code:
    
    Option Explicit 
    
    Public Declare Function Process32First Lib "kernel32" ( _ 
      ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long 
    
    Public Declare Function Process32Next Lib "kernel32" ( _ 
      ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long 
    
    Public Declare Function CloseHandle Lib "Kernel32.dll" _ 
      (ByVal Handle As Long) As Long 
    
    Public Declare Function OpenProcess Lib "Kernel32.dll" _ 
     (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _ 
         ByVal dwProcId As Long) As Long 
    
    Public Declare Function EnumProcesses Lib "psapi.dll" _ 
      (ByRef lpidProcess As Long, ByVal cb As Long, _ 
         ByRef cbNeeded As Long) As Long 
    
    Public Declare Function GetModuleFileNameExA Lib "psapi.dll" _ 
      (ByVal hProcess As Long, ByVal hModule As Long, _ 
         ByVal ModuleName As String, ByVal nSize As Long) As Long 
    
    Public Declare Function EnumProcessModules Lib "psapi.dll" _ 
      (ByVal hProcess As Long, ByRef lphModule As Long, _ 
         ByVal cb As Long, ByRef cbNeeded As Long) As Long 
    
    Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" ( _ 
      ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long 
    
    Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long 
    
    Public 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 * 260 
    End Type 
    
    Public Const PROCESS_QUERY_INFORMATION = 1024 
    Public Const PROCESS_VM_READ = 16 
    Public Const PROCESS_TERMINATE = &H1 
    Public Const MAX_PATH = 260 
    Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 
    Public Const SYNCHRONIZE = &H100000 
    'STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF 
    Public Const PROCESS_ALL_ACCESS = &H1F0FFF 
    Public Const TH32CS_SNAPPROCESS = &H2& 
    Public Const hNull = 0 
    
    Function StrZToStr(s As String) As String 
       StrZToStr = Left$(s, InStr(s, vbNullChar) - 1) 
    End Function 
    
    Public Function TerminateProc(ByVal Process As Long) As Long 
       Dim Proc As Long 
       Proc = OpenProcess(PROCESS_TERMINATE, False, Process) 
       TerminateProc = TerminateProcess(Proc, 0) 
       Call CloseHandle(Proc) 
    End Function 
    
    Form code: 
    Code:
    Option Explicit 
    
    Private Type Process 
       ProcName As String 
       ProcFileName As String 
       ProcID As Long 
    End Type 
    
    Private Processes() As Process 
    
    Public Sub GetProcesses() 
       Dim i As Integer 
       Dim f As Long 
       Dim sName As String, sFileName As String 
       Dim hSnap As Long, Proc As PROCESSENTRY32 
       hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) 
       If hSnap = hNull Then Exit Sub 
       Proc.dwSize = Len(Proc) 
        
       lstProcesses.Clear 
       f = Process32First(hSnap, Proc) 
       Do While f 
           sFileName = StrZToStr(Proc.szExeFile) 
           sName = Right$(sFileName, Len(sFileName) - InStrRev(sFileName, "\")) 
            
           ReDim Preserve Processes(i) As Process 
           Processes(i).ProcID = Proc.th32ProcessID 
           Processes(i).ProcFileName = sFileName 
           Processes(i).ProcName = sName 
            
           lstProcesses.AddItem Processes(i).ProcName 
            
           f = Process32Next(hSnap, Proc) 
           i = i + 1 
       Loop 
    End Sub 
    
    Private Sub cmdEndProcess_Click() 
       If lstProcesses.ListIndex <> -1 Then 
           Dim RetVal As Long 
           Dim Proc As Process 
            
           Proc = Processes(lstProcesses.ListIndex) 
           If MsgBox("Are you sure you want to end the process '" & Proc.ProcName & "'?", vbYesNo + vbQuestion) = vbYes Then 
               RetVal = TerminateProc(Proc.ProcID) 
               If RetVal = 1 Then lstProcesses.RemoveItem lstProcesses.ListIndex 
           End If 
       End If 
    End Sub 
    
    Private Sub Form_Load() 
       GetProcesses 
    End Sub 
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) 
       If UnloadMode <> vbFormCode Then ExitProgram 
    End Sub
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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