Can someone explain the following vbs script code

Can someone explain the following vbs script code:

Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set wshShell    = WScript.CreateObject("WScript.Shell")

'initialize logging
 strLogFile = wshShell.ExpandEnvironmentStrings("%TEMP%\CitrixReceiverShortcutClean.log.txt")
 Set objLogFile = objFSO.OpenTextFile(strLogFile, 8, True)
 objLogFile.WriteLine Now & ": Logging Initialized"

'get list of folders in C:\Users
 Set objFolder = objFSO.GetFolder("C:\Users")
 objLogFile.WriteLine Now & ": Got list of user folders under C:\Users"

For Each UserSubFolder in objFolder.SubFolders
	'search the users start menu for Citrix shortcuts
	objStartFolder = UserSubFolder.Path & "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs"
	objLogFile.WriteLine Now & ": Searching folder: " & objStartFolder
	If objFSO.FolderExists(objStartFolder) Then
		Set objSearchFolder = objFSO.GetFolder(objStartFolder)
		Set colFiles = objSearchFolder.Files
		For Each objFile in colFiles
		  If InStr(objFile.Name, ".lnk") Then
			IsCitrixShortcut objSearchFolder.Path & "\" & objFile.Name
		  End If
		Next

		ShowSubfolders objFSO.GetFolder(objStartFolder)

		' now search the users desktop for Citrix shortcuts
		objStartFolder = UserSubFolder.Path & "\Desktop"
		objLogFile.WriteLine Now & ": Searching folder: " & objStartFolder

		Set objSearchFolder = objFSO.GetFolder(objStartFolder)
		Set colFiles = objSearchFolder.Files
		For Each objFile in colFiles
			If InStr(objFile.Name, ".lnk") Then
				IsCitrixShortcut objSearchFolder.Path & "\" & objFile.Name
			End If
		Next
		ShowSubfolders objFSO.GetFolder(objStartFolder)
	End If
Next

	objLogFile.WriteLine Now & ": Script complete"

Sub ShowSubFolders(Folder)
     For Each Subfolder in Folder.SubFolders
         Set objFolder = objFSO.GetFolder(Subfolder.Path)
         Set colFiles = objFolder.Files
         For Each objFile in colFiles
		  If InStr(objFile.Name, ".lnk") Then
			IsCitrixShortcut SubFolder.Path & "\" & objFile.Name
		  End If
         Next
         ShowSubFolders Subfolder
     Next
 End Sub

 

Sub IsCitrixShortcut(strShortcut)
  ' CreateShortcut works like a GetShortcut when the shortcut already exists!
  Set objShortcut2 = wshShell.CreateShortcut(strShortcut)
  'WScript.Echo "Target Path       : " & objShortcut2.TargetPath
  If InStr(objShortcut2.TargetPath, "pnagent.exe") Then
   objLogFile.WriteLine Now & ": Deleting PNAgent Shortcut: " & strShortcut
   objFSO.DeleteFile strShortcut, true
  End If
 End Sub

Open in new window

llaravaAsked:
Who is Participating?
 
Kyle AbrahamsSenior .Net DeveloperCommented:
For each folder in c:\users
Go to the start menu path  (C:\<USER>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\)
and it's recursively looking at each shortcut where the target Path contains "pnagent.exe"
If it finds it, it deletes it, logging it to a log file (%TEMP%\CitrixReceiverShortcutClean.log.txt)
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
Auto Close.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.