Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Thursday, October 14, 2010

Powershell set-ClusterParameter

Powershell is wonderful. That being said there are still dark corners you have to traverse through.

I need to create a Powershell script to create a MSMQ resource on a failover cluster. One of the things I need is to set the IP address using DHCP. Using the UI interface is simple, select the network, click DHCP enabled, click apply. You would think you can do the same thing in Powershell, but it has to work like this:


$clusterGroup = Add-ClusterGroup -InputObject $cluster -Name "MsmqCluster"

# create cluster IP address
$IPClusterResource = add-ClusterResource -InputObject $ClusterGroup -Name "${clusterGroup}-IP" -ResourceType "IP Address"

# find the network name
$ClusterParam = get-ClusterResource "Cluster IP Address"|get-ClusterParameter Network
$NetworkName = new-object Microsoft.FailoverClusters.Powershell.ClusterParameter $IPClusterResource,Network,$ClusterParam.Value
# have to fake an ipaddress and subnet mask
$address = new-object Microsoft.FailoverClusters.Powershell.ClusterParameter $IPClusterResource,address,"10.16.12.101"
$subnetmask = new-object Microsoft.FailoverClusters.Powershell.ClusterParameter $IPClusterResource,subnetmask,"255.255.255.0"

# have to bundle the parameters together and set the parameters in one shot
$setParams = $NetworkName,$address,$subnetmask
$setParams|set-clusterParameter

# now you have to enable NetBIOS before you can Enable Dhcp
set-ClusterParameter -inputObject $IPClusterResource -Name EnableNetBIOS -Value 1
set-ClusterParameter -inputObject $IPClusterResource -Name EnableDhcp -Value 1

Friday, June 04, 2010

Network Load Balancing in Windows

I am using NLB on a prototype I am working on. I have a custom process that listens to custom port and I have two Windows 2008 boxes to act like a web farm. The quick gotcha is that if my process is down but the network on the machine is still up NLB will try to distribute the network load around the two nodes. I was hoping for something a little bit smarter (like figuring out the port has not listener) but that is not the case.

Monday, March 29, 2010

invalid license data. reinstall is required

I have Vista 64 SP2 and Visual Studio 2008 SP1. Monday morning I got this error message when I try to start Visual Studio. MSDN recommends reinstalling Visual Studio.

Luckily the technical support guy reminded to reboot the computer first. The problem goes away.

Tuesday, July 29, 2008

Inconsistent Behaviour

I was helping to troubleshoot a problem with HttpWebRequest where a cookie came from the server but wasn't going back to the server.

The server (say www.foo.com) sends the cookie in the header of the response with attribute domain=www.foo.com. The .Net cookie class interprets this according to RFC 2965 and adds a period (dot) in front of the domain. So when we try to get the cookies for www.foo.com this cookie is not included. Specifying something like

myCookieContainer.GetCookies(new Uri("http://a.www.foo.com")

works though.

The way I understand the RFC is that the domain should be foo.com instead of www.foo.com. However both IE and Firefox accepts this and sends the cookie back so no web server developer or tester would ever pick this up because the major browser works.

Wednesday, June 04, 2008

To shut down a computer in .Net

I was testing something and needed to shutdown a computer. Wanted to look for an example and couldn't found one anywhere. So here is what I have written:


ManagementClass MC = new ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection ObjCol = MC.GetInstances();
//there is only one object in the Collection
foreach (ManagementObject MO in ObjCol)
{
  MO.Scope.Options.EnablePrivileges = true;
  MO.InvokeMethod("Shutdown", null);
}


Note that if you skip the EnablePrivileges line you will get a exception with the message:
Privilege not held

This assumes the identity of the process has the privilege to shutdown the computer under normal conditions.

Tuesday, February 26, 2008

i think this is a bug

I am writing a little app that hosts the Internet Explorer/Webcontrol control to navigate our production site and get some page load values. Somewhere on a page we have the following html snippet:

<input name="foo" type="checkbox" id="foo" />

Both IE and Firefox render this as a checkbox without the check mark.

When I interrogate the attributes inside the HtmlElement object, here is the interesting bit:

GetAttribute("Value") returns "on"
GetAttribute("checked") returns "False"

I wrote a loop to get all the input elements inside the <Form> tag to construct a post data string so the natural choice is to use the Value attribute because it seems to work for all input types. So the post is sending in foo=on for this input. ASP.Net happily interprets it as checkbox value=true and created a different behaviour that took me a while to track down and isolate.

Monday, November 26, 2007

problem of the day

A colleague was trying to write a calculation tool on IIS logs. I recommended him to try the text file driver from Microsoft Jet. He couldn't get it going. The error is:

Cannot Update. Database or object is read-only
Error code is -2147217911 or 0x80040E09

Turns out the file has an extension of ".log". Once I changed it to ".txt" everything works. Can't find an explanation though.

Wednesday, November 21, 2007

gotcha

We got caught in the production system yesterday.

Turns out the problem is that we use System.IO.Path.GetTempFileName() to, well, get a temporary file name to use in a directory. This method, if you read the documentation (which I did not), states that

Creates (emphasis mine) a uniquely named, zero-byte temporary file on disk and returns the full path of that file.

So there is a side-effect by calling this method. But that's not all. In the remarks it said:

The GetTempFileName method will raise an IOException if it is used to create more than 65535 files.

So the production system failed because this method has been called more than 65535 times.

Lessons learned:
(1) RTFM!
(2) the method should be renamed CreateTempFile.

Tuesday, October 23, 2007

Another weird problem

This time it is in our development environment. We are integrating with an external report engine and one of my tasks is to look at some performance statistics to see if we need extra hardware to support the report services. The reporting engine is still a 32-bit process so I wrote a bit of code to thunk down from our 64-bit .Net code to 32-bit before calling the reporting service.

After that I hook up our test/performance harness to make the system run 100 reports. That CPU was under siege for well over 10 minutes. After same tuning and monitoring I realized the CPU was not spent in the reporting process (nor our application services for that matter), it was the 64-bit version of rundll32.exe. Out comes the Sysinternals Process viewer. It turns out rundll32 was running:

rundll32.exe ntprint.dll "printer name"

The process is trying to install a printer. I tried it manually and we don't have the printer driver locally. So I guess this process failed repeatedly but kept trying. I looked up some documentation and found the option to turn off the printing portion of the report and everything works like charm. Just another day in the office...
 
Listed on BlogShares