I’ve always wanted to blog about undocumented features and today’s that day. Recently, I’ve been demonstrating how you can save time on scripting by using the various classes in the ZTIUtility.vbs when creating your custom deployment scripts. However, there’s no documentation or examples explaining how to access the file handling functions in the Utility class. In fact the MDT scripts use the oFSO.DeleteFile and oFSO.MoveFile methods to manage files rather than the available file handling functions. So here’s my article on the undocumented file handling methods.
There’s a list of File System Object functions in the ZTIUtility.vbs from lines 3872 to 4065. These can be called by using oFileHandling property and the relative functions as the methods. I could not find any information on Google or anywhere on oFileHandling.
To Delete a file.
I’ve created a file called C:\Test.txt that I intend to delete. The function DeleteFile(sFile) will attempt to delete a target file and create a log file entry displaying either success or failure.
To begin with, create an MDT Scripting Template (as per previous blogs). Then add this custom code.
Dim sTargetFile sTargetFile = "C:\test.txt" oFileHandling.DeleteFile sTargetFile
Run the script twice. The first time, your script will be deleted and the second time, you will get an error. You will find this logged under MININT\SMSOSD\OSDLOGS\ and the log file will have the same prefix as your script. This will also be logged in the BDD.log file.
There’s a list of other file handling functions below. I’ve also written some simple code examples to help you get started. You can use these examples to manage all your basic file management tasks.
To Move a File.
Dim sFile, sDest sFile = "C:\Folder1\test.txt" sDest = "C:\Folder2\" '// Move a file. oFileHandling.MoveFile sFile, sDest
To Copy a File.
Function CopyFile(sFile,sDest, bOverwrite)
Dim sFile, sDest, bOverwrite sFile = "C:\Folder1\test.txt" sDest = "C:\Folder2\" bOverwrite = True ' // Copy a file. oFileHandling.CopyFile sFile, sDest, bOverwrite
To Copy a Folder.
Function CopyFolder (sSource, sDest, bOverwrite)
Dim sSource, sDest, bOverwrite sSource = "C:\Folder1" sDest = "C:\Folder2" bOverwrite = True ' // Copy a folder. oFileHandling.CopyFolder sSource, sDest, bOverwrite
To Move a Folder.
Function MoveFolder (sSource, sDest )
Dim sSource, sDest sSource = "C:\Folder1" sDest = "C:\Folder2\" ' // Move a folder. oFileHandling.MoveFolder sSource, sDest
To Delete a Folder and Subdirectorys.
Dim sPath sPath = "C:\Folder1" ' // Delete a folder and subfolders. oFileHandling.RemoveFolder sPath