| View previous topic :: View next topic |
| Author |
Message |
cildor666 Advanced Cheater
Reputation: 0
Joined: 08 Mar 2008 Posts: 95
|
Posted: Tue Sep 23, 2008 12:40 pm Post subject: [Visual Basic help needed]. |
|
|
I have created a program and made a label that says 'Status :' next to it says 'Program not running' I want to make it so that when i make the program opens CMD it changes the label text to 'Program running'. I know how to change the text but how do i make it so that the program detects when CMD is open or not?
Help is appreciated.
|
|
| Back to top |
|
 |
Cryoma Member of the Year
Reputation: 198
Joined: 14 Jan 2009 Posts: 1819
|
Posted: Tue Sep 23, 2008 12:47 pm Post subject: |
|
|
scan for process cmd.exe
If it's true then status.text ="Program Running"
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Sep 23, 2008 12:51 pm Post subject: |
|
|
FindWindow
or
CreateToolhelp32Snapshot
Process32First
Process32Next
|
|
| Back to top |
|
 |
Cryoma Member of the Year
Reputation: 198
Joined: 14 Jan 2009 Posts: 1819
|
Posted: Tue Sep 23, 2008 12:53 pm Post subject: |
|
|
| Wow all these years I've been doing things unnecessarily complicated.
|
|
| Back to top |
|
 |
cildor666 Advanced Cheater
Reputation: 0
Joined: 08 Mar 2008 Posts: 95
|
Posted: Tue Sep 23, 2008 1:10 pm Post subject: |
|
|
| slovach wrote: | FindWindow
or
CreateToolhelp32Snapshot
Process32First
Process32Next |
I don't understand the bottom way, and i'm using visual basic 2008 express edition so i don't think the 'FindWindow' command exists. I was thinking of something like 'If process "cmd" = running Then label1.text = Program running' I know that command doesn't exist but i need something like that.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Sep 23, 2008 1:19 pm Post subject: |
|
|
| cildor666 wrote: | | slovach wrote: | FindWindow
or
CreateToolhelp32Snapshot
Process32First
Process32Next |
I don't understand the bottom way, and i'm using visual basic 2008 express edition so i don't think the 'FindWindow' command exists. I was thinking of something like 'If process "cmd" = running Then label1.text = Program running' I know that command doesn't exist but i need something like that.  |
pinvoke, then call it.
or do it the managed way, which is probably smarter since you're using .NET
Look at the System.Diagnostics.Process class.
The GetProcessesByName method will be of use.
http://msdn.microsoft.com/en-us/library/z3w4xdc9.aspx
|
|
| Back to top |
|
 |
cildor666 Advanced Cheater
Reputation: 0
Joined: 08 Mar 2008 Posts: 95
|
Posted: Tue Sep 23, 2008 1:56 pm Post subject: |
|
|
| But i want to type it into the form code, so its like 'If Process("CMD") = running then Label1.Text = "Program Running" - Something similar.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Sep 23, 2008 2:39 pm Post subject: |
|
|
How about you actually try reading the article?
It returns a process array, can you guess what happens when there's no match?
The array is empty.
|
|
| Back to top |
|
 |
Fuzz Grandmaster Cheater
Reputation: 0
Joined: 12 Nov 2006 Posts: 531
|
Posted: Tue Sep 23, 2008 6:33 pm Post subject: |
|
|
Just use the API FindWindow, not sure if you can in VB, but yeah. Then just see if the HWND finwwindow == 1. Not sure to the VB equivilant.
_________________
|
|
| Back to top |
|
 |
Polynomial Grandmaster Cheater
Reputation: 5
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
|
Posted: Tue Sep 23, 2008 7:01 pm Post subject: |
|
|
Simple way to do it in VB.NET:
| Code: | Public Function IsApplicationRunning(ByVal ApplicationName As String) As Boolean
Return System.Diagnostics.Process.GetProcessesByName(ApplicationName).Length > 0
End Function |
Note that you call this method with the friendly name of the executable - so you would do IsApplicationRunning("cmd") not IsApplicationRunning("cmd.exe"). The >0 part at the end of the Return line basically checks if any processes were found that match the name you specified and if so, return true (else return false).
If you want it in C# for whatever reason:
| Code: | public bool IsApplicationRunning(string ApplicationName)
{
return System.Diagnostics.Process.GetProcessesByName(ApplicationName).Length > 0;
} |
|
|
| Back to top |
|
 |
|