Close Applications in VBA code

BOGIA

Active Member
Joined
May 23, 2005
Messages
266
Hi all,

I use "SHELL" to open applications but am stuck with closing them down. Any help would be very much appreciated.

cheers,
bogia
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi Bogia. In what regard are you utilizing these apps? For example, are you running an application to perform some specific task and then wishing to close it after it has completed? In other words... would it be appropriate to start an application, wait for it to complete some task, and then close it???
 
Upvote 0
Hi Tom,

Thanks for your reply.

I have to use all applications that I have every month, eg: word, access, acrobat adobe, adobe photoshop elements etc... Otherwise, my profile will be changed by the IT team. It means, I'll have to ask them to re-install the application again. Sometimes, I just miss using the some applications for a few days and I lost them (the IT team took it away from me).

Therefore I need to set open them every month and make it like I have been using the applications. It takes little bit of time to manually open and close about 15 applications at once.

cheers,
bogia
 
Upvote 0
bogia

Do you really need code to do this?

Can't you just set up shortcuts to each application, select all the shortcuts, open all of them and then close them?

That might seem like a hassle but it would be a one time deal to create the shortcuts and a monthly deal to open/close the applications.

Mind you I would look into/question the IT department's methods.

Removing a user's ability to access certain applications based on usage on a monthly basis seems a bad idea.

Doesn't it cut down on productivity?

It might also not be too healthy for the whole system uninstalling/reinstalling things all the time.:)
 
Upvote 0
Hi Norie,

I agree with you 100%. We have suggested the idea but no luck.

The IT section is controlling everything here.

This is what I have to open my applications:

Sub Open_Applications()

Shell ("C:\Program Files\Nero\Nero 7\Core\NERO.exe")
Shell ("C:\Program Files\Adobe\Acrobat 8.0\Acrobat Elements\Acrobat Elements.exe")
Shell ("C:\Windows\System32\MSPAINT.exe")
Shell ("POWERPNT")
Shell ("MSACCESS")
Shell ("WINWORD")

End Sub

cheers,
bogia
 
Upvote 0
Loop for each program name. i.e.

Code:
KillProcess("AcroRd32.exe")

Code:
'-------------------------------------------------------
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
'-------------------------------------------------------
Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, _
ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long

Declare Function ProcessFirst Lib "kernel32.dll" Alias "Process32First" (ByVal hSnapshot As Long, _
uProcess As PROCESSENTRY32) As Long

Declare Function ProcessNext Lib "kernel32.dll" Alias "Process32Next" (ByVal hSnapshot As Long, _
uProcess As PROCESSENTRY32) As Long

Declare Function CreateToolhelpSnapshot Lib "kernel32.dll" Alias "CreateToolhelp32Snapshot" ( _
ByVal lFlags As Long, lProcessID As Long) As Long

Declare Function TerminateProcess Lib "kernel32.dll" (ByVal ApphProcess As Long, _
ByVal uExitCode As Long) As Long

Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
'-------------------------------------------------------

Public Sub KillProcess(NameProcess As String)
Const PROCESS_ALL_ACCESS = &H1F0FFF
Const TH32CS_SNAPPROCESS As Long = 2&
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
Dim WinDirEnv As String
        
       If NameProcess <> "" Then
          AppCount = 0

          uProcess.dwSize = Len(uProcess)
          hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
          RProcessFound = ProcessFirst(hSnapshot, uProcess)
  
          Do
            i = InStr(1, uProcess.szexeFile, Chr(0))
            SzExename = LCase$(Left$(uProcess.szexeFile, i - 1))
            WinDirEnv = Environ("Windir") + "\"
            WinDirEnv = LCase$(WinDirEnv)
        
            If Right$(SzExename, Len(NameProcess)) = LCase$(NameProcess) Then
               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 While RProcessFound
          Call CloseHandle(hSnapshot)
       End If

End Sub
 
Upvote 0
"Removing a user's ability to access certain applications based on usage on a monthly basis seems a bad idea."

Hi Norie. I bet it's a licensing issue. They may save on licensing.
 
Upvote 0
Tom

Do you think that's the case?

Do licences get sold/granted based on monthly usage?

I always thought it was on a kind of no of users basis.:)
 
Upvote 0
I don't know. I used to work for a large company and they were hesitant to allow installation of available applications. You had to jump through hoops.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top