Audit Start Menu Shortcuts Using WSH
by John Loomes
This script demonstrates several key WSH techniques: i) How to use the WScript shortcut object to access shortcut properties ii) How to use the Excel Application object to create and write to Excel Spreadsheets. iii) How to use the FileSystem Object to traverse folders and files.
This script demonstrates several key WSH techniques...The script itself takes a Path an an argument, it then traverses all the folders in this path, gets the names and properties of all the shortcuts it finds, and writes this information to an Excel Spreadsheet. You can use this script to effectively 'Audit' a start menu, a fairly crude technique of auditing installed software if you like.....
The syntax to run the script is as follows: Wscript.exe AuditSM.vbs \\myserver\mystartmenu
The script will run on Win2k or NT4 (providing WSH components are installed)
Option Explicit
dim objFS, objRoot, objFolder, objArgs, objXL, objWShell, objShortCut
dim szRoot, szMsg, szFileName, szTarget
Dim nRetVal
Dim intIndex
set objFS = CreateObject( "Scripting.FileSystemObject" )
set objXL = CreateObject( "Excel.Application" )
set objArgs = Wscript.Arguments
set objWShell = CreateObject ( "Wscript.Shell" )
intIndex = 1
objXL.Visible = TRUE
objXL.WorkBooks.Add
If objArgs.Count >= 1 then
szRoot = objArgs.Item(0)
Else szMsg = "No path Specified"
Wscript.Echo szMsg
Wscript.Quit
End If
if objFS.FolderExists( szRoot ) then
dim objFile
set objRoot = objFS.GetFolder( szRoot )
for each objFolder in objRoot.SubFolders
if IsObject( objFolder ) then
nRetVal = DisplayFolder( objFolder, intIndex )
end if
next
for each objFile in objRoot.Files
if IsObject( objFile ) then
nRetVal = DisplayFile( objFile, intIndex )
intIndex = intIndex + 1
objXL.Cells(intIndex, 1).Select
end if
next
end if
function DisplayFolder(objFolder, intIndex)
dim objSub, objFile
dim nRetVal
for each objSub in objFolder.SubFolders
nRetVal = DisplayFolder( objSub, intIndex )
next
for each objFile in objFolder.Files
nRetVal = DisplayFile( objFile, intIndex )
intIndex = intIndex + 1
objXL.Cells(intIndex, 1).Select
next
end function
function DisplayFile( objFile, intIndex )
dim intIndexPerm
dim saPermissions
dim szACL
dim arACL(100)
dim intACL
dim szACLList
dim intACLIndex
szFileName = objFile.Path
If objXL.Cells(intIndex, 1).Value <> objFile.Name Then
objXL.Cells(intIndex, 1).Value = objFile.Name
end if
If objXL.Cells(intIndex, 2).Value <> Right(objFile.ParentFolder, Len(objFile.ParentFolder) - Len(szRoot)) Then
ObjXL.Cells(intIndex, 2).Value = Right(objFile.ParentFolder, Len(objFile.ParentFolder) - Len(szRoot))
end if
On Error Resume Next
set objShortCut = objWShell.CreateShortCut( szFileName )
szTarget = objShortCut.TargetPath
If Err.Number <> 0 Then Exit Function
If objXL.Cells(intIndex, 3).Value <> szTarget Then
objXL.Cells(intIndex, 3).Value = szTarget
end if
if objXL.Cells(intIndex, 4).Value <> objShortCut.WorkingDirectory Then
objXL.Cells(intIndex, 4).Value = objShortCut.WorkingDirectory
end if
if objXL.Cells(intIndex, 5).Value <> objShortCut.IconLocation Then
objXL.Cells(intIndex, 5).Value = objShortCut.IconLocation
end if
objShortCut = vbNull
End
Function
Please note that
this is provided 'as is' with no warranties i.e. dont blame me if it
all goes wrong!

