Hi,
I'm trying to make my program give a MsgBox as soon as there's a certain process on such as 'notepad.exe'. I tried something in the lines of: -
Dim process = System.Diagnostics.Process.GetProcessesByName("notepad")
-
-
If process = True Then
-
timer_checkforprocess.Enabled = False
-
MsgBox("blahblah", MsgBoxStyle.OkOnly)
-
End If
-
I've also been searching around on the web and this site. I either dont use the right keywords or the answer isn't there.
How could I get this to work ?
Also, currently it's within a timer with an interval of 100. Does this increase CPU usage/memory usage ? If yes, is there a way to make it use as less cpu as possible ?
Thanks in advance,
Evolution445
15 4077
Hi,
I'm trying to make my program give a MsgBox as soon as there's a certain process on such as 'notepad.exe'. I tried something in the lines of: -
Dim process = System.Diagnostics.Process.GetProcessesByName("notepad")
-
-
If process = True Then
-
timer_checkforprocess.Enabled = False
-
MsgBox("blahblah", MsgBoxStyle.OkOnly)
-
End If
-
I've also been searching around on the web and this site. I either dont use the right keywords or the answer isn't there.
How could I get this to work ?
Also, currently it's within a timer with an interval of 100. Does this increase CPU usage/memory usage ? If yes, is there a way to make it use as less cpu as possible ?
Thanks in advance,
Evolution445
i would set the timer at a less tick rate, such as 500 or 1000 or even less, depending on what your doing, and you could just use a simple for each statement such as... - Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
For Each myprocess In Process.GetProcesses
-
If myprocess.MainWindowTitle.Contains("Visual Basic") Then 'I only used this because i didnt have notepad running, notice the MainWindowTitle, there are other options such as just the ProcessName...
-
MsgBox("Found It")
-
-
End If
-
ListBox1.Items.Add(myprocess.ProcessName) 'Just adds all of the processes after done with the if statement, whether the if returns true or false...
-
Next
-
End Sub
this worked fine for me...
joedeene
I would think that your IF statement would always return false, since "process" would either be null(nothing) or an instance of the process object, and never a boolean.
And while I'm at it, if you're in VB.NET and not VB, you should be using the .NET constructs MessageBox.Show() and not MsgBox
And while I'm at it, if you're in VB.NET and not VB, you should be using the .NET constructs MessageBox.Show() and not MsgBox
I got both programs, VB2005 and VB.NET, I often confuse both and then my code gets mixed up. I meant VB.NET here.
Thanks joedeene, I now managed to work that out a little further by myself and its working :)
Thanks for the help.
You missed Plater's point. VB.NET and VB are different languages. Visual Studio.NET uses VB.NET 2003, Visual Studio 2005 uses VB.NET 2005.
MsgBox is a construct from classic VB 6 and older. You should use the .NET constructs whenever and wherever you can.
i apologize for the faulty code sample, i guess im already starting to pick up lazy habits of VB.net =(, but i was just showing a simple way to find the process name..
joedeene
Sorry to ask another thing related to this..
It now collects all processes inside a listbox, how would I make another messagebox display as soon as the same process appears in there twice or more ?
I thought something like this, but it just results in an error: -
If list_processes.Items.Count.CompareTo(process) = 2 Then
-
MessageBox.Show("You cannot have 2 instances of " & psname & " running at the same time!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)
-
Me.Close()
-
End If
-
well some processes run two instances if they have different ones open ? like what if they are running two internet explorer browsers ? (process name "iexplore.exe")
joedeene
Yes, if my listbox contains 2 processes that have exactly the same name, I want to close my program, I know how to close it with "Me.Close()", but how to figure out if there's 2 of the same name.. That's where I'm a little stuck right now.
well give a little more code sample fully of what you've got so far... i have to see how you are using your variables so i can know how to be of best help, i dont quite understand your code.
joedeene
I'm even having trouble understanding my own code. I've been busy for a few hours now on this little bit. I keep changing it, but it never seems to work, or .NET does different things than I want.
My first code is a few posts above here, this is my 2nd attempt: -
If list_processes.Items.Item(psname) = list_processes.Items.Count = 2 Then
-
MessageBox.Show("You cannot have 2 instances of " & psname & " running at the same time!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False) Me.Close()
-
End If
-
And just at the moment I'm thinking of something like this: -
Dim i, pscount As Integer
-
For i = 0 To list_processes.Items.Count - 1
-
pscount = list_processes.Items.Item(i).ToString.Contains(psname)
-
Next
-
If i = 2 Then
-
MessageBox.Show("You cannot have 2 instances of " & psname & " running at the same time!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)
-
Me.Close()
-
End If
-
The program I'm making is for a few games, and as soon as one of them has 2 windows open at the same time, I want my program to close. I thought the best way to find out if there's 2 instances running for that same game by checking the processlist, instead of using API FindWindow().
Evolution445
I'm even having trouble understanding my own code. I've been busy for a few hours now on this little bit. I keep changing it, but it never seems to work, or .NET does different things than I want.
My first code is a few posts above here, this is my 2nd attempt: -
If list_processes.Items.Item(psname) = list_processes.Items.Count = 2 Then
-
MessageBox.Show("You cannot have 2 instances of " & psname & " running at the same time!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False) Me.Close()
-
End If
-
And just at the moment I'm thinking of something like this: -
Dim i, pscount As Integer
-
For i = 0 To list_processes.Items.Count - 1
-
pscount = list_processes.Items.Item(i).ToString.Contains(psname)
-
Next
-
If i = 2 Then
-
MessageBox.Show("You cannot have 2 instances of " & psname & " running at the same time!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, False)
-
Me.Close()
-
End If
-
The program I'm making is for a few games, and as soon as one of them has 2 windows open at the same time, I want my program to close. I thought the best way to find out if there's 2 instances running for that same game by checking the processlist, instead of using API FindWindow().
Evolution445
something as simple as this worked for me, but you'd have to ignore certain processes running two or more instances, such as system services/processes.
code. - For Each proc In Process.GetProcesses
-
If ListBox1.Items.Contains(proc.ProcessName) Then
-
MessageBox.Show("Process '" & proc.ProcessName & "' Running To Or More Instances")
-
End If
-
ListBox1.Items.Add(proc.ProcessName)
-
-
Next
this code checks to see if the process name already exists before adding it to the listbox, now after messagebox.show(), place a me.close if necessary for you, but is this what you were looking for ?
It's rather like, if it appears in the listbox 2 times, a duplicate item. Then I want to close my program and give a messagebox. But I don't know if that's actually possible ?
I'm just stuck at the bit where to check if the same item appears twice or more times in the listbox.
It's rather like, if it appears in the listbox 2 times, a duplicate item. Then I want to close my program and give a messagebox. But I don't know if that's actually possible ?
I'm just stuck at the bit where to check if the same item appears twice or more times in the listbox.
yes if the *ProcessName* appears in the listbox already, before adding the *ProcessName* it will check to see if the listbox contains the process name, you can also do many other options from the proc, like when you open notepad twice, you will notice 'notepad.exe' is listed there twice ? it will check for the Processes Name, not the main window title, such as 'Untitled - Notepad'.... ?
joedeene
I tried your code, but now the message pops up everytime as there is a duplicate going in the listbox, but it should only be giving the warning for a few certain processes. I now have something like this: -
For Each ps In Process.GetProcesses()
-
Dim processname As String
-
If list_processes.Items.Contains(ps.ProcessName.Contains(processname)) Then
-
timer_checkforprocess.Enabled = False
-
MessageBox.Show("Error!")
-
Me.Close()
-
End If
-
list_processes.Items.Add(ps.ProcessName)
-
-
Next
-
But this doesnt result in anything
I tried your code, but now the message pops up everytime as there is a duplicate going in the listbox, but it should only be giving the warning for a few certain processes. I now have something like this: -
For Each ps In Process.GetProcesses()
-
Dim processname As String
-
If list_processes.Items.Contains(ps.ProcessName.Contains(processname)) Then
-
timer_checkforprocess.Enabled = False
-
MessageBox.Show("Error!")
-
Me.Close()
-
End If
-
list_processes.Items.Add(ps.ProcessName)
-
-
Next
-
But this doesnt result in anything
well ya ? when you said - Dim processname As String
you never set a value for the processname variable to search for, so its returning null, unless you left that part out of your code you posted?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Terry |
last post by:
Hi, I need some feedback.
We are converting to .Net and we are trying to decide on whether to use
VB.net or C#.net.
As far as our current systems, they will probably be rewritten in ASP.Net.
I...
|
by: Arsalan |
last post by:
Is there any advantage in C# over VB.NET ? Or the difference is only syntax
? Can anything done in C# which cannot be done in VB.NET?
|
by: Robin Tucker |
last post by:
I need to find some documents/research for my manager about VB.NET v C# use.
I've noticed that there are many more people using C# than VB.NET, that
there seem to be more job vacancies specifying...
|
by: Andy |
last post by:
Any good resources regarding benefitis by using C3 over VB?
/Andy
|
by: Jim Hubbard |
last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
|
by: lonelyplanet |
last post by:
Hi,
I'm studying for 70-306 using the book "MCAD/MCSD Visual Basic .NET
Windows Applications" published by McGraw Hill (ISBN: 0-07-212583-7).
I found the book has no programming exercise...
|
by: clintonG |
last post by:
This is not about starting a fight but an observation that seems to be
proving itself on its own merit and is therefore simply a point of
conjecture.
I did not get serious about writing software...
|
by: zacks |
last post by:
A co-worker where I work is proposing all future code devopment be done
in Visual C#. Here is his assessment of VB:
VB.NET is hack as far as the CLR(Common Language Runtime) goes. It was...
|
by: John Smith |
last post by:
Can someone convert from C# into VB this line for me:
if (c is System.Web.UI.HtmlControls.HtmlForm)
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |