Solved

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

Posted on 2003-11-05
13
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 5 hours left to enroll

636 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