Jump to content

SetupComplete.cmd and files not deleted


Recommended Posts

HI

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"
Wscript.Quit
End If


If objFSO.FolderExists(objArgs(0)) Then
DeleteFolder objArgs(0)
ElseIf objFSO.FileExists(objArgs(0)) Then
KillObject(objArgs(0))
Else
Wscript.Echo "Can't find path: " & objArgs(0)
Wscript.Quit
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."
Else
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
DeleteFolder(objSubFolder.Path)
Next
For Each objFile In objFolder.Files
objFSO.GetFile(objFile).Attributes = 0
KillObject objFile.Path
Next
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.

THANKS

BYE

Edited by balubeto
Link to comment
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...