Share via


A handy WMI script to check for pending file rename operations

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

Comments

  • Anonymous
    August 15, 2008
    C'mon no more VBScript. We are in the PowerShell era ;-)

  • Anonymous
    August 15, 2008
    Tom Mills posted a great post on his blog about a handy wmi script to check fo pending file rename operations

  • Anonymous
    July 12, 2009
    Do this script support on Windows 2008 servers as well ? I was trying to install the SQL 2008 and got the pending reboot check failed. On googling this, i got to know the registry key which you used in your script, but unfortunately the key was not there on my Windows 2008 server. I tried on 2-3 Windows 2008 server and the key was not there. Any pointers on the solution to this issue ?

  • Anonymous
    July 12, 2009
    This may (and probably did) change in Windows Server 2008. I'll check and see if I can find out how it's done.