Solved

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

Posted on 2014-02-14
5
542 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
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 …
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now