Solved

VB.NET - How to set priority of process on remote computer using WMI

Posted on 2014-02-14
5
556 Views
Last Modified: 2014-02-19
I am having a hell of a time finding this on Google so I am hoping someone can help me out.  Here is the code I was trying to use but I can't figure out how to set the priority.  I feel like I need to use the InvokeMethod on the ManagementObject but I cannot find anywhere on MSDN what possible methodnames are available.  Maybe I am going about this all wrong.  Please help me out.

    Public Sub SetPriority(ByVal c As Client)
        Try
            Dim conOptions As New ConnectionOptions
            With conOptions
                .Username = myusername
                .Password = mypassowrd
            End With
			
            Dim ManagementScope As New ManagementScope("\\" & c.HostName & "\root\cimv2")
            ManagementScope.Options = conOptions

            Dim query As New Management.ObjectQuery(String.Concat("select * from Win32_Process where name = '", processname, "'"))

            Using searcher As New ManagementObjectSearcher(ManagementScope, query)
                For Each Process As ManagementObject In searcher.Get
                    'SET PRIORITY HERE
					'Process.InvokeMethod("SetPriority", {"Low"})
                Next
            End Using
        Catch ex As Exception
            debug.print(ex.message)
        End Try
    End Sub

Open in new window

0
Comment
Question by:FamousMortimer
[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
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 39861358
try like below

Const ABOVE_NORMAL = 32768
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcesses
    objProcess.SetPriority(ABOVE_NORMAL) 
Next

Open in new window

0
 
LVL 10

Author Comment

by:FamousMortimer
ID: 39861893
That is vbscript and for the local computer.

Can anyone help with vb.net.  I don't there there is much to change in the code I provided.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39870352
There is a SetPriority method but it is an integer so you need to use a number as parameter.
0
 
LVL 10

Author Closing Comment

by:FamousMortimer
ID: 39871754
Thank you.  That brought me here which solved my problem.  I had to change 4 characters in the code provided... {LOW} to {&H40}
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

726 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