Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Authentication of Web Services 3 49
DataGridView Events ? 3 37
Close tabpage of custom control 9 23
How can my static class become undefined?? 8 13
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

16 Experts available now in Live!

Get 1:1 Help Now