Here's a script that will check for and display any pending file rename operations. Windows stores the information on locked files that need to be renamed or deleted at startup. This is usually a result of an install or update that tries to replace files that are in use. This script was developed to use as a pre-installation step for a command line install routine that did not report pending file rename operations back to the user. If pending operations were found, the server was rebooted before the install was run. Using this script saved time and effort as the number of servers to be rebooted was known in advance of the install and could be handled more efficiently.

It uses the WMI StdRegProv class and its GetMultiStringValue method to query the registry and display the results.

 

 '---------------------------------------------------------------------
'Name:   CheckPendingFileRenameOperations
'Programmer: Tom Mills/Microsoft Corp.
'Date:  8/14/2008
'Purpose: Checks registry key for pending file rename operations
'Notes:  None
'---------------------------------------------------------------------

CONST HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
strFileOps = ""

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
    strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager"

strValueName = "PendingFileRenameOperations"

Return = objReg.GetMultiStringValue(HKEY_LOCAL_MACHINE,strKeyPath,_
    strValueName,arrValues)

If (Return = 0) And (Err.Number = 0) Then  
    For Each strValue In arrValues
    strFileOps = strFileOps & chr(13) & strValue
Next

    WScript.Echo "Pending File Rename Operations Found: " & strFileOps

Else
    If Err.Number = 0 Then
         Wscript.Echo "No Pending File Operations Found"
    Else
         Wscript.Echo "Check Pending File Operations failed. Error = " & Err.Number
    End If
End If

Another (and more sophisticated approach) is to use Windows Powershell. The VBscript was developed for servers that did not have Powershell available.

Here's some links to Powershell scripting info and SQL Server 2008 support for Powershell:

Scripting with Windows PowerShell Script Center

Using the SQL Server PowerShell Provider