<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Richard's Weblog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/richard_macdonald/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/feed.xml</link>
    <description />
    <lastBuildDate>Fri, 17 Apr 2015 06:05:47 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Charting with PowerShell</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/charting-with-powershell</link>
      <pubDate>Tue, 28 Apr 2009 09:29:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2009/04/28/charting-with-powershell/</guid>
      <description><![CDATA[You may be aware that there are some 3-rd party add-ins for PowerShell that allow you to create...]]></description>
      <content:encoded><![CDATA[<P>You may be aware that there are some 3-rd party add-ins for PowerShell that allow you to create charts and graphs from your PowerShell scripts.&nbsp; What you may not be aware of is that there is a free download from Microsoft that will allow you to do the same.&nbsp; The <EM>Microsoft Chart Controls for Microsoft .NET Framework 3.5</EM> are a set of .NET classes that allow you to draw bar, line, pie, etc charts with relative ease.</P>
<P>I’ve been using these for a C# project I’m working on, but I thought I’d write a short post to show how easy they are to use from PowerShell.</P>
<P>If you want to follow along with the examples, you’ll need to install the following:</P>
<BLOCKQUOTE>
<P><A href="https://www.microsoft.com/technet/scriptcenter/topics/msh/download.mspx" mce_href="https://www.microsoft.com/technet/scriptcenter/topics/msh/download.mspx">PowerShell v1.0</A>&nbsp; (I used v2.0 on Windows 7, but don’t see any reason why v1.0 won’t do just as well)</P>
<P><A href="https://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;DisplayLang=en" mce_href="https://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;DisplayLang=en">.NET Framework 3.5</A></P>
<P><A href="https://www.microsoft.com/downloads/details.aspx?familyid=130F7986-BF49-4FE5-9CA8-910AE6EA442C&amp;displaylang=en" mce_href="https://www.microsoft.com/downloads/details.aspx?familyid=130F7986-BF49-4FE5-9CA8-910AE6EA442C&amp;displaylang=en">Microsoft Chart Controls for Microsoft .NET Framework 3.5</A></P></BLOCKQUOTE>
<P>I’ll build a simple example script step-by-step.&nbsp; To use it, simply copy the individual sections into a file called something like “Chart.ps1”, then execute from the PowerShell command window.</P>
<P>To create a chart the first thing you need to do is to load the appropriate .NET assemblies:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># load the appropriate assemblies <BR>[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") <BR>[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")</FONT></P></BLOCKQUOTE>
<P><EM>System.Windows.Forms</EM> gives you the standard forms classes.&nbsp; While not necessary in order to use the Chart Controls, I’ll be using a form later to display the chart.&nbsp; <EM>System.Windows.Forms.DataVisualization</EM> is the main namespace for the chart controls.</P>
<P>Next you’ll need to create a Chart object and set some basic properties:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># create chart object <BR>$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart <BR>$Chart.Width = 500 <BR>$Chart.Height = 400 <BR>$Chart.Left = 40 <BR>$Chart.Top = 30</FONT></P></BLOCKQUOTE>
<P>Next you must define a ChartArea to draw on and add this to the Chart:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># create a chartarea to draw on and add to chart <BR>$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea <BR>$Chart.ChartAreas.Add($ChartArea)</FONT></P></BLOCKQUOTE>
<P>Now for some data to display:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># add data to chart <BR>$Cities = @{London=7556900; Berlin=3429900; Madrid=3213271; Rome=2726539; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Paris=2188500} <BR>[void]$Chart.Series.Add("Data") <BR>$Chart.Series["Data"].Points.DataBindXY($Cities.Keys, $Cities.Values)</FONT></P></BLOCKQUOTE>
<P>For simplicity, I’ve hard-coded some data on European cities <A href="https://en.wikipedia.org/wiki/Largest_cities_of_the_European_Union_by_population_within_city_limits" mce_href="https://en.wikipedia.org/wiki/Largest_cities_of_the_European_Union_by_population_within_city_limits">taken from WikiPedia</A>.&nbsp; As you’ll see later, it is just as easy to use data gathered or generated by the script itself.</P>
<P>The final step is to display the chart on a Windows Form:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># display the chart on a form <BR>$Chart.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left <BR>$Form = New-Object Windows.Forms.Form <BR>$Form.Text = "PowerShell Chart" <BR>$Form.Width = 600 <BR>$Form.Height = 600 <BR>$Form.controls.add($Chart) <BR>$Form.Add_Shown({$Form.Activate()}) <BR>$Form.ShowDialog()</FONT></P></BLOCKQUOTE>
<P>If you put all of this together and run it, you should see a Window similar to the one below:</P>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_initial.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_initial.png" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_initial.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="Basic Column Chart" border=0 alt="Basic Column Chart" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_initial_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_initial_thumb.png" width=244 height=244 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_initial_thumb.png"></A> </P></BLOCKQUOTE>
<P>The chart will re-size when you pull the edges of the form around.&nbsp; In fact, when displayed on a form like this the charts can be quite interactive and, for example, can be updated with live data.&nbsp; I’ll leave that as an exercise for the reader!</P>
<P>So, we’ve got a fairly basic chart, but what tweaks can we make to improve it?</P>
<P>First thing is to add a title and some labels to the axes:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># add title and axes labels <BR>[void]$Chart.Titles.Add("Top 5 European Cities by Population") <BR>$ChartArea.AxisX.Title = "European Cities" <BR>$ChartArea.AxisY.Title = "Population"</FONT></P></BLOCKQUOTE>
<P>Although it is quite clear in this example which item is the largest, in some instances it might not be as obvious, so it is possible to highlight that item (as well as the smallest):</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># Find point with max/min values and change their colour <BR>$maxValuePoint = $Chart.Series["Data"].Points.FindMaxByValue() <BR>$maxValuePoint.Color = [System.Drawing.Color]::Red </FONT></P>
<P><FONT face="Lucida Console">$minValuePoint = $Chart.Series["Data"].Points.FindMinByValue() <BR>$minValuePoint.Color = [System.Drawing.Color]::Green</FONT></P></BLOCKQUOTE>
<P>Let's get rid of the extra white space around the chart:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># change chart area colour <BR>$Chart.BackColor = [System.Drawing.Color]::Transparent</FONT></P></BLOCKQUOTE>
<P>Finally, those flat looking bars aren’t too interesting, so let’s give them a slightly 3D appearance:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># make bars into 3d cylinders <BR>$Chart.Series["Data"]["DrawingStyle"] = "Cylinder"</FONT></P></BLOCKQUOTE>
<P>Now, you should have something like this:</P>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_better_2.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_better_2.png" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_better_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="Better Column Chart" border=0 alt="Better Column Chart" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_better_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_better_thumb.png" width=244 height=244 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/chart_better_thumb.png"></A> </P></BLOCKQUOTE>
<P>A nice little chart, with minimal effort.&nbsp; </P>
<P>This is all good, but your chart is gone once you close the form.&nbsp; Wouldn’t it be great if you could save a copy?&nbsp; Well, the good news is that you can.&nbsp; The code below adds a button to the form that saves the chart to your desktop when clicked:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># add a save button <BR>$SaveButton = New-Object Windows.Forms.Button <BR>$SaveButton.Text = "Save" <BR>$SaveButton.Top = 500 <BR>$SaveButton.Left = 450 <BR>$SaveButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right <BR>$SaveButton.add_click({$Chart.SaveImage($Env:USERPROFILE + "\Desktop\Chart.png", "PNG")}) </FONT></P>
<P><FONT face="Lucida Console">$Form.controls.add($SaveButton)</FONT></P></BLOCKQUOTE>
<P>A couple of points about this button:</P>
<UL>
<LI>I also reduced the height of the chart to make room for the button, by changing the chart height set earlier in the script: <FONT face="Lucida Console">$Chart.Height = 450</FONT> </LI>
<LI>As it happens, this button is not necessary, and you can call the save method directly from PowerShell, like this: </LI></UL>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># save chart to file <BR>$Chart.SaveImage($Env:USERPROFILE + "\Desktop\Chart.png", "PNG")</FONT></P></BLOCKQUOTE>
<UL>
<LI>You should call “$Form.controls.add($SaveButton)” <EM>after</EM> creating the form object.&nbsp; This seems obvious, but I just wanted to be clear as the snippet above doesn’t show the rest of the code for the form and depending on where you paste it in, it may fail. </LI></UL>
<P>If you’re more interested in a fully automated script with no GUI or user interaction, then you’ll be glad to hear that the Windows Form is not necessary at all – you can create, populate, configure and save the chart to file without ever displaying it.&nbsp; This&nbsp; is useful if you don’t actually want to see it there and then, but need it for a report or presentation later.</P>
<P>Ok, so you’re not interested in European demography.&nbsp; In that case, let’s look at an example that is more useful if you’re a SysAdmin.</P>
<P>As you know, with PowerShell it is trivial to gather certain system information.&nbsp; For example, here is how to gather information on running processes and display it in a (truncated) table:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console">PS C:\Windows\system32&gt; Get-Process | Format-Table</FONT></P>
<P><FONT face="Lucida Console">Handles&nbsp; NPM(K)&nbsp;&nbsp;&nbsp; PM(K)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WS(K) VM(M)&nbsp;&nbsp; CPU(s)&nbsp;&nbsp;&nbsp;&nbsp; Id ProcessName <BR>-------&nbsp; ------&nbsp;&nbsp;&nbsp; -----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ----- -----&nbsp;&nbsp; ------&nbsp;&nbsp;&nbsp;&nbsp; -- ----------- <BR>&nbsp;&nbsp;&nbsp; 128&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 10&nbsp;&nbsp;&nbsp; 15848&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15556&nbsp;&nbsp;&nbsp; 52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5580 audiodg <BR>&nbsp;&nbsp;&nbsp; 909&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 40&nbsp;&nbsp;&nbsp; 19888&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 33372&nbsp;&nbsp; 128&nbsp;&nbsp;&nbsp;&nbsp; 5.79&nbsp;&nbsp; 2368 CcmExec <BR>&nbsp;&nbsp; 1324&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 79&nbsp;&nbsp;&nbsp; 45556&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 53780&nbsp;&nbsp; 351&nbsp;&nbsp;&nbsp; 26.96&nbsp;&nbsp; 3924 communicator <BR>&nbsp;&nbsp;&nbsp;&nbsp; 57&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp; 2356&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6404&nbsp;&nbsp;&nbsp; 74&nbsp;&nbsp;&nbsp;&nbsp; 0.06&nbsp;&nbsp;&nbsp; 668 conhost <BR>&nbsp;&nbsp;&nbsp; 665&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 13&nbsp;&nbsp;&nbsp;&nbsp; 1976&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4128&nbsp;&nbsp;&nbsp; 48&nbsp;&nbsp;&nbsp;&nbsp; 2.56&nbsp;&nbsp;&nbsp; 364 csrss <BR>&nbsp;&nbsp;&nbsp; 509&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 19&nbsp;&nbsp;&nbsp;&nbsp; 3972&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 18040&nbsp;&nbsp; 112&nbsp;&nbsp;&nbsp;&nbsp; 9.86&nbsp;&nbsp;&nbsp; 452 csrss <BR>&nbsp;&nbsp;&nbsp; 116&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 15&nbsp;&nbsp;&nbsp; 29240&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 26832&nbsp;&nbsp; 139&nbsp;&nbsp;&nbsp; 43.98&nbsp;&nbsp; 3064 dwm <BR>&nbsp;&nbsp; 1171&nbsp;&nbsp;&nbsp;&nbsp; 148&nbsp;&nbsp;&nbsp; 56664&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 66612&nbsp;&nbsp; 307&nbsp;&nbsp;&nbsp; 38.08&nbsp;&nbsp; 1256 explorer</FONT></P></BLOCKQUOTE>
<P>Tables are good, but often a simple graph is better, especially in presentations.&nbsp; Let’s assume you want to show the top 5 consumers of physical memory (WS – Working set – in the table above).&nbsp; Normally, to show this in a table, you’d do something like this:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console">Get-Process | Sort-Object -Property WS | Select-Object Name,WS,ID -Last 5 | Format-Table -AutoSize</FONT></P></BLOCKQUOTE>
<P>To add this to a chart, do this instead:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># add data to chart <BR>$Processes = Get-Process | Sort-Object -Property WS | Select-Object Name,WS,ID -Last 5 <BR>$ProcNames = @(foreach($Proc in $Processes){$Proc.Name + "_" + $Proc.ID}) <BR>$WS = @(foreach($Proc in $Processes){$Proc.WS/1MB}) </FONT></P>
<P><FONT face="Lucida Console">[void]$Chart.Series.Add("Data") <BR>$Chart.Series["Data"].Points.DataBindXY($ProcNames, $WS)</FONT></P></BLOCKQUOTE>
<P>Apart from this change to how the data is gathered (and the chart titles), <EM>everything else in our script remains the same as before</EM>.&nbsp; This is great - once we have a script that shows a chart, we can easily re-use&nbsp;it to show other data.&nbsp; Obviously, if you’re going to use a lot of charts, then you probably want to organise the charting part as a separate function you can call when needed.&nbsp; So, this time, your chart should look something like this:</P>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/ws_better_2.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/ws_better_2.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=ws_better border=0 alt=ws_better src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/ws_better_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/ws_better_thumb.png" width=244 height=244></A> </P></BLOCKQUOTE>
<P>As before, the largest and smallest columns are highlighted.&nbsp; If your data does not come pre-sorted, as it is in&nbsp;the example, the chart control can sort the data after it is bound to the control, like this:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console">$Chart.Series["Data"].Sort([System.Windows.Forms.DataVisualization.Charting.PointSortOrder]::Descending, "Y")</FONT></P></BLOCKQUOTE>
<P>This chart is pretty clear and easy to understand, but not all data benefits from a Column view.&nbsp; Although not ideal for the current example, let’s assume a pie chart would be better.&nbsp; How do you draw one of those?&nbsp; Easy.</P>
<P>Remove these code sections from your script:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console">$Chart.Series["Data"].Sort([System.Windows.Forms.DataVisualization.Charting.PointSortOrder]::Descending, "Y") </FONT></P>
<P><FONT face="Lucida Console">$ChartArea.AxisX.Title = "Process" <BR>$ChartArea.AxisY.Title = "Working Set (MB)" </FONT></P>
<P><FONT face="Lucida Console"># Find point with max/min values and change their colour <BR>$maxValuePoint = $Chart.Series["Data"].Points.FindMaxByValue() <BR>$maxValuePoint.Color = [System.Drawing.Color]::Red </FONT></P>
<P><FONT face="Lucida Console">$minValuePoint = $Chart.Series["Data"].Points.FindMinByValue() <BR>$minValuePoint.Color = [System.Drawing.Color]::Green </FONT></P>
<P><FONT face="Lucida Console"># make bars into 3d cylinders <BR>$Chart.Series["Data"]["DrawingStyle"] = "Cylinder"</FONT></P></BLOCKQUOTE>
<P>Substitute the following:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># set chart type <BR>$Chart.Series["Data"].ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]::Pie</FONT></P></BLOCKQUOTE>
<P>Which gives you a basic pie chart:</P>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_2.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_2.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=pie border=0 alt=pie src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_thumb.png" width=244 height=244></A> </P></BLOCKQUOTE>
<P>To improve the appearance, add the following code:</P>
<BLOCKQUOTE>
<P><FONT face="Lucida Console"># set chart options <BR>$Chart.Series["Data"]["PieLabelStyle"] = "Outside" <BR>$Chart.Series["Data"]["PieLineColor"] = "Black" <BR>$Chart.Series["Data"]["PieDrawingStyle"] = "Concave" <BR>($Chart.Series["Data"].Points.FindMaxByValue())["Exploded"] = $true</FONT></P></BLOCKQUOTE>
<P>Now, your chart should look like this:</P>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_better_2.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_better_2.png"><IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=pie_better border=0 alt=pie_better src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_better_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ChartingwithPowerShell_20A6/pie_better_thumb.png" width=244 height=244></A> </P></BLOCKQUOTE>
<P>Well, that’s it for this short tutorial, but if you’re hungry for more (and there is a <EM>lot</EM> more) on using the Chart Controls, download the Chart Control documentation and samples:</P>
<BLOCKQUOTE>
<P><A href="https://www.microsoft.com/downloads/details.aspx?familyid=EE8F6F35-B087-4324-9DBA-6DD5E844FD9F&amp;displaylang=en" mce_href="https://www.microsoft.com/downloads/details.aspx?familyid=EE8F6F35-B087-4324-9DBA-6DD5E844FD9F&amp;displaylang=en">Microsoft Chart Controls for .NET Framework Documentation</A> <BR><A href="https://code.msdn.microsoft.com/mschart" mce_href="https://code.msdn.microsoft.com/mschart">Samples Environment for Microsoft Chart Controls</A></P></BLOCKQUOTE>]]></content:encoded>
    </item>
    <item>
      <title>Protecting Removable Drives with Bitlocker</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/protecting-removable-drives-with-bitlocker</link>
      <pubDate>Mon, 06 Oct 2008 05:36:46 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2008/10/06/protecting-removable-drives-with-bitlocker/</guid>
      <description><![CDATA[In a recent post, I explained how easy it was to use Bitlocker to secure your drives in a dual-boot...]]></description>
      <content:encoded><![CDATA[<p>In a <a target="_blank" href="https://blogs.technet.com/richard_macdonald/archive/2008/07/19/3091052.aspx">recent post</a>, I explained how easy it was to use Bitlocker to secure your drives in a dual-boot scenario with Windows Vista and Server 2008.&#160; Following this I had some discussions with colleagues about how to securely backup copies of the files from the encrypted drive.&#160; Specifically, how to create a <em>portable</em> copy to carry around with you.&#160; Engineers in my team are out on the road a lot and sometimes don't have good access to our corporate network, so having a second copy of important files with you is very useful, but as you can imagine, copying your files from a system secured by Bitlocker to a plane old USB drive renders the Bitlocker a bit pointless, especially if this drive is carried around in the same bag as your laptop!</p>  <p>The good news is that Bitlocker can also secure removable drives.&#160; Admittedly, this makes the drive somewhat less portable, but it does allow you to create a secure backup that you can carry with you.&#160; Here's how to do it: </p>  <ul>   <li><strong>Insert the USB drive and format using NTFS</strong>.&#160; If you already have files on the drive, either temporarily copy these elsewhere and run a normal format then copy the files back, or use the <em>convert</em> command at the command-line to change the format with the files in place. </li>    <li><strong>Open the <em>Bitlocker Drive Encryption</em> tool from the Control Panel</strong>.&#160; Notice that the removable drive is shown as a valid drive for Bitlocker encryption: </li> </ul>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/clear_2.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/clear_2.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="clear" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/clear_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/clear_thumb.png" width="523" height="116" /></a> </p>    <p>The drive used in the above example is a simple 4GB USB drive.</p> </blockquote>  <ul>   <li><strong>Click &quot;Turn on Bitlocker&quot; and follow the prompt to encrypt the drive.</strong>&#160; Make sure to save the recovery key to a secure location, which means somewhere other than another USB drive you carry around with you! </li> </ul>  <p>Now the drive is fully encrypted by Bitlocker and will be automatically useable on the system it was encrypted on.&#160; So, you can now copy files from your main encrypted system to here and carry the drive around as a secure backup.&#160; If the drive is stolen/lost, the data is inaccessible:</p>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/denied_4.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/denied_4.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="denied" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/denied_thumb_1.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/denied_thumb_1.png" width="386" height="187" /></a> </p> </blockquote>  <p>One downside to this is that the increased security has come at the cost of reduced portability.&#160; If all you want is a backup copy of your original files, to be used only when the originals are corrupt or lost, then this is fine as moving between systems isn't really an issue.&#160; However, if you want to use the drive on several machines, say to copy files from a desktop system to your laptop, or vice versa, then the current setup won't do.</p>  <p>To make the drive accessible on another Bitlocker-capable machine, do this:</p>  <ul>   <li><strong>Insert the drive as normal</strong>.&#160; As mentioned above, it will be inaccessible in Explorer (or via any other means, for that matter), but it <em>is</em> recognised by the system&#160; as being encrypted: </li> </ul>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/bl_4.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/bl_4.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="bl" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/bl_thumb_1.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/bl_thumb_1.png" width="750" height="116" /></a> </p> </blockquote>  <ul>   <li><strong>Open the Bitlocker Drive Encryption tool</strong>.&#160; The drive will appear as encrypted and locked: </li> </ul>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/unlock_2.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/unlock_2.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="unlock" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/unlock_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/unlock_thumb.png" width="451" height="135" /></a> </p> </blockquote>  <ul>   <li><strong>Click &quot;Unlock Volume&quot; and follow the prompt to supply the recovery key</strong>.&#160; Once unlocked, the data will be accessible as with a normal USB drive. In addition, if the system used to unlock the drive is itself Bitlocker protected, you will see an option to save the recovery key locally: </li> </ul>  <blockquote>   <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/save_2.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/save_2.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="save" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/save_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProtectingRemovableDriveswithBitlocker_1E59/save_thumb.png" width="569" height="449" /></a> </p>    <p>Using the &quot;Save Keys&quot; option means that each time you insert the drive, it will be automatically unlocked and ready for use, just like a normal USB drive.</p> </blockquote>  <p>You can repeat the steps above on as many systems as you like to make the Bitlocker encryption transparent between these systems, while ensuring that the data on the removable drive remains secure.&#160; Unfortunately, the data is not going to be readable on any system that does not support Bitlocker, but for the scenario I started with (as a secondary, secure, storage for your Vista laptop), then this doesn't really matter.</p>]]></content:encoded>
    </item>
    <item>
      <title>Programming Hyper-V with WMI and C# - Getting Started</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/programming-hyper-v-with-wmi-and-c-getting-started</link>
      <pubDate>Mon, 11 Aug 2008 11:25:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2008/08/11/programming-hyper-v-with-wmi-and-c-getting-started/</guid>
      <description><![CDATA[You may have seen from a recent post that I received a new laptop that was capable of running...]]></description>
      <content:encoded><![CDATA[<p>You may have seen from a <a href="https://blogs.technet.com/richard_macdonald/archive/2008/07/19/3091052.aspx" target="_blank" mce_href="https://blogs.technet.com/richard_macdonald/archive/2008/07/19/3091052.aspx">recent post</a> that I received a new laptop that was capable of running Hyper-V.&#160; Well, it's all fully installed and working, so I thought I might blog about it a bit.&#160; There are plenty of existing blogs on Hyper-V, so I thought I might take a slightly different tack and look at coding for Hyper-V in C#.&#160; </p>  <p>This suits me fine as I like to get to know new software technologies via their API - I think it really helps to understand the features and what you can do with a technology if you have to write some code using it.&#160; You may think differently, depending on how much coding you do - if you are more of a scripter, then check out my colleague, <a href="https://blogs.technet.com/benp/archive/2008/08/11/scripting-hyper-v-with-wmi-and-powershell-part-1-introduction-querying-state.aspx" target="_blank" mce_href="https://blogs.technet.com/benp/archive/2008/08/11/scripting-hyper-v-with-wmi-and-powershell-part-1-introduction-querying-state.aspx">Ben Pearce's blog</a>, where he does a similar thing to what I'm doing here, but using PowerShell.</p>  <p>Anyway, Hyper-V provides a nice interface for scripting and programming.&#160; The interface is usable from any scripting/coding language that can access WMI.&#160; For example: VBScript, C++, PowerShell, C#, etc.&#160; In this short tutorial I'll look at connecting and querying via C#, but the techniques can be easily adapted to the language of your choice.</p>  <blockquote>   <p><em>UPDATE:&#160; After posting I realised I'd made a classic dev mistake:&#160; I wrote and tested the code while logged in with an account with administrative rights on the Hyper-V server, and just assume you'd do the same&#160; If you have any access problems make sure you use an appropriate account.&#160; Some references to help with setting that up:</em></p>    <p><a class="class" href="https://msdn.microsoft.com/en-us/library/aa389290(VS.85).aspx" target="_blank" mce_href="https://msdn.microsoft.com/en-us/library/aa389290(VS.85).aspx">Connecting to WMI on a Remote Computer</a></p>    <p><a class="class" href="https://blogs.technet.com/jhoward/archive/2008/03/28/part-1-hyper-v-remote-management-you-do-not-have-the-requested-permission-to-complete-this-task-contact-the-administrator-of-the-authorization-policy-for-the-computer-computername.aspx" target="_blank" mce_href="https://blogs.technet.com/jhoward/archive/2008/03/28/part-1-hyper-v-remote-management-you-do-not-have-the-requested-permission-to-complete-this-task-contact-the-administrator-of-the-authorization-policy-for-the-computer-computername.aspx">Hyper-V Remote Management: You do not have the requested permission to complete this task. Contact the administrator of the authorization policy for the computer ‘COMPUTERNAME’</a></p> </blockquote>  <p><strong>Basic Connection</strong></p>  <p>WMI is the Microsoft implementation of <a href="https://www.dmtf.org/standards/wbem" target="_blank" mce_href="https://www.dmtf.org/standards/wbem">WBEM</a> and has been around since Windows 2000, so you may already be familiar with it from scripting, etc.&#160; If you've used it in C# before, then even better - working with Hyper-V will be a breeze for you.</p>  <p>For this example, we will need to use the <a href="https://msdn.microsoft.com/en-us/library/cc136822(VS.85).aspx" target="_blank" mce_href="https://msdn.microsoft.com/en-us/library/cc136822(VS.85).aspx">Msvm_ComputerSystem</a> class.&#160; This class gives details of a Hyper-V host or virtual machine, including the &quot;state&quot; (i.e. is it running, paused, etc), &quot;runtime&quot; (how long has it been executing), etc.</p>  <p>Using this class, we can easily connect to the local system and grab a list of the VMs.&#160; The important WMI bits are these:</p>  <blockquote>   <pre class="csharpcode"><span class="rem">// add this namespace in order to access WMI</span>
<span class="rem">// also need to add a reference to System.Management.dll</span>
<span class="kwrd">using</span> System.Management;

<span class="rem">// we want to connect locally (&quot;.&quot;) to the Hyper-V namespace (&quot;root\virtualization&quot;)</span>
ManagementScope manScope = <span class="kwrd">new</span> ManagementScope(<span class="str">@&quot;\\.\root\virtualization&quot;</span>);

<span class="rem">// define the information we want to query - in this case, just grab all properties of the object</span>
ObjectQuery queryObj = <span class="kwrd">new</span> ObjectQuery(<span class="str">&quot;SELECT * FROM Msvm_ComputerSystem&quot;</span>);

<span class="rem">// connect and set up our search</span>
ManagementObjectSearcher vmSearcher = <span class="kwrd">new</span> ManagementObjectSearcher(manScope, queryObj);
ManagementObjectCollection vmCollection = vmSearcher.Get();

<span class="rem">// loop through the machines</span>
<span class="kwrd">foreach</span> (ManagementObject vm <span class="kwrd">in</span> vmCollection)
{
    <span class="rem">// display VM details</span>
    Console.WriteLine(<span class="str">&quot;\nName: {0}\nStatus: {1}\nDescription: {2}\n&quot;</span>,
                        vm[<span class="str">&quot;ElementName&quot;</span>].ToString(),
                        vm[<span class="str">&quot;EnabledState&quot;</span>].ToString(),
                        vm[<span class="str">&quot;Description&quot;</span>].ToString());
}</pre>
</blockquote>

<p>The above code will connect to the local Hyper-V system and pull out details for the host and all VMs.&#160; To connect to a remote system, simply change the management scope:</p>

<blockquote>
  <p>ManagementScope manScope = <span class="kwrd">new</span> ManagementScope(@&quot;<a href="file://remotesystem/root/virtualization" mce_href="file://\\RemoteSystem\root\virtualization">\\<strong><font color="#ff0000">RemoteSystem</font></strong>\root\virtualization</a>&quot;);</p>
</blockquote>

<p>Where &quot;RemoteSystem&quot; is the name of the remote Hyper-V system to manage.</p>&#160;&#160;&#160; <p><strong>I'm Not Me, I'm Him</strong></p>

<p>The above sample can connect locally and remotely (depending on the scope) and in both cases, it simply uses the credentials of the logged-on user.&#160; However, in the remote case, it is possible to supply alternate credentials to use.&#160; It is a little more work, but not much:</p>

<blockquote>
  <pre class="csharpcode"><span class="rem">// add this namespace in order to access WMI</span>
<span class="rem">// also need to add a reference to System.Management.dll</span>
<span class="kwrd">using</span> System.Management;

<span class="rem">// define the information we want to query - in this case, just grab all properties of the object</span>
ObjectQuery queryObj = <span class="kwrd">new</span> ObjectQuery(<span class="str">&quot;SELECT * FROM Msvm_ComputerSystem&quot;</span>);

<span class="rem">// object for storing WMI connection options</span>
<span class="rem">// pass the &quot;user&quot;, &quot;password&quot; and &quot;domain&quot; from command-line</span>
<span class="rem">// don't hard-code these into the application!</span>
ConnectionOptions connOpts = <span class="kwrd">new</span> ConnectionOptions();
connOpts.Username  = user;
connOpts.Authority = <span class="str">&quot;ntlmdomain:&quot;</span> + domain;
connOpts.Password  = password;

<span class="rem">// management scope object</span>
ManagementScope manScope = <span class="kwrd">new</span> ManagementScope(<span class="str">@&quot;\\RemoteSystem\root\virtualization&quot;</span>, connOpts);

<span class="rem">// connect and set up our search</span>
ManagementObjectSearcher vmSearcher = <span class="kwrd">new</span> ManagementObjectSearcher(manScope, queryObj);
ManagementObjectCollection vmCollection = vmSearcher.Get();

<span class="rem">// loop through the VMs</span>
<span class="kwrd">foreach</span> (ManagementObject vm <span class="kwrd">in</span> vmCollection)
{
    <span class="rem">// display VM details</span>
    Console.WriteLine(<span class="str">&quot;\nName: {0}\nStatus: {1}\nDescription: {2}\n&quot;</span>,
                      vm[<span class="str">&quot;ElementName&quot;</span>].ToString(),
                      vm[<span class="str">&quot;EnabledState&quot;</span>].ToString(),
                      vm[<span class="str">&quot;Description&quot;</span>].ToString());
}</pre>
  <style type="text/css">
.csharpcode {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	margin: 0em; width: 100%; background-color: #f4f4f4
}
.csharpcode .lnum {
	color: #606060
}</style></blockquote>

<p>Trying to use alternate credentials locally will result in an exception. <style type="text/css">
.csharpcode {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	margin: 0em; width: 100%; background-color: #f4f4f4
}
.csharpcode .lnum {
	color: #606060
}</style><style type="text/css">
.csharpcode {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	margin: 0em; width: 100%; background-color: #f4f4f4
}
.csharpcode .lnum {
	color: #606060
}</style><style type="text/css">
.csharpcode {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	margin: 0em; width: 100%; background-color: #f4f4f4
}
.csharpcode .lnum {
	color: #606060
}</style><style type="text/css">
.csharpcode {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	margin: 0em; width: 100%; background-color: #f4f4f4
}
.csharpcode .lnum {
	color: #606060
}</style></p>
<style type="text/css">
.csharpcode {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	margin: 0em; width: 100%; background-color: #f4f4f4
}
.csharpcode .lnum {
	color: #606060
}</style>

<p>So, that's it for basic connecting and querying the machines on a Hyper-V system.&#160; For a more complete sample that implements the above code in a more realistic way, grab the download below.</p>

<p><style type="text/css">
.csharpcode {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	margin: 0em; width: 100%; background-color: #f4f4f4
}
.csharpcode .lnum {
	color: #606060
}</style></p>

<p><strong>Code Sample</strong></p>

<p>Download a complete working code sample here:</p>

<blockquote>
  <p><a href="https://bit.ly/vmstate" target="_blank">VMStateQuery Code</a></p>
</blockquote>

<p>VMStateQuery is a command-line tool that implements the code snippets discussed above.&#160; Compile in Visual Studio, then use like this:</p>

<blockquote>
  <p>VMStateQuery [-vhost remoteserver] [-user domain\user] [-pwd password] [-vguest guest] [-sortbystate]</p>

  <p>Where:</p>

  <table class="class" border="0" cellspacing="0" cellpadding="2" width="599"><tbody>
      <tr>
        <td class="class" valign="top" width="199">-vhost remoteserver </td>

        <td class="class" valign="top" width="398">specifies the remote hyper-v server to manage</td>
      </tr>

      <tr>
        <td class="class" valign="top" width="199">-user</td>

        <td class="class" valign="top" width="398">specifies the domain\user to connect as</td>
      </tr>

      <tr>
        <td class="class" valign="top" width="199">-pwd password</td>

        <td class="class" valign="top" width="398">password for the specified user account</td>
      </tr>

      <tr>
        <td class="class" valign="top" width="199">-vguest guest</td>

        <td class="class" valign="top" width="398">query the state of a specific virtual machine</td>
      </tr>

      <tr>
        <td class="class" valign="top" width="199">-sortbystate</td>

        <td class="class" valign="top" width="398">sort the output by the state of the machine</td>
      </tr>
    </tbody></table>
</blockquote>

<p>Typical output looks like this:</p>

<blockquote>
  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProgrammingHyperVwithWMIandCPart1Getting_A4D3/vmsqout_2.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProgrammingHyperVwithWMIandCPart1Getting_A4D3/vmsqout_2.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProgrammingHyperVwithWMIandCPart1Getting_A4D3/vmsqout_2.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="vmsqout" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ProgrammingHyperVwithWMIandCPart1Getting_A4D3/vmsqout_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProgrammingHyperVwithWMIandCPart1Getting_A4D3/vmsqout_thumb.jpg" width="356" height="240" mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ProgrammingHyperVwithWMIandCPart1Getting_A4D3/vmsqout_thumb.jpg" /></a> </p>
</blockquote>

<p><strong>References</strong></p>

<blockquote>
  <p><a href="https://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx" target="_blank" mce_href="https://msdn.microsoft.com/en-us/library/aa394582(VS.85).aspx">Windows Management Instrumentation Documentation</a></p>

  <p><a href="https://msdn.microsoft.com/en-us/library/system.management(VS.80).aspx" target="_blank" mce_href="https://msdn.microsoft.com/en-us/library/system.management(VS.80).aspx">System.Management Namespace</a></p>

  <p><a href="https://msdn.microsoft.com/en-us/library/cc136992(VS.85).aspx" target="_blank" mce_href="https://msdn.microsoft.com/en-us/library/cc136992(VS.85).aspx">Virtualization WMI Provider</a></p></blockquote>]]></content:encoded>
    </item>
    <item>
      <title>(Virtually) Everything You Need to Know About Hyper-V</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/virtually-everything-you-need-to-know-about-hyper-v</link>
      <pubDate>Mon, 21 Jul 2008 05:00:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2008/07/21/virtually-everything-you-need-to-know-about-hyper-v/</guid>
      <description><![CDATA[Following on from my post last year on general virtualisation resources, here is a similar one just...]]></description>
      <content:encoded><![CDATA[<P>Following on from my <A href="https://blogs.technet.com/richard_macdonald/archive/2007/03/12/Virtually-Everything-About-Microsoft-Virtualisation-Technologies.aspx" target=_blank mce_href="https://blogs.technet.com/richard_macdonald/archive/2007/03/12/Virtually-Everything-About-Microsoft-Virtualisation-Technologies.aspx">post</A> last year on general virtualisation resources, here is a similar one just for Hyper-V.&nbsp; Enjoy!</P>
<BLOCKQUOTE>
<P><EM>Note:&nbsp; Thanks to my colleague, Tushar, who sent some of these links around to our team recently.</EM></P></BLOCKQUOTE>
<P><EM></EM></P>
<P><STRONG>Official Hyper-V Web Sites</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://blogs.technet.com/controlpanel/blogs/www.microsoft.com/hyperv" target=_blank mce_href="www.microsoft.com/hyperv">Hyper-V Homepage</A></P>
<P><A href="https://technet2.microsoft.com/windowsserver2008/en/servermanager/virtualization.mspx" target=_blank mce_href="https://technet2.microsoft.com/windowsserver2008/en/servermanager/virtualization.mspx">Hyper-V TechCenter</A></P></BLOCKQUOTE>
<P><STRONG>Getting Started with Hyper-V</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://download.microsoft.com/download/4/2/b/42bea8d6-9c77-4db8-b405-6bffce59b157/Top%20Ten%20Reasons%20for%20Hyper-V.docx" mce_href="https://download.microsoft.com/download/4/2/b/42bea8d6-9c77-4db8-b405-6bffce59b157/Top%20Ten%20Reasons%20for%20Hyper-V.docx">Top Ten Reasons to Adopt Hyper-V</A> (.docx)</P>
<P><A href="https://www.microsoft.com/windowsserver2008/en/us/hyperv-features.aspx" target=_blank mce_href="https://www.microsoft.com/windowsserver2008/en/us/hyperv-features.aspx">Key Hyper-V Features</A></P>
<P><A href="https://www.microsoft.com/windowsserver2008/en/us/hyperv-faq.aspx" target=_blank mce_href="https://www.microsoft.com/windowsserver2008/en/us/hyperv-faq.aspx">Hyper-V FAQ</A></P>
<P><A href="https://go.microsoft.com/fwlink/?LinkId=120241" mce_href="https://go.microsoft.com/fwlink/?LinkId=120241">Hyper-V Release Notes</A></P>
<P><A href="https://go.microsoft.com/fwlink/?LinkID=105293" mce_href="https://go.microsoft.com/fwlink/?LinkID=105293">Hyper-V Step-by-Step Guide: Getting Started</A></P></BLOCKQUOTE>
<P><STRONG>Hyper-V Documents and Articles</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://download.microsoft.com/download/4/2/b/42bea8d6-9c77-4db8-b405-6bffce59b157/Hyper-V%20Technical%20Overview.docx" target=_blank mce_href="https://download.microsoft.com/download/4/2/b/42bea8d6-9c77-4db8-b405-6bffce59b157/Hyper-V%20Technical%20Overview.docx">Windows Server 2008 Hyper-V Technical Overview</A> (.docx)</P>
<P><A href="https://go.microsoft.com/fwlink/?LinkID=120666" target=_blank mce_href="https://go.microsoft.com/fwlink/?LinkID=120666">Hyper-V Step-by-Step Guide: Testing Hyper-V and Failover Clustering</A></P></BLOCKQUOTE>
<BLOCKQUOTE>
<P><A href="https://go.microsoft.com/fwlink/?LinkID=112109" mce_href="https://go.microsoft.com/fwlink/?LinkID=112109">Solution Accelerator Guide: Windows Server Virtualization</A></P>
<P><A href="https://go.microsoft.com/fwlink/?LinkID=112110" mce_href="https://go.microsoft.com/fwlink/?LinkID=112110">Solution Accelerator Guide: Selecting the Right Virtualization Technology</A></P>
<P><A href="https://go.microsoft.com/fwlink/?LinkId=117991" mce_href="https://go.microsoft.com/fwlink/?LinkId=117991">Microsoft Assessment and Planning Tool</A></P>
<P><A href="https://www.microsoft.com/windowsserver2008/en/us/virtualization-consolidation.aspx" target=_blank mce_href="https://www.microsoft.com/windowsserver2008/en/us/virtualization-consolidation.aspx">Virtualization and Consolidation with Hyper-V</A></P>
<P><A href="https://technet2.microsoft.com/windowsserver2008/en/library/5341cb70-0508-4201-a6da-dcac1a65fd351033.mspx?mfr=true" target=_blank mce_href="https://technet2.microsoft.com/windowsserver2008/en/library/5341cb70-0508-4201-a6da-dcac1a65fd351033.mspx?mfr=true">Hyper-V Installed Help</A></P>
<P><A href="https://download.microsoft.com/download/8/2/f/82fa3808-7168-46f1-a07b-f1a7c9cb4e85/WS08%20Quick%20Migration%20with%20Hyper-V_Whitepaper_FINAL.doc" target=_blank mce_href="https://download.microsoft.com/download/8/2/f/82fa3808-7168-46f1-a07b-f1a7c9cb4e85/WS08%20Quick%20Migration%20with%20Hyper-V_Whitepaper_FINAL.doc">Quick Migration with Hyper-V</A> (.doc)</P>
<P><A href="https://download.microsoft.com/download/4/1/d/41d3cbff-6a2d-457e-a6ab-0e1607629c16/Windows_Server_2008_Hyper-V_and_BitLocker_Drive_Encryption_(2008-05-27).docx" mce_href="https://download.microsoft.com/download/4/1/d/41d3cbff-6a2d-457e-a6ab-0e1607629c16/Windows_Server_2008_Hyper-V_and_BitLocker_Drive_Encryption_(2008-05-27).docx">Windows Server 2008 Hyper-V and BitLocker Drive Encryption</A> (.docx)</P>
<P><A href="https://download.microsoft.com/download/1/9/c/19c559f6-332e-4824-ac17-d68ce6a9aac1/MMS_Virtualization.pdf" mce_href="https://download.microsoft.com/download/1/9/c/19c559f6-332e-4824-ac17-d68ce6a9aac1/MMS_Virtualization.pdf">Configuring Hyper-V for Windows Essential Business Server</A> (.pdf)</P></BLOCKQUOTE>
<P><STRONG>Virtualisation and Licensing</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://www.microsoft.com/licensing/highlights/virtualization.mspx" target=_blank mce_href="https://www.microsoft.com/licensing/highlights/virtualization.mspx">Windows Server System Licensing for Virtualization Scenarios</A></P>
<P><A href="https://www.microsoft.com/windowsserver2008/en/us/licensing-without-hyperv.aspx" target=_blank mce_href="https://www.microsoft.com/windowsserver2008/en/us/licensing-without-hyperv.aspx">Licensing without Hyper-V</A></P>
<P><A href="https://download.microsoft.com/download/E/E/C/EECF5D44-9A88-43D8-AFDB-D2AB82BE035C/Win%20Server%20Lic%20Book%20customer%20hi-res.pdf" mce_href="https://download.microsoft.com/download/E/E/C/EECF5D44-9A88-43D8-AFDB-D2AB82BE035C/Win%20Server%20Lic%20Book%20customer%20hi-res.pdf">Your Ultimate Quick Reference Resource for Licensing and Pricing</A> (.pdf)</P></BLOCKQUOTE>
<P><STRONG>Hyper-V Programming and Scripting</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://msdn.microsoft.com/en-us/library/cc136992(VS.85).aspx" target=_blank mce_href="https://msdn.microsoft.com/en-us/library/cc136992(VS.85).aspx">Virtualization WMI Provider</A></P></BLOCKQUOTE>
<P><STRONG>Hyper-V Training and Webcasts</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://www.microsoft.com/events/series/windowsserver2008.aspx?tab=webcasts&amp;id=42531" target=_blank mce_href="https://www.microsoft.com/events/series/windowsserver2008.aspx?tab=webcasts&amp;id=42531">Webcasts</A></P>
<P><A href="https://www.microsoft.com/learning/en/us/syllabi/6422A.aspx" target=_blank mce_href="https://www.microsoft.com/learning/en/us/syllabi/6422A.aspx">Implementing and Managing Windows Server 2008 Hyper-V</A></P>
<P><A href="https://www.microsoft.com/learning/en/us/exams/70-652.mspx" target=_blank mce_href="https://www.microsoft.com/learning/en/us/exams/70-652.mspx">Exam 70-652: Windows Server Virtualization, Configuring</A></P></BLOCKQUOTE>
<P><STRONG>Hyper-V Related Blogs</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://blogs.msdn.com/virtual_pc_guy/default.aspx" mce_href="https://blogs.msdn.com/virtual_pc_guy/default.aspx">Virtual PC Guy's WebLog</A></P>
<P><A href="https://blogs.technet.com/jhoward/default.aspx" mce_href="https://blogs.technet.com/jhoward/default.aspx">John Howard - Hyper-V and virtualization blog</A></P>
<P><A href="https://blogs.technet.com/roblarson/default.aspx" target=_blank mce_href="https://blogs.technet.com/roblarson/default.aspx">Rob Larson's blog</A></P>
<P><A href="https://blogs.msdn.com/mikekol/" target=_blank mce_href="https://blogs.msdn.com/mikekol/">Virtual Varia</A></P>
<P><A href="https://blogs.technet.com/virtualization/" target=_blank mce_href="https://blogs.technet.com/virtualization/">Virtualisation Team Blog</A></P></BLOCKQUOTE>
<P><STRONG>Miscellaneous</STRONG></P>
<BLOCKQUOTE>
<P><A href="https://www.windowsservercatalog.com/results.aspx?&amp;bCatID=1333&amp;cpID=0&amp;avc=11&amp;ava=0&amp;avq=22&amp;OR=1&amp;PGS=25&amp;ready=0" target=_blank mce_href="https://www.windowsservercatalog.com/results.aspx?&amp;bCatID=1333&amp;cpID=0&amp;avc=11&amp;ava=0&amp;avq=22&amp;OR=1&amp;PGS=25&amp;ready=0">Hyper-V Capable Server Hardware</A></P>
<P><A href="https://forums.microsoft.com/TechNet/ShowForum.aspx?ForumID=583&amp;SiteID=17" target=_blank mce_href="https://forums.microsoft.com/TechNet/ShowForum.aspx?ForumID=583&amp;SiteID=17">Hyper-V Discussion Forum</A></P>
<P><A href="https://technet.microsoft.com/en-us/virtualization/default.aspx" target=_blank mce_href="https://technet.microsoft.com/en-us/virtualization/default.aspx">Virtualisation Solution Center</A></P>
<P><A href="https://www.microsoft.com/MSPress/books/11842.aspx" target=_blank mce_href="https://www.microsoft.com/MSPress/books/11842.aspx">Windows Server 2008 Hyper-V Resource Kit</A> </P>
<P><A href="https://www.microsoft.com/whdc/system/sysperf/Perf_tun_srv.mspx" target=_blank mce_href="https://www.microsoft.com/whdc/system/sysperf/Perf_tun_srv.mspx">Performance Tuning Guidelines for Windows Server 2008</A></P>
<P><A href="https://www.microsoft.com/systemcenter/virtualmachinemanager/en/us/default.aspx" target=_blank mce_href="https://www.microsoft.com/systemcenter/virtualmachinemanager/en/us/default.aspx">System Center Virtual Machine Manager</A></P>
<P><A href="https://www.microsoft.com/downloads/details.aspx?FamilyID=060f0c51-339a-4c4e-bb6e-716bb7401fd4&amp;displaylang=en" target=_blank mce_href="https://www.microsoft.com/downloads/details.aspx?FamilyID=060f0c51-339a-4c4e-bb6e-716bb7401fd4&amp;displaylang=en">Windows Server 2008 Evaluation Virtual Hard Drive Images (for Hyper-V)</A></P>
<P><A href="https://download.microsoft.com/download/6/C/5/6C559B56-8556-4097-8C81-2D4E762CD48E/MSCOM_Virtualizes_MSDN_TechNet_on_Hyper-V.docx" target=_blank mce_href="https://download.microsoft.com/download/6/C/5/6C559B56-8556-4097-8C81-2D4E762CD48E/MSCOM_Virtualizes_MSDN_TechNet_on_Hyper-V.docx">Msdn Technet Powered By Hyper V</A> (.docx)</P>
<P><A href="https://www.microsoft.com/downloads/details.aspx?familyid=AD3921FB-8224-4681-9064-075FDF042B0C&amp;displaylang=en" target=_blank mce_href="https://www.microsoft.com/downloads/details.aspx?familyid=AD3921FB-8224-4681-9064-075FDF042B0C&amp;displaylang=en">Infrastructure Planning and Design</A></P>
<P><A href="https://www.microsoft.com/downloads/details.aspx?familyid=A5002C32-C053-4FFA-BE09-71B82B9F51FE&amp;displaylang=en" target=_blank mce_href="https://www.microsoft.com/downloads/details.aspx?familyid=A5002C32-C053-4FFA-BE09-71B82B9F51FE&amp;displaylang=en">Windows Server Virtualization Technologies</A></P></BLOCKQUOTE>
<P><STRONG>Hyper-V Knowledge Base Articles</STRONG></P>
<BLOCKQUOTE>
<P>949222 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;949222" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;949222">Virtual machines that were created on the beta version of the Hyper-V role do not start after the Hyper-V role is updated to a later version</A></P>
<P>950050 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;950050" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;950050">Description of the update for the release version of the Hyper-V technology for Windows Server 2008</A></P>
<P>950792 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;950792" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;950792">When you try to enable, disable, or update Hyper-V technology, the process stops responding</A></P>
<P>951636 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;951636" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;951636">Description of the Hyper-V Language Pack for Windows Server 2008</A></P>
<P>952627 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;952627" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;952627">Description of the Windows Vista Service Pack 1 Management Tools update for the release version of Hyper-V</A></P>
<P>953828 - <A href="https://support.microsoft.com/kb/953828/en-us" target=_blank mce_href="https://support.microsoft.com/kb/953828/en-us">The NLB host does not converge as expected on Windows Server 2008 Hyper-V virtual machines</A></P>
<P>954279 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954279" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954279">You are not prompted for credentials after you receive an "Access Denied" error message when you try to connect to a virtual machine from the Windows Server 2008 Hyper-V MMC snap-in</A></P>
<P>954280 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954280" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954280">Error message when you try to export a virtual machine on a Windows Server 2008-based computer that uses Hyper-V: "An error occurred while attempting to export the virtual machine"</A></P>
<P>954281 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954281" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954281">After you install Windows 2000 on a virtual machine that is running on a Windows Server 2008-based computer that uses Hyper-V technology, you can only create a maximum startup disk that is 127 GB</A></P>
<P>954282 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954282" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954282">The VMBus device does not load on a virtual machine that is running on a Windows Server 2008-based computer that has Hyper-V installed</A></P>
<P>954283 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954283" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954283">You experience issues after you install Windows Server 2008 Hyper-V Integration Services on a Vista Home Premium virtual machine or a Vista Home Basic virtual machine</A></P>
<P>954356 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954356" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954356">After you deploy a Sysprep prepared image, the Hypervisor layer service does not start automatically in Windows Server 2008</A></P>
<P>954357 - <A href="https://vkbexternal/VKBWebService/ViewContent.aspx?scid=KB;EN-US;954357" target=_blank mce_href="https://vkbexternal/VKBWebService/ViewContent.aspx?scid=KB;EN-US;954357">Error message when you use Vmconnect.exe to connect to a virtual machine in Windows Server 2008: "A connection will not be made because credentials may not be sent to the remote computer."</A></P>
<P>954358 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954358" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954358">Virtual Hard Disk (.vhd file) contents may be accessed by all users after you mount the file as a loopback device in Windows Server 2008</A></P>
<P>954958 - <A href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954958" target=_blank mce_href="https://support.microsoft.com/default.aspx?scid=kb;EN-US;954958">Guest operating systems that are supported on a Hyper-V virtual machine host</A></P></BLOCKQUOTE>]]></content:encoded>
    </item>
    <item>
      <title>Vista, Server 2008 and the Case of the Bitlocker Dual Boot</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/vista-server-2008-and-the-case-of-the-bitlocker-dual-boot</link>
      <pubDate>Fri, 18 Jul 2008 21:10:29 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2008/07/18/vista-server-2008-and-the-case-of-the-bitlocker-dual-boot/</guid>
      <description><![CDATA[This week, I received my shiny new work laptop, which I'd been anticipating for some time.&#160;...]]></description>
      <content:encoded><![CDATA[<p>This week, I received my shiny new work laptop, which I'd been anticipating for some time.&#160; Normally, I'm not much of a hardware geek and don't get overly excited with new kit, but I was really looking forward to this as it is 64-bit and finally allows me to install Server 2008 and Hyper-V for customer demos, testing, etc.</p>  <p>Although I wanted to use Server 2008, I still wanted Vista as my day-to-day desktop for email and the like, so I planned to dual boot with a shared data partition.&#160; However, as I sometimes have sensitive documents on my laptop I wanted to use Bitlocker to secure everything.</p>  <p>At first I wasn't sure what would happen if I just booted to Vista or Server 2008 and Bitlockered all of the drives.&#160; Would the system boot at all?&#160; Would I lose access to one or both operating systems?&#160; What about the shared data?</p>  <p>As it turns out, this dual-boot scenario is no problem for Bitlocker.&#160; In case you're faced with a similar scenario, here's how I installed mine:</p>  <ol>   <li>Installed Vista Ultimate SP1 to C: partition.&#160; Vista Enterprise also supports Bitlocker.</li>    <li>Installed Server 2008 Enterprise on D: partition. </li>    <li>Created data partition E:. </li>    <li>Created a small partition, S:, for the unencrypted boot files.&#160; You can do this manually with Disk Manager or you can use the <a href="https://www.microsoft.com/downloads/details.aspx?familyid=320b9aa9-47e8-44f9-b8d0-4d7d6a75add0&amp;displaylang=en&amp;tm" target="_blank">Bitlocker Drive Preparation Tool</a> (also available as an Ultimate Extra).</li>    <li>Booted into Vista and applied Bitlocker to the C: drive, saving the recovery key to a USB drive and setting a boot PIN.</li>    <li>Booted into Server 2008 and applied Bitlocker to D:, saving the recovery key to a USB drive and setting a boot PIN.&#160; The PIN is not shared across the two operating systems, but you can use the same number for both. </li> </ol>  <p>At this point both operating systems are protected by Bitlocker, both boot fine (using the appropriate PIN) and both can access the unencrypted data partition E:.&#160; However, they cannot access each other's partition.&#160; Next, to protect E: and make it accessible to both operating systems, I did this:</p>  <ol>   <li>Booted into Vista and applied Bitlocker to the E: partition, saving the recovery key to a USB drive.</li>    <li>Booted into Server 2008, where E: is now inaccessible.</li>    <li>Started the Bitlocker Drive Encryption tool and selected the &quot;Unlock Volume&quot; option for E:</li>    <li>Selected to load the volume recovery key from removable media when prompted and inserted the USB drive.</li>    <li>Selected the &quot;Save key...&quot; option and unlocked the partition.</li> </ol>  <p>Now, partitions C:, D: and E: are all protected by Bitlocker and each OS can boot without problem and can access the shared E: drive without any need to enter the recovery key.&#160; I deliberately left it so that each OS still can't see the other's install partition, so as to avoid accidental changes, but using the &quot;unlock&quot; method above it would be possible to make all drives accessible under each OS.</p>  <p>There is possibly a neater way of doing this, but apart from waiting for the encryption steps to complete it was all very quick and painless.</p>  <p>A couple of notes:</p>  <ul>   <li>I used a new system with clean installs of Vista and Server 2008, so if things had gone wrong all I'd have lost is a bit of my time.&#160; If you do this on an existing system, please <strong>remember to back up your data first</strong> - I'm sure everything will be fine, but you never know ...</li>    <li>If you follow the method above you will end up with a USB drive with all of your recovery keys on it.&#160; Remember to keep this in a safe place <em>away</em> from your computer (e.g. don't leave it in your bag with your laptop).</li>    <li>If you're interested in dual-booting with an OS that doesn't support Bitlocker, have a look <a href="https://blogs.technet.com/voy/archive/2006/10/13/building-a-dual-boot-system-with-windows-vista-bitlocker-protection-with-tpm-support.aspx" target="_blank">here</a>.</li>    <li>Above, I assume you know how to turn on Bitlocker, but if you don't, you can find details in the <a href="https://technet2.microsoft.com/windowsserver2008/en/library/c61f2a12-8ae6-4957-b031-97b4d762cf311033.mspx?mfr=true" target="_blank">Windows BitLocker Drive Encryption Step-by-Step Guide</a>.</li> </ul>]]></content:encoded>
    </item>
    <item>
      <title>Manipulating Performance Monitor Logs</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/manipulating-performance-monitor-logs</link>
      <pubDate>Tue, 08 Apr 2008 13:50:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2008/04/08/manipulating-performance-monitor-logs/</guid>
      <description><![CDATA[If you need to monitor or troubleshoot performance problems on a Windows system, chances are you'll...]]></description>
      <content:encoded><![CDATA[<P>If you need to monitor or troubleshoot performance problems on a Windows system, chances are you'll simply fire up PerfMon,&nbsp; log some data to a file, which you later load in PerfMon for analysis.&nbsp; This is great and is often all that you need, but it's a bit of a passive use of the log and gives the impression that if you make a mistake in your selections at the start you're stuck with it.&nbsp; What if <EM>you</EM> didn't gather the data and the log you're given contains counters you don't need, or is too big to use easily, or you're only interested in a short period of the logging interval?&nbsp; What can you do?&nbsp; As it turns out there is quite a bit you can do.&nbsp; The little-known, but highly-useful, <EM>Relog.exe</EM> tool can perform some clever manipulation once you have your log, allowing you to focus your troubleshooting a bit more (or at least make it a bit easier).&nbsp; </P>
<P>Relog is built-in for Windows XP and later, and is available to <A class="" title="Windows 2000 Relog Download" href="https://www.microsoft.com/downloads/details.aspx?FamilyID=f043c2f5-2a48-41ed-951b-ba7f62cf51d6&amp;displaylang=en" target=_blank mce_href="https://www.microsoft.com/downloads/details.aspx?FamilyID=f043c2f5-2a48-41ed-951b-ba7f62cf51d6&amp;displaylang=en">download</A> for Windows 2000.&nbsp;Here are some things it can do:</P>
<P mce_keep="true">&nbsp;</P>
<P><STRONG>Converting Logs to Different Formats</STRONG></P>
<P>The default log format for performance logs is <EM>Binary (.blg)</EM> and you usually just want to leave it that way as PerfMon can read it just fine.&nbsp; However, what if you wanted to use another tool (Excel, for example) to analyse the data and the tool doesn't understand binary files?&nbsp; Relog allows you to take an existing log in, say, .blg format and generate a new file in, say, <EM>Comma Separated Value (.csv)</EM> format:</P>
<BLOCKQUOTE>
<P><STRONG><EM>Relog OriginalLog.blg -f CSV -o NewLog.csv</EM></STRONG></P></BLOCKQUOTE>
<P>This command takes <EM>OriginalLog.blg</EM> and creates <EM>NewLog.csv</EM> from it, with this new log containing all of the same datapoints as the original.&nbsp; You can convert between .blg, .csv, <EM>Tab Separated Value</EM> (.tsv), and .sql formats.</P>
<P mce_keep="true">&nbsp;</P>
<P><STRONG>Resampling the Data</STRONG></P>
<P>When creating a log file one of the parameters you need to set is the sample interval.&nbsp; You should set this according to the nature of the troubleshooting or monitoring you're doing, so, for example, you would not set the same sample interval on logs that will run for 3 weeks as you would for one that runs for 3 hours.&nbsp; However, you can still end up with some unwieldy log files, which are a pain to view in PerfMon.&nbsp; Relog allows you to resample the data, generating a new log file containing every <EM>n</EM>-th datapoint.&nbsp; For example, this command will take <EM>OriginalLog.blg</EM> and generate <EM>NewLog.blg</EM>, which contains every 5-th datapoint:</P>
<BLOCKQUOTE>
<P><STRONG><EM>Relog OriginalLog.blg -t 5 -o NewLog.blg</EM></STRONG></P></BLOCKQUOTE>
<P>Clearly, you are discarding information here and care needs to be taken or you may end up missing something important from the new dataset - for example, if you originally sampled every 60 seconds, but change this to the equivalent of every 30 minutes, you are likely to miss a transient problem that lasts 5 minutes.&nbsp; However, this isn't really any worse than if you'd set the sample interval differently in the first place, so better to select the correct interval before logging begins.</P>
<P>If you don't want to lose data, but know that the problem your investigating happened mid-way through the logging period, then you can create a new log of just the datapoints in a given time window.&nbsp; For example, if we have a log that ran between Midnight on 3rd March to Midnight on 10th Match, we can extract the data for 5th and 6th March using this command:</P>
<BLOCKQUOTE>
<P><STRONG><EM>Relog OriginalLog.blg -b 05/03/2008 00:00:00 -e 06/03/2008 00:00:00 -o NewLog.blg</EM></STRONG></P></BLOCKQUOTE>
<P>Relog does its best to match the times specified, but if these do not correspond to specific sample times, then it chooses the closest ones.</P>
<P mce_keep="true">&nbsp;</P>
<P><STRONG>Extracting Specific Counters</STRONG></P>
<P>As an alternative to the above approach of re-sampling the datapoints, you can split your log file into multiple files, each with all the datapoints, but with a subset of the original counters.&nbsp; For example, the following command will take all of the Memory-related counters from <EM>OriginalLog.blg</EM> and copy them to <EM>NewLog.blg</EM>:</P>
<BLOCKQUOTE>
<P><EM><STRONG>Relog OriginalLog.blg -c "\Memory\*" -o NewLog.blg</STRONG></EM></P></BLOCKQUOTE>
<P>If you need to do more complex filtering of the counters, then you can list the counters you want in a text file and pass the path to Relog:</P>
<BLOCKQUOTE>
<P><EM><STRONG>Relog Original.blg -cf CounterList.txt -o NewLog.blg</STRONG></EM></P></BLOCKQUOTE>
<P>The counter list is specified with a single counter per-line.&nbsp; For example:</P>
<BLOCKQUOTE>
<P><EM>\Memory\Pool Paged Bytes<BR>\Process(*)\Pool Paged Bytes<BR>\Process(*)\Handle Count<BR>\Thread(Explorer*)\% Processor Time</EM>&nbsp;</P></BLOCKQUOTE>
<P mce_keep="true">&nbsp;</P>
<P><STRONG>Merging Logs</STRONG></P>
<P>If you have several logs you've split out as described above and would like to re-combine two or more of them, say for easier comparison in PerfMon, then Relog can do this as follows:</P>
<BLOCKQUOTE>
<P><STRONG><EM>Relog SeparateLog11.blg SeparateLog2.blg -o CombinedLog.blg</EM></STRONG></P></BLOCKQUOTE>
<P>This takes <EM>SeparateLog1.blg</EM> and combines it with <EM>SeparateLog2.blg</EM> and writes the result to <EM>CombinedLog.blg</EM>.&nbsp; You can do this for more than two logs, but all of them must be in .blg format.</P>
<P mce_keep="true">&nbsp;</P>
<P><STRONG>Combining Actions</STRONG></P>
<P>It is possible to combine some of the actions mentioned above in a single command.&nbsp; For example:</P>
<BLOCKQUOTE>
<P><STRONG>Resample and convert log type</STRONG></P>
<P>To convert from .blg to .csv and copy only every 10th datapoint, us this command:</P>
<P><STRONG><EM>&nbsp;&nbsp;&nbsp;&nbsp; Relog OriginalLog.blg -f CSV -t 10 -o NewLog.csv</EM></STRONG></P>
<P mce_keep="true">&nbsp;</P>
<P><STRONG>Extract Counters, Change Time Window and Resample</STRONG></P>
<P>To extract every 5th datapoint for just the Memory counters from 5-6th March, use this command:</P>
<P><STRONG><EM>&nbsp;&nbsp;&nbsp;&nbsp; Relog OriginalLog.blg -b 05/03/2008 00:00:00 -e 06/03/2008 00:00:00 -c "\Memory\*" -t 5 -o NewLog.blg</EM></STRONG>&nbsp;</P></BLOCKQUOTE>
<P mce_keep="true">&nbsp;</P>
<P>Obviously, analysing the data after you've played around with it is the critical part, and that's beyond the scope of a simple blog post, but to get you started, here are a few resources that you might find useful:</P>
<BLOCKQUOTE>
<P><A href="https://www.codeplex.com/PAL" target=_blank mce_href="https://www.codeplex.com/PAL">Performance Analysis of Logs (PAL)</A> .&nbsp;&nbsp; PAL automates the analysis of the logs by applying specified thresholds (supplied) to the data, generating reports with details of what it found.</P>
<P><A href="https://www.microsoft.com/mspress/books/5555.aspx" target=_blank mce_href="https://www.microsoft.com/mspress/books/5555.aspx">Windows Performance Guide</A>.&nbsp; Part of the Server 2003 Resource Kit, this is <EM>the</EM> place to read up on performance analysis.</P>
<P><A href="https://www.microsoft.com/windowsserver2003/evaluation/performance/tuning.mspx" target=_blank mce_href="https://www.microsoft.com/windowsserver2003/evaluation/performance/tuning.mspx">Performance Tuning Guidelines for Windows Server 2003</A>.&nbsp; Provides guidance on parameter to tweak in order to maximise performance in Server 2003.</P>
<P><A href="https://www.microsoft.com/whdc/system/sysperf/Perf_tun_srv.mspx" target=_blank mce_href="https://www.microsoft.com/whdc/system/sysperf/Perf_tun_srv.mspx">Performance Tuning Guidelines for Windows Server 2008</A>.&nbsp; Server 2008 equivalent of the guide mentioned above.</P></BLOCKQUOTE>]]></content:encoded>
    </item>
    <item>
      <title>Viewing Your MSDN Product Keys Off-Line</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/viewing-your-msdn-product-keys-off-line</link>
      <pubDate>Sun, 09 Mar 2008 15:13:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2008/03/09/viewing-your-msdn-product-keys-off-line/</guid>
      <description><![CDATA[If you have an MSDN subscription, then you'll know that the subscription includes a set of product...]]></description>
      <content:encoded><![CDATA[<p>If you have an MSDN subscription, then you'll know that the subscription includes a set of product keys for use with the versions of Office, Windows, etc that your subscription gives you access to.&#160; The keys can be viewed on-line at the MSDN subscriber site, but this isn't great if you don't have any network access, and even then it's not all that convenient to have to log on each time to get a key.</p>  <p>Now, there is an option to export your keys to an XML file, which means you can have them available off-line.&#160; However, XML isn't the most user-friendly format:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Capture" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture_thumb.jpg" width="640" height="140" mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture_thumb.jpg" /></a> </p>  <p>Admittedly, XML is great for developers looking for a nice file format to store data in and MSDN subscribers you would assume are developers, but you really don't want to have to write a script or app to read the keys.&#160; So, to save you the trouble I wrote a simple tool, <em>KeyView.exe</em>, that loads the XML file and displays the keys in a more useful format:</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture2.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture2.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture2.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Capture2" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture2_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture2_thumb.jpg" width="429" height="232" mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ViewingYourMSDNProductKeysOffLine_12A85/Capture2_thumb.jpg" /></a> </p>  <p>Download KeyView as a Visual Studio 2008 project here (get VS 2008 from the MSDN download site):</p>  <blockquote>   <p><a href="https://bit.ly/keyview" target="_blank">KeyView C# Code Download</a>&#160; <span style="color: gray">[Updated: 15 March 2008]</span></p>    <p>Note: you may need to install <a href="https://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;DisplayLang=en" target="_blank" mce_href="https://www.microsoft.com/downloads/details.aspx?FamilyID=333325fd-ae52-4e35-b531-508d977d32a6&amp;DisplayLang=en">.NET Framework 3.5</a> to make KeyView work.</p> </blockquote>  <p>Once compiled, to get KeyView to work, you simply need to export your keys from the MSDN site to a file called MSDNkeys.xml in the same folder as KeyView and it will load the data automatically when it's launched.&#160; Alternatively you can browse to the file if it's stored, say, on a network share.&#160; Also, if you need to, KeyView allows you to export the data to CSV format.</p>  <p>Yes, yes, not the most useful tool in the world, but I was bored one evening while stuck in a hotel on a business trip!</p>]]></content:encoded>
    </item>
    <item>
      <title>Forcing Theme Settings in Windows Vista</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/forcing-theme-settings-in-windows-vista</link>
      <pubDate>Fri, 17 Aug 2007 03:48:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2007/08/17/forcing-theme-settings-in-windows-vista/</guid>
      <description><![CDATA[Recently I was working with a customer to find a way to automate forcing a specific Aero theme in...]]></description>
      <content:encoded><![CDATA[<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">Recently I was working with a customer to find a way to automate forcing a specific Aero theme in Windows Vista.&#160; The idea was to have the Vista clients &quot;colour-coded&quot; according to their use; so whenever a user logs on the window border colour would indicate the type of system (which was actually based on security levels).&#160; So, for example, if a user logs onto a public terminal with more relaxed browsing settings, the window borders should be red as a reminder the system is less secure, a more secure system might have blue border.</span></p>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt"></span>&#160;</p>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">Unfortunately there isn't any public API or scripting interface for this, nor a GPO setting - the only &quot;theme&quot; GPO setting relates to deploying a specific &quot;style&quot; (stored in an 'msstyles' file), which is not the same as the theme (stored in a 'theme' file).</span></p>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt"></span>&#160;</p>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">After some work we devised the workaround below.&#160; This isn't ideal, by any means, but does the job.&#160; I thought I'd blog about it in case it's useful to anyone in a similar situation.&#160; The usual caveats apply about hacking the registry, etc.&#160; While this seems to work for the moment, there's no guarantee that a future update may change the behaviour.</span>&#160;</p>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal" mce_keep="true">&#160;</p>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">We created these two Aero-based themes:</span></p>  <blockquote>   <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">            </span><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/red.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/red.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/red.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="red" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/red_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/red_thumb.jpg" mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/red_thumb.jpg" /></a>&#160; </p>    <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt"><em><strong>Red.theme - for non-secure systems</strong></em></span></p>    <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt"></span>&#160;</p>    <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">       <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/blue.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/blue.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/blue.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="blue" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/blue_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/blue_thumb.jpg" mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ForcingThemeSettingsinVista_AA72/blue_thumb.jpg" /></a> </p>     </span></p>    <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt"><strong><em>Blue.theme - for secure systems</em></strong></span></p> </blockquote>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">        </span></p>  <p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">To forcibly apply these at logon we:&#160;    </span></p>  <ul type="disc">   <li style="margin: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;"> Copied the .theme files to a location on the local disk of the target system</span> </li>    <li style="margin: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l0 level1 lfo1; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">Changed the &quot;InstallTheme&quot; value in the following registry key to point to the full path of the specifice .theme file:</span><span style="mso-fareast-font-family: &#39;Times New Roman&#39;">            </span></li> </ul>  <blockquote>   <p><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes</span></p>    <p><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt"><em><strong>NOTE:</strong></em> A custom ADM file that sets this can be downloaded <a title="Sample theme ADM" href="https://bit.ly/vistatheme" target="_blank">here</a>.&#160; Using this you can set the registry key centrally in the computer policy for the target system(s).</span></p> </blockquote>  <ul type="disc">   <li style="margin: 0cm 0cm 0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class="MsoNormal"><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt; mso-fareast-font-family: &#39;Times New Roman&#39;">Added the following commands to the user's logon script:</span></li> </ul>  <blockquote>   <p>reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Themes /v SetupVersion /f     <br />regsvr32 /n /s /I:/UserInstall themeui.dll</p> </blockquote>  <p><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">When the user logged on, the script forced the custom theme to apply.&#160; With all this in place, we were able to manage the themes centrally in Active Directory to easily change between themes without visiting the clients.</span></p>  <p><span style="font-family: &#39;Tahoma&#39;,&#39;sans-serif&#39;; font-size: 10pt">I'd be interested to hear of your experience using this or any better method you have for doing the same thing.</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Service Security in Windows Vista</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/service-security-in-windows-vista</link>
      <pubDate>Wed, 27 Jun 2007 06:30:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2007/06/27/service-security-in-windows-vista/</guid>
      <description><![CDATA[After a long break from blogging due to holidays and a heavy workload, I've finally got round to...]]></description>
      <content:encoded><![CDATA[<P>After a long break from blogging due to holidays and a heavy workload, I've finally got round to writing something new.&nbsp; To follow on from my last post on <EM>File and Registry Virtualisation</EM>, I thought I'd take a look at another Vista security-related topic:&nbsp; <EM>Service Security</EM>.&nbsp; 
<P>Services generally&nbsp;run&nbsp;with elevated privileges and are therefore&nbsp;very attractive&nbsp;targets for&nbsp;hackers looking for ways to elevate their own privilege level. In Windows Vista several key changes help reduce the security risk when using system services.&nbsp; Important changes are: 
<H2><STRONG>Session 0 Isolation</STRONG> </H2>
<P>Previously Windows&nbsp;services would all run in the same session as the first user who logged on to the console. This session is called <EM>Session 0</EM>.&nbsp;&nbsp; 
<P>Running services and user applications together in Session 0 poses a security risk.&nbsp; Some services have visible and invisible windows and dialogs that the user or other processes can interact with directly using mouse input or programmatically via window messages.&nbsp; This makes them vulnerable to certain attacks such as the so-called <A href="https://en.wikipedia.org/wiki/Shatter_attack" mce_href="https://en.wikipedia.org/wiki/Shatter_attack">Shatter Attack</A>. 
<P>Vista mitigates the risk by isolating system services in Session 0 and making Session 0 non-interactive; in Vista, only system processes and services run in Session 0 and the first user logs on to Session 1.&nbsp; Subsequent users log on to sessions 2, 3 ,4 , etc. This means that services never run in the same session as user applications and are therefore protected against attacks from malicious user-mode code. 
<P><EM>Figure 1</EM> shows an example service, RegAlert,&nbsp;running on Windows XP.&nbsp; This service monitors a specific registry&nbsp;value and will display a dialogue box to the user when the contents change.&nbsp; In XP, the console user sees the dialogue and can interact with it easily, but as I mentioned this means that malware can also interact with it.&nbsp;&nbsp;Since users and system services no longer "live" in the same session in Vista, this&nbsp;dialogue is not visible to the console&nbsp;user&nbsp;on a Vista system (though there is a workaround, that I'll discuss shortly).&nbsp; 
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=180 alt="Figure 1: Service dialogue shown on the XP user desktop" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture_thumb.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture_thumb.jpg"></A> 
<P><EM><STRONG>Figure 1: Service dialogue shown on the XP user desktop</STRONG></EM></P></BLOCKQUOTE>
<H4><STRONG>Consequences of Session 0 Isolation</STRONG> </H4>
<P>Any service (or service-hosted driver) that assumes the user is running in Session 0&nbsp;won't work correctly in Windows Vista. Some examples of where this is potentially a problem are: 
<BLOCKQUOTE>
<P><STRONG>UI Interaction</STRONG></P>
<P>As&nbsp;mentioned above, any service that assumes the user is in the same session&nbsp;is&nbsp;going to have problems interacting with users.&nbsp;&nbsp;Services that show dialogs like this should use alternative methods; for example, use the Terminal Services APIs such as <EM>WTSSendMessage</EM> to send messages to the appropriate session or use <EM>CreateProcessAsUser</EM> to create a new process in the user’s session. </P></BLOCKQUOTE>
<BLOCKQUOTE>
<P><STRONG>Window Messages</STRONG> 
<P>If a services and applications use window message functions such as SendMessage and PostMessage to&nbsp;interact&nbsp;they are not going to work as the session isolation means they will have isolated message queues. </P></BLOCKQUOTE>
<BLOCKQUOTE>
<P><STRONG>Using Named Objects</STRONG> 
<P>For services running in Session 0, named objects they create are usually in the \BaseNamedObjects\ namespace. However, user applications that try to open these&nbsp;objects using the default&nbsp;<STRONG>Local\</STRONG> prefix are going to have problems as the objects are not local to the user session as they were in XP.&nbsp;The proper thing to do here is to create the object with the explicit&nbsp;<STRONG>Global\</STRONG> prefix. </P></BLOCKQUOTE>
<P>In actual fact these implications for services are also&nbsp;a problem with <EM>Fast User Switching</EM> (FUS) in Windows XP because&nbsp;FUS users all run in&nbsp;different sessions. Services that assume that the user is running in Session 0 encounter the same issues as above when subsequent users log on&nbsp;using FUS. Services&nbsp;that work fine with FUS are likely to be ok in Vista, but should be thoroughly tested before migration. 
<H4><STRONG>Interactive Service Detection Service</STRONG> </H4>
<P>To help work with legacy services that send dialogue boxes to the Session 0 desktop a new system service, the <EM>Interactive Service Detection Service</EM> (UI0Detect), is available.&nbsp;&nbsp; 
<P>The UI0Detect service notifies the user when a dialogue box or window&nbsp;appears in Session 0. Information about each of the last ten dialogue boxes will appear in turn. 
<P><EM>Figure 2</EM> shows the RegAlert service running on a Vista system.&nbsp; This time, the dialogue is not displayed to the user; instead the UI0detect shows its own dialogue detailing the service that wants to interact with the user. 
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture2_1.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture2_1.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture2_1.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=179 alt="Figure 2: UI0detect service alerts the user that a dialogue was shown in Session 0" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture2_thumb_1.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture2_thumb_1.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture2_thumb_1.jpg"></A> 
<P><EM><STRONG>Figure 2: UI0detect service alerts the user that a dialogue was shown in Session 0</STRONG></EM></P></BLOCKQUOTE>
<P>At this point users can: 
<P>•&nbsp;&nbsp;&nbsp; Respond to the dialogue box immediately by clicking&nbsp;the "Show me the message" button&nbsp;to switch to Session 0, interact with the dialogue box, then switch back to their session. 
<P>•&nbsp;&nbsp;&nbsp; Be reminded again in 5 minutes. They will continue to be reminded until the dialogue box closes. 
<P><EM>Figure 3</EM> shows what the user will see if they select the "Show me the message" option shown in <EM>Figure 2</EM>.&nbsp; The user can then interact with the dialogue as they would in XP, but the critical difference is that other applications running on the user's desktop are prevented from any interaction. 
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture3.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture3.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture3.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=179 alt="Figure 3: the Session 0 desktop showing the service dialogue" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture3_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture3_thumb.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture3_thumb.jpg"></A> 
<P><STRONG><EM>Figure 3: the Session 0&nbsp;desktop showing the service dialogue</EM></STRONG></P></BLOCKQUOTE>
<P>The UI0detect service can notify users logged on at the physical machine or via Remote Desktop. 
<H2><STRONG>Privilege&nbsp;Management</STRONG> </H2>
<P>Windows Vista now runs many services under accounts that have a lower level of privilege than the&nbsp;<EM>LocalSystem</EM> account that was typically used in previous Windows versions.&nbsp; In addition, service developers (and administrators)&nbsp;can have their service declare to the <EM>Service Control Manager</EM> (SCM) which privileges they actually need and the SCM then gives the service a “filtered” token, with just those privileges. This means that even if the service is compromised the rights gained by the hacker are limited to only those the service uses and not the full set granted to LocalSystem, for example. 
<P>Administrators can use the built-in <EM>SC</EM> command to manage the privileges of a given service, so that legacy services (which don’t declare their privilege needs), can also be restricted: 
<BLOCKQUOTE>
<P><STRONG>Querying Service Privileges<BR></STRONG>The privileges allowed to a particular service can be queried using the qprivs option: 
<P><EM>SC [server] qprivs [service name]</EM> 
<P align=left><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Captur3.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Captur3.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Captur3.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=130 alt="Figure 4: Showing the privileges allowed for the Windows Installer Service" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Captur3_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Captur3_thumb.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Captur3_thumb.jpg"></A> </P>
<P align=left><EM><STRONG>Figure 4: Showing the privileges allowed for the Windows Installer Service</STRONG></EM> 
<P align=left><STRONG><EM></EM></STRONG>
<P><STRONG>Setting Service Privileges</STRONG><BR>The privileges allowed to a particular service can be set using the privs option: </P>
<P><EM>SC&nbsp; [server]&nbsp; privs [service name] [privilege1/privilege2/...]</EM> 
<P>For example, to allow the Windows Installer service on the local system only the "act as part of the operating system" and "debug programs" rights, use this command: 
<P><EM>SC privs msiserver SeTcbPrivilege/SeDebugPrivilege</EM> 
<P>Or, to clear all privileges set for the Windows Installer, use this command: 
<P><EM>SC privs msiserver /</EM> </P></BLOCKQUOTE>
<P>The privileges for a particular service can be set programmatically using the <A href="https://msdn2.microsoft.com/en-us/library/ms681988.aspx" mce_href="https://msdn2.microsoft.com/en-us/library/ms681988.aspx">ChangeServiceConfig2</A> API and are stored in clear text here in the registry: 
<BLOCKQUOTE>
<P><EM>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\&lt;service name&gt;\ RequiredPrivileges</EM></P></BLOCKQUOTE>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture4.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture4.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture4.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=97 alt="Figure 5: Windows Installer service privileges shown in the registry" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture4_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture4_thumb.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture4_thumb.jpg"></A> 
<P><EM><STRONG>Figure 5: Windows Installer service privileges shown in the registry</STRONG></EM> 
<P><STRONG><EM></EM></STRONG>&nbsp;</P></BLOCKQUOTE>
<H2><STRONG>Service&nbsp;Isolation</STRONG>&nbsp;</H2>
<P>The final tool available for securing services is the ability to restrict object access for system services as if the service itself is a user - this is known as <EM>Service Isolation</EM>.&nbsp; In Vista, the SCM can create a new <EM>Security Identifier</EM> (SID) for the service itself (hence, it's called a <EM>per-service SID</EM>).&nbsp; That is, the service will have&nbsp;a new, unique, SID that can be used to grant/deny it permissions to files, etc regardless of the account the service runs under. 
<P>The SCM adds the&nbsp;service SID to the security token used when the service is running&nbsp;and it is&nbsp;possible for Administrators to apply a blanket restriction on any “write” operations by the service by setting the SID type.&nbsp; 
<P>The SID type can be: 
<BLOCKQUOTE>
<P>NONE - new SID type is not used 
<P>RESTRICTED - SID is restricted from writing to files, registry, etc unless explicitly granted access 
<P>UNRESTRICTED - new SID is created and added to the token, but write operations are not automatically&nbsp;restricted</P></BLOCKQUOTE>
<P>Again this setting can be managed with the SC command: 
<BLOCKQUOTE>
<P><STRONG>Viewing the Current SID Type</STRONG> 
<P>To query the current type of the service SID, use this command: 
<P><EM>SC [server] qsidtype [service name]</EM></P></BLOCKQUOTE>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture5.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture5.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture5.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=47 alt="Figure 6: Showing the SID type for the RegAlert service" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture5_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture5_thumb.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture5_thumb.jpg"></A> 
<P><STRONG><EM>Figure 6: Showing the SID type for the RegAlert service</EM></STRONG></P></BLOCKQUOTE>
<BLOCKQUOTE>
<P><STRONG>Setting the SID Type</STRONG> 
<P>To set the SID type, use this command:</P></BLOCKQUOTE>
<BLOCKQUOTE>
<P><EM>SC [server] sidtype [service name] [none|restricted|unrestricted]</EM></P></BLOCKQUOTE>
<P>Once the SID is restricted, the service will not be able to write to any resources. Administrator can then use normal file/registry permissions to allow the service access to only the resources they want it to access. 
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture6.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture6.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture6.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=139 alt="Figure 7: File permissions for the RegAlert service" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture6_thumb.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture6_thumb.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/ServiceHardeninginWindowsVista_DA57/Capture6_thumb.jpg"></A> 
<P><STRONG><EM>Figure 7: File permissions for the RegAlert service</EM></STRONG></P></BLOCKQUOTE>
<H2><STRONG>Further Reading</STRONG></H2>
<P>This is just a brief look at a couple of changes I found interesting.&nbsp; For more detail on these and other improvements, have a look at these documents: 
<BLOCKQUOTE>
<P><A class="" title="Services in Windows Vista" href="https://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/Vista_Services.doc" target=services mce_href="https://download.microsoft.com/download/9/c/5/9c5b2167-8017-4bae-9fde-d599bac8184a/Vista_Services.doc">Services in Windows Vista</A> 
<P><A class="" title="Impact of Session 0 Isolation" href="https://www.microsoft.com/whdc/system/vista/services.mspx" target=impact mce_href="https://www.microsoft.com/whdc/system/vista/services.mspx">Impact of Session 0 Isolation on Services and Drivers in Windows Vista</A> </P></BLOCKQUOTE>]]></content:encoded>
    </item>
    <item>
      <title>Windows Vista File and Registry Virtualisation</title>
      <link>https://docs.microsoft.com/archive/blogs/richard_macdonald/windows-vista-file-and-registry-virtualisation</link>
      <pubDate>Fri, 18 May 2007 08:50:00 GMT</pubDate>
      <dc:creator><![CDATA[UniqueName1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/richard_macdonald/2007/05/18/windows-vista-file-and-registry-virtualisation/</guid>
      <description><![CDATA[Windows Vista is designed to be more secure than previous versions of Windows. Part of the...]]></description>
      <content:encoded><![CDATA[Windows Vista is designed to be more secure than previous versions of Windows. Part of the improvements are related to <I>User Account Control </I>(UAC), which encourages the good practice of not logging on with an Administrator account (and even if you do, it limits your available rights by default). While this is good for security, it can be problematic when dealing with legacy application, many of which were developed with the expectation that the user can make changes to locations such as the <I>Windows</I> directory. <BR><BR>Ideally, applications should be re-written or patched to make them compliant with Windows Vista security, but where this is not possible Windows Vista provides a new feature that will help alleviate problems in this area. The feature is known as <I>File and Registry Virtualisation</I> (FARV).&nbsp; Below is a brief overview of FARV:<BR><BR><BR>
<H3>How File and Registry Virtualisation Helps</H3>FARV presents a “virtual” view of certain parts of the filesystem and registry to legacy applications. That is, the legacy application can read and write to what it thinks is the correct location in the registry and filesystem, but any changes are actually redirected to a user-specific location. <BR><BR>File changes are redirected to the following location: 
<BLOCKQUOTE><I>%UserProfile%\AppData\Local\VirtualStore</I> </BLOCKQUOTE>This directory contains subdirectories matching the location that was redirected. For example, if changes were redirected from the <I>Windows</I> directory, the store will look similar to this: <BR><BR>
<BLOCKQUOTE>
<P><I><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled2%5B2%5D.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled2%5B2%5D.png" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled2%5B2%5D.png" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=151 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled2_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled2_thumb.png" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled2_thumb.png"></A>&nbsp;</I></P>
<P><I>The FARV VirtualStore, showing some redirected folders.</I> </P></BLOCKQUOTE>
<P>If you navigate to the <I>Windows</I> drectory in Windows Explorer, you will <I>not</I> see the virtual version of the file. Explorer will show the actual content of folder. However, it does alert you to the fact that virtual copies of some files exist by a new button on the taskbar: </P>
<BLOCKQUOTE>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Capture%5B6%5D.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Capture%5B6%5D.jpg" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Capture%5B6%5D.jpg" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=104 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Capture_thumb%5B2%5D.jpg" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Capture_thumb%5B2%5D.jpg" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Capture_thumb%5B2%5D.jpg"></A> <BR><EM>Explorer alerts you to the existence of user-specific files in the VirtualStore</EM></P></BLOCKQUOTE>
<P>Clicking this button takes you to the virtual store mentioned above. <BR><BR>A similar store exists for redirected Registry changes: </P>
<BLOCKQUOTE>HKEY_CLASSES_ROOT\VirtualStore </BLOCKQUOTE>This may appear to be a system-wide store since it doesn’t contain any user-specific information in the path. However, this key is actually just a pointer to the following location: 
<BLOCKQUOTE>HKEY_USERS\&lt;user SID&gt;\Software\Classes\VirtualStore <BR>[also accessible via: HKEY_CURRENT_USER\Software\Classes\VirtualStore] </BLOCKQUOTE>So, registry changes <I>are</I> also stored on a per-user basis. <BR><BR><BR>
<H3>What is Virtualised?</H3>File and Registry Virtualisation is hard-coded to present a virtual view of only these locations in the filesystem and registry: 
<BLOCKQUOTE>Registry (includes subkeys) 
<BLOCKQUOTE></I>HKEY_LOCAL_MACHINE\Software</I> </BLOCKQUOTE>Exceptions are: 
<UL>
<LI>HKLM\Software\Microsoft\Windows 
<LI>HMLM\Software\Microsoft\Windows NT 
<LI>Other subkeys under “Microsoft” </LI></UL>Keys can be excluded by setting the new DONT_VIRTUALIZE flag for the key using the </I>Reg.exe</I> tool. <BR><BR>Filesystem (includes subfolders) 
<UL>
<LI>%SystemRoot% (e.g. C:\Windows) 
<LI>%ProgramFiles% (e.g. C:\Program Files) 
<LI>%AllUsersProfile% (e.g. C:\ProgramData – previously C:\Documents and Settings\All Users) </LI></UL>Binary executable files (.exe, .dll, .sys, etc) are excluded from virtualisation. Additional extensions can be added here: 
<BLOCKQUOTE>HKLM\System\CurrentControlSet\Services\Luafv\Parameters\ExcludedExtensionsAdd </BLOCKQUOTE></BLOCKQUOTE>These are locations where it is common for legacy applications to store their settings and data, but which should be secured against unauthorised access. There is no mechanism for adding additional folders or registry keys.<BR><BR><BR>
<H3>When is File and Registry Virtualisation Enabled?</H3>File and Registry Virtualisation is an “opt-out” feature. That is, it is enabled for an application unless Windows is told otherwise. The mechanisms that Windows uses to tell if it should disable FARV are: 
<OL>
<LI><B>Process Target Architecture</B>. FARV is not enabled for 64-bit applications. 
<LI><B>Logon Type</B>. Only activity originating from an interactive logon is virtualised. So, for example, any file writes due to file sharing across the network are not subject to FARV. 
<LI><B>Running as Administrator</B>. If an application was launched with a Full Token, then Windows does not enable FARV since it is assumed that the user has appropriate access permissions for the locations discussed above. 
<LI><B>Application Manifest</B>. If the application has an associated manifest file (embedded or external) that contains the new requestedExecutionLevel entry, Windows assumes the application has been written specifically for Windows Vista and thus will deal appropriately with security restrictions. 
<LI><B>User Intervention</B>. If the user decides that FARV is not required, they can disable it using Task Manager: <BR><BR><I><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled%5B4%5D.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled%5B4%5D.png" mce_href="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled%5B4%5D.png" atomicselection="true"><IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=101 src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_technet/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled_thumb.png" original-url="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled_thumb.png" width=240 border=0 mce_src="https://blogs.technet.com/blogfiles/richard_macdonald/WindowsLiveWriter/WindowsVistaFileandRegistryVirtualisatio_C020/Untitled_thumb.png"></A>&nbsp;</I></LI></OL>
<BLOCKQUOTE>
<P><I>Virtualisation status shown in Task Manager</I> <BR><BR>Right-clicking on an entry in Task Manager shows a context menu with an option to toggle FARV on and off. </P></BLOCKQUOTE><BR>
<H3>Limitations of File and Registry Virtualisation</H3>FARV is not intended to be a complete answer to dealing with poorly written legacy applications. It is really a stop-gap mechanism to help with migration to the new Windows Vista Security model. It is likely that this feature will be dropped from future versions of Windows, so application developers should not rely on it for the proper operation of their applications, but should instead change their applications to work within the security constraints of Windows Vista. <BR><BR>Some places where FARV is limited are: 
<UL>
<LI><B>Target locations</B>. The locations handled by FARV are hard-coded and apart from the Registry exclusions mentioned above users cannot alter this list. Nor can the user specify where the redirected data is stored. 
<LI><B>Machine-wide changes</B>. FARV works on a per-user basis, thus changes stored by one user are not seen by other users. Also, since user-specific data over-ride any actual data, Administrators have no way to make changes for all users at the same time. 
<LI><B>Roaming users</B>. FARV data that is stored in the local filesystem and does not roam with the user when they move to another computer. 
<LI><B>Application functionality</B>. For poorly written applications that may rely on settings stored in the virtualised locations to determine what they allow users to do, etc, this can be by-passed by the user changing data in the virtualised location, which over- rides any “real” settings in the restricted locations. Even if this does not result in a security problem (which it might), it could still lead to unexpected behaviour. </LI></UL>]]></content:encoded>
    </item>
  </channel>
</rss>