Solved

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

Posted on 2014-02-14
5
551 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 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