Handy Process Management Utilities

Hey guys,

I just wanted to share a couple of cool utilities to assist with managing processes.

ImageCFG (http://www.robpol86.com/index.php/ImageCFG)

ImageCFG is a utility that lets you tweak the CPU affinity of an executable. What does this mean? Well, if you have a multi-core system, or even a hyper-threaded (virtual multi-core) system, you can restrict which cores a process can execute on. This may be desirable if there is a program that tends to hog processor time, such as a video editing application, and you want to allow it to run, but only on a restricted set of resources.

Prio (http://www.prnwatch.com/prio.html)

Although I haven’t used Prio yet, it looks to be a great, free (for personal use) program. A couple of features it offers are:

  • Save process priority settings – useful if there’s a program you always want to run in low priority / background mode
  • Always elevate certain processes – maintain good security with UAC, and convenience at the same time!
  • TCP / IP task manager tab – lets you view open network connections in real-time through task manager

——————————————

I had a need for a piece of the Prio tool, but didn’t need the entire toolset (or be able to use it freely for commercial use), so I wrote a small C# utility called “SetProcessPriority” that does just what I need it to, instead. This utility searches for a process by it’s friendly name (eg. ‘notepad‘, but without the ‘.exe’) every 2 seconds, and sets the process’ priority to “Below Normal.” This was necessary to server as a work-around to a software bug I was having with the Microsoft ConfigMgr console.

Here is the C# code for it:

using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

namespace SetProcessPriority
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1) return;

            string procname = args[0];
            while (1 == 1)
            {
                try
                {
                    Process[] procs = Process.GetProcessesByName(procname);
                    foreach (Process proc in procs)
                    {
                        proc.PriorityClass = ProcessPriorityClass.BelowNormal;
                    }
                }
                catch { }
                Thread.Sleep(2000);
            }
        }
    }
}

You can compile the above code in Visual Studio 2008, targeting the .NET 2.0 framework. Once you’ve compiled it into a .NET assembly, you can simply write a batch script to call it, like this:

SetProcessPriority notepad

———————————————-

Anyway, I hope this post helps someone out, out there!

Merry Christmas to all!

PowerShell: Allowing all file exts. for ConfigMgr

When running Configuration Manager 2007 on Windows Server 2008, you must enable certain file extensions in IIS, so that a BITS-enabled distribution point (DP) can transfer files correctly. See this Technet article for more information.

If you would like to enable all of the file extensions on a BITS-enabled DP, simply run the following PowerShell code:

function EnableAllExtensions()
{
    $ahPath = "$((Get-WmiObject Win32_OperatingSystem).SystemDirectory)inetsrvconfigapplicationHost.config"
    if (-not [IO.File]::Exists($ahPath)) { return } # If file doesn't exist, return
    $xd = New-Object Xml.XmlDocument
    $xd.Load($ahPath)
    $nodes = $xd.SelectNodes("/configuration/system.webServer/security/requestFiltering/fileExtensions/add")
    foreach ($child in $nodes)
    {
        $child.SetAttribute("allowed", "true")
    }
    $xd.Save($ahPath)
}

. EnableAllExtensions


Hope this helps!

Don’t forget to make your WebDAV configuration edits using PowerShell also!

PowerShell: Making WebDAV Configuration Edits on Server 2008

If you’re configuring a Windows Server 2008 system to be a ConfigMgr site system, you may have noticed that you need to make some changes to the WebDAV configuration in IIS. Unfortunately, making those changes through the IIS GUI doesn’t always work quite right. Instead of digging around inside of an XML file though, you can simply run a PowerShell script to take care of it!

function FixWebdavConfig()
{
    $xd = New-Object System.Xml.XmlDocument # create new, empty XmlDocument
    $xd.Load("C:WindowsSystem32inetsrvconfigschemaWEBDAV_schema.xml") # Load XML content. returns void, so no need to cast void

    $node = $xd.SelectSingleNode("//attribute[@name='allowAnonymousPropfind']")
    $node.defaultValue = "true"
    $node = $xd.SelectSingleNode("//attribute[@name='allowInfinitePropfindDepth']")
    $node.defaultValue = "false"
    $node = $xd.SelectSingleNode("//attribute[@name='allowCustomProperties']")
    $node.defaultValue = "false"

    $xd.Save("C:WindowsSystem32inetsrvconfigschemaWEBDAV_schema.xml")
}

. FixWebdavConfig

As far as  how to enable WebDAV with PowerShell, I haven’t figured that out just yet, but I wanted to share this for now.

I hope this script helps save you some time in your ConfigMgr deployments!

Quick Update

Hey guys,

For those of you that do actually follow me, sorry for not writing much new content recently. I’ve been really busy with work and haven’t had the time to dedicate to writing that I’d like to. I hope to keep writing more on here (mostly on PowerShell, ConfigMgr, and OSD topics).

Cheers,

Trevor Sullivan