How do i check is some random program is running with VB6? I want to make a program that detect if a program is running if not open it and if i close the program shall it be reopened. is that eaven possible or am i hoping on to much.
msn and skype i just want to make them reopen when i close them but i dont know how to make that i think i shall put some code in a timer.
Why you want to do that...????
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
i just want them to reopen if they crash or something
Why don't you open it manually, on crashing...???
Could you explain the situation...???
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
I am making like a console to open some of the games i am playing and i want to reopen msn and skype if the crash becuse i am lazy and want to have a program to do that for me.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
i just want to have the window down but the program running and a timer that check if it is running every secound but i dont know how to make the timer check i just know how the timer start the program. if it gets turned off the program will reopen it within a secound but right now the program atemts to open a new copy of it every secound
Last edited by Healingbot; Feb 17th, 2010 at 08:11 AM.
Reason: wrote some things wrong
Requirements
As far as I understood you intented to check if a process/program is running and if it is not then you want to start it.
To check if a process/program is running you need to make a snapshot of the current processes and iterrate through them.
You will need the following APIs for that:
CreateToolhelp32Snapshot
Process32First
Process32Next
CloseHandle
You also will need the type structure "ProcessEntry32".
To run a process you use the Shell command as previously stated.
Please note this solution is my personal preference as I do not like using other API functions such as FindWindow or similar as using the name of a window is not as reliable as using the name of the actual process you are looking for. Again, that is simply my personal preference my own oppinion and does not reflect best practice or standards.
Solution
In the attached demo I have a main form with 2 textboxes and a button to allow you to specify the name and the full file path of the process/program you want to check/re-start.
In my Demo I use "Notepad.exe" and "c:\windows\SYSTEM32\notepad.exe".
The button simply executes the code and either starts Notepad or tells you if its running.
Change the values on the form as required.
I added a module "ProcessController.bas" which contains the code to iterrate through the processes and poppulates a Process object with the results.
I added a classobject "Process.cls", which represents a single process and will contain the process data.
Samples
The key-code which gets the process data:
VB Code:
'/// <summary>
'/// Retrieves the data of a process by the specified name.
'/// </summary>
'/// <param name="myProcessName">The name of the process to get the data for.</param>
'/// <param name="myProcess">The Process object to populate with the data.</param>
'/// <remarks>
'/// The myProcess parameter is a reference and will be updated with the results.
'/// If a match was found the myProcess.IsRunning property will be True.
'/// If not match was found of an error occurred, the myProcess.IsRunning property will be False.
'/// </remarks>
Public Sub GetProcessByName(ByVal myProcessName As String, ByRef myProcess As Process)
MsgBox "Process (" & myProcessFileName & ") is allready running."
End If
End Sub
Download the attachment for the full demo.
Modify the code to your needs.
The APIs will work on Windows95, 98, 2000 and XP but not on Windows NT.
I don't know if they work on VISTA or Windows 7.
I hope this helps.
If it did, please rate my Post.
Edit
Feel free to add a "Start" method to the Process object which will execute the shell command for you, using it's own properties.
Thus when needing to start the process all you do is myProcess.Start.
As the class object has all the required properies populated it will work and it's the proper way of writing the code as well.
Last edited by Optional; Feb 17th, 2010 at 11:11 AM.
Kind Regards,
Optional
If you feel this post has helped in answering your question please return the favour and Rate this post.
If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.