Solved

checking what applications are currently open and opening a file in a different application from vb

Posted on 2003-11-05
13
177 Views
Last Modified: 2010-05-03
ok, i want to check what applications are currently open (like when you ctrl-alt-delete).

i'd also like to know how i would open a file in a different application, for example, opening a wma file in windows media player, or a playlist file in musicmatch jukebox.

the reason for this is that i'm making a program that will turn my music off at a selected time, and then reopen the program and start my music playing again
0
Comment
Question by:hazgod
13 Comments
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 84 total points
ID: 9691956
This will give you a list of all running process:
http://www.thescarms.com/VBasic/RunningProcs.asp

This will list the one as if you press ALT+TAB
http://www.thescarms.com/VBasic/alttab.asp

you can use shellexecute to open the program and passing the wma file name as filename

~ fantasy ~
0
 
LVL 5

Assisted Solution

by:g0rath
g0rath earned 83 total points
ID: 9691966
two questions:

1st:

This takes a little effort, so another expert has it written better than I could

http://beta.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20684555.html

2nd:

result = shell("c:\program files\whatever" & path2File2Load, vbnormalfocus)

or use the win32 api to open a file with the default viewer

ShellExecute hwnd, "open", "C:\acrobat3\reader\acrobat.pdf", vbNullString, "C:\", 1
- this will open the pdf file, and if you have acrobat installed it will launch it to run your file

this will take a little work to get up first

Public 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


0
 
LVL 5

Assisted Solution

by:jayeshshah
jayeshshah earned 83 total points
ID: 9692276
Hi

1. To get a list of all the processes running on your machine.
Dim strWinMgt As String
Dim process As Object
Dim objProc As Object
Dim ComName As String
ComName = "YourComputername"

strWinMgt = "winmgmts://" & ComName & ""
Set objProc = GetObject(strWinMgt).ExecQuery("Select * from Win32_Process")
For Each process In objProc
   List1.additem process.Name      
Next


2. to open a file in a different application you need to know the path of that application
like for e.g. you want to open a file "d:\test.txt" with Word then you can do it as

Ret_Val = shell("winword.exe d:\test.txt" , vbnormalfocus)


K'Regards

Jayesh



0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:hazgod
ID: 9692534
i'd like the program names in a list, like "Outlook" or something like that.

so the application title as opposed to the application process (Outlook, not outlook.exe)


i still cannot get it to open a file with a different program.
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9692585
The link I gave you:

This will give you a list of all running process:
http://www.thescarms.com/VBasic/RunningProcs.asp

This will list the one as if you press ALT+TAB
http://www.thescarms.com/VBasic/alttab.asp

You have to do some string manipulation with the title.
Even if we open the Task Manager, Windows also didn't show the string that you mentioned.

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function ShellExecute Lib "shell32" _
    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 As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWDEFAULT As Long = 10
Private Const SE_ERR_NOASSOC As Long = 31
Public Sub RunShellExecute(sTopic As String, _
                           sFile As Variant, _
                           sParams As Variant, _
                           sDirectory As Variant, _
                           nShowCmd As Long)
   Dim hWndDesk As Long
   Dim success As Long
 
  'the desktop will be the
  'default for error messages
   hWndDesk = GetDesktopWindow()
 
  'execute the passed operation
   success = ShellExecute(hWndDesk, sTopic, sFile, sParams, sDirectory, nShowCmd)

  'This is optional. Uncomment the three lines
  'below to have the "Open With.." dialog appear
  'when the ShellExecute API call fails
  'If success = SE_ERR_NOASSOC Then
  '   Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile, vbNormalFocus)
  'End If
End Sub

' to open the default program for playing
Call RunShellExecute("Play", "my.mp3", 0&, 0&, SW_SHOWNORMAL)




0
 
LVL 9

Expert Comment

by:Dang123
ID: 9694004
Listening
0
 
LVL 1

Author Comment

by:hazgod
ID: 9694373
that works if i split at "-" for programs like Microsoft Outlook, but then if i try to close internet explorer, it doesn't work
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9697898
What is the method you use to close the Window (any program)?
If you have the full title of the window, then to close the window

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"

function closeit(mycaption as string)
    Dim WinWnd As Long, RetVal As Long, lpClassName As String
    'Search the window
    WinWnd = FindWindow(vbNullString, mycaption)
    If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    ShowWindow WinWnd, SW_SHOWNORMAL
    'Create a buffer
    lpClassName = Space(256)
    'retrieve the class name
    RetVal = GetClassName(WinWnd, lpClassName, 256)   'no necessary
    'Post a message to the window to close itself
    PostMessage WinWnd, WM_CLOSE, 0&, 0&
end function

usage:
closeit("blabla - Microsoft Internet Explorer")
0
 
LVL 1

Author Comment

by:hazgod
ID: 9711970
i'm just using some api i found to close the program. just have to send (Outlook) to the api. about opening a file in a different program, i just found out that musicmatch has an 'alarm' feature that starts a playlist going at a set time so i can't be bothered to do it myself.

can just set the musicmatch alarm and then tell my program to close musicmatch at a certain time.

cheers for the help tho guys
0
 
LVL 1

Author Comment

by:hazgod
ID: 10350164
i posted my solution in the last post.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question