Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1005
  • Last Modified:

Set Windows Process Priority through VB?

Hello,

Is there a way to set a windows process priority through VB (lower/higher its priority)?

What if there are two processes with the same name?
For example, two instances of ms word (winword)?

Thanks,
Rick
0
Rick
Asked:
Rick
  • 3
  • 2
1 Solution
 
MatthiasVanceCommented:
Are you using VB6 or .NET?

Kind regards,

Matthias Vance
0
 
RickAuthor Commented:
I'm using VB 08, but I will take the answer in any version.

Thanks,
Rick
0
 
MatthiasVanceCommented:
Here's some example code, I hope it helps you.

Kind regards,

Matthias Vance
    Private Sub SetProcessPriority(ByVal processName As String, ByVal priority As ProcessPriorityClass)
        Dim pl() As Process = Process.GetProcessesByName(processName)
        For Each p As Process In pl
            p.PriorityClass = ProcessPriorityClass.High
        Next
    End Sub

Open in new window

0
 
MatthiasVanceCommented:
Updated code.
    Private Sub SetProcessPriority(ByVal processName As String, ByVal priority As ProcessPriorityClass)
        Dim pl() As Process = Process.GetProcessesByName(processName)
        For Each p As Process In pl
            p.PriorityClass = priority
        Next
    End Sub
 
SetProcessPriority("calc", ProcessPriorityClass.High)

Open in new window

0
 
RickAuthor Commented:
Excellent job!

Thank you,
Rick
0

Featured Post

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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now