One of the things I really like about VBScript is the ability to use conditional logic. As promised in an earlier blog entry, here is a good example.
We found that in order for a particular software product to install (that product name shall remain nameless) and function properly; the IRPStackSize needs to be adjusted to a minimum size. The problem? Many desktops and servers have this key set to a larger value than the minimum required. In that event we do not want to change it to perhaps a smaller value, potentially reintroducing issues. Also, to add to the complexity of the problem at hand this key may, or may not exist.
If you review the logic of this VBScript, we test to see if the value exists, if a null is found, it means the key does not exist, create the key with the proper value. If the key and value exist, check the value to see if the new value needs to replace the existing value.
This gave us the ability to use this script as part of the installation process minimizing risk that it would introduce any new issues.
Here are a couple of kb articles that explain one of the more common errors with IRPStackSize and the resolution.
Event ID 2011
Not enough server storage is available to process this command.
http://support.microsoft.com/kb/106167
Description of the IRPStackSize parameter in Windows 2000, in Windows XP, and in Windows Server 2003
http://support.microsoft.com/kb/285089
Excerpt: The IRPStackSize parameter specifies the number of stack locations in I/O request packets (IRPs) that are used by Windows 2000 Server, by Windows Server 2003, and by Windows XP. You may have to increase this number for certain transports, for media access control (MAC) drivers, or for file system drivers. Each stack uses 36 bytes of memory for each receive buffer.
As always, test before deploying, most of all have fun…
' *********************************************************************
' 2/6/2008
' Adjust size of IRP Stack Size - specifically for xyz product
' install on servers.
' Key location:
' HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
' > IRPStackSize
' Optimum size of value is 30, or larger... if value is less than 30, modify.
' **********************************************************************
'
'
OPTION EXPLICIT
const HKEY_LOCAL_MACHINE = &H80000002
dim strKeyPathRoot
dim strKeyPath
dim strComputer
dim strValueName
dim oReg
dim strValue
dim strNewValue
dim dwValue
Dim objWMIService
Dim colServiceList
DIM objService
strValueName = "IRPStackSize"
‘ change IRPStackSize value here, if required
strNewValue = 30
strComputer = "."
' Read IRP Stacksize... adjust as needed
IRPStackSize
Sub IRPStackSize
On Error Resume Next
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPathRoot = "SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters"
' this logic allows us to extend to keys below the path
strKeyPath = strKeyPathRoot
' retrieve the IRPStackSize value
oReg.GetDWordValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
' strValue contains a NULL if not found...
if strValue & "" = "" Then
' key name and value not found, create key set to strNewValue
' wscript.echo "strValue = " & strValue & " - Empty/no key, add one"
oReg.SetDWordValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strNewValue
Else
If strValue < strNewValue Then
' value is set to something less than strNewValue, adjust
' wscript.echo "strValue = " & strValue & " - value < 30, update!"
oReg.SetDWordValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strNewValue
Else
' Nothing to do
' wscript.echo "strValue = " & strValue & " - nothing to do"
End If
End if
End Sub