• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 573
  • Last Modified:

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

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
FamousMortimer
Asked:
FamousMortimer
  • 2
1 Solution
 
Kalpesh ChhatralaSoftware ConsultantCommented:
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
 
FamousMortimerAuthor Commented:
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
 
CodeCruiserCommented:
There is a SetPriority method but it is an integer so you need to use a number as parameter.
0
 
FamousMortimerAuthor Commented:
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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