Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


SetupComplete.cmd and files not deleted

Recommended Posts


I wrote this RemovePending.vbs script used to delete multiple files at the end of a custom installation of Vista SP2 and, then, I inserted, in the SetupComplete.cmd file, the calls to this vbs script. Namely:

Option Explicit
Dim objFSO, objReg, objArgs
Dim objFile, objFolder, objSubFolder
Dim arrObjects, arrOldObjects, strKill

Const HKEY_LOCAL_MACHINE = &H80000002

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objArgs = Wscript.Arguments
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\root\default:StdRegProv")

objReg.GetMultiStringValue HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Session Manager", "PendingFileRenameOperations", ArrOldObjects
If isArray(arrOldObjects) Then strKill = Join(arrOldObjects, vbTab)

If objArgs.Count = 0 Then
Wscript.Echo "Script for scheduling files and folders for removal at next boot" & vbCrLf &_
"Syntax: RemovePending.vbs c:\folder"
End If

If objFSO.FolderExists(objArgs(0)) Then
DeleteFolder objArgs(0)
ElseIf objFSO.FileExists(objArgs(0)) Then
Wscript.Echo "Can't find path: " & objArgs(0)
End If

arrObjects = Split(strKill, vbTab)
objReg.SetMultiStringValue HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Session Manager", "PendingFileRenameOperations", ArrObjects
If Err.number = 0 Then
Wscript.Echo objArgs(0) & " was scheduled for removal at next boot."
Wscript.Echo "Could not schedule object for removal" & vbCrLf & "Error: " & Err.Number & " " & Err.Description
End If

Private Sub DeleteFolder(strFolder)
Set objFolder = objFSO.GetFolder(strFolder)
For Each objSubFolder In objFolder.SubFolders
For Each objFile In objFolder.Files
objFSO.GetFile(objFile).Attributes = 0
KillObject objFile.Path
objFSO.GetFolder(strFolder).Attributes = 0
KillObject strFolder
End Sub

Sub KillObject(strObject)
If Len(strKill) > 0 Then strKill = strKill & vbTab
strKill = strKill & "\??\" & strObject
strKill = strKill & vbTab
End Sub

and, at the end of the SetupComplete.cmd file, I wrote:

cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\Setup\Scripts
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\setupact.log
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\Logs\DPX\setupact.log
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\Panther\setupact.log
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\Panther\UnattendGC\setupact.log
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\setuperr.log
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\Logs\DPX\setuperr.log
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\Panther\setuperr.log
cscript %windir%\Setup\Scripts\RemovePending.vbs %windir%\Panther\UnattendGC\setuperr.log

shutdown /r /t 30

I noticed, however, that some files not are deleted as the %windir%\setupact.log and %windir%\setuperr.log files and the %windir%\Setup\Scripts directory. Why?

P.S: If, however, having finished the installation, I write one of the following commands (%windir%\Setup\Scripts\RemovePending.vbs %windir%\setupact.log or %windir%\Setup\Scripts\RemovePending.vbs %windir%\setuperr.log or %windir%\Setup\Scripts\RemovePending.vbs %windir%\Setup\Scripts )from the command prompt of the administrator, the next time that I restart Vista, these objects are removed as scheduled.



Edited by balubeto

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...