I am working on some materials for an upcoming class, and found this script that we run in one of our site’s logon scripts. It warns the user to remove files from their desktop using the Microsoft Agent and IE for file display.
‘ NAME: FilesOnDesktop.vbs
‘
‘ AUTHOR: Alan Kaplan , alan dot akaplan at va dot gov
‘ DATE : 1/26/2007
‘
‘ COMMENT: Warns users that files on desktop are not backed up.
‘ v 1.1 adds path and computername for help desk.
‘==========================================================================
Option Explicit
dim wshShell
Set wshShell = WScript.CreateObject(“WScript.Shell”)
Dim strIgnore, strDesktop, message
Dim iCount
Dim strAgentName, objAgent, objCharacter, WinDir
Dim strAgentPath
‘note this Is a String listing of extensions, Not an Array
‘The list is not required
strIgnore = “LNK,URL,INI,PIF,INF,HISTORY,VBS,EXE”
‘if you leave in URLs, internet shortcuts are noted
‘strIgnore = “LNK,INI,PIF,INF”
strDesktop = wshShell.ExpandEnvironmentStrings(“%USERPROFILE%”&”Desktop”)
iCount = 0
dim fso
Set fso = CreateObject(“Scripting.FileSystemObject”)
message = “If your hard drive crashes, or this computer is replaced, ” & _
“you will lose these files found on your desktop:” & VbCrLf
check strDesktop
message = message & VbCrLf & VbCrLf & _
“Copy these files, internet shortcuts and any other files that you may have stored on this computer to your ” & _
“network home directory now to avoid possible data loss!” & VbCrLf & VbCrLf & _
” If you need assistance, please call your Service Application Coordinator.” & VbCrLf & VbCrLf & _
“Your desktop path is ” & strDesktop & _
” on ” & wshShell.ExpandEnvironmentStrings(“%COMPUTERNAME%”) & “.” & VbCrLf
if iCount > 1 Then
RunAgent
IEMessage Message,”DATA LOSS WARNING!”,”lt Blue”,600,750,True
Wscript.Sleep 5000
objCharacter.Stop
objCharacter.Hide
End If
‘================ Functions and Subs ==============
Sub RunAgent
strAgentName = “Merlin”
WinDir = wshShell.ExpandEnvironmentStrings(“%Windir%”)
strAgentPath = windir & “MsagentChars” & strAgentName & “.acs”
Set objAgent = CreateObject(“Agent.Control.2”)
objAgent.Connected = True
objAgent.Characters.Load strAgentName, strAgentPath
Set objCharacter = objAgent.Characters.Character(strAgentName)
objCharacter.Show
objCharacter.Play “GetAttention”
objCharacter.Play “Confused”
objCharacter.Speak “I am confused. Why do you have files on your desktop?”
objCharacter.Play “GestureLeft”
objCharacter.Speak “Read the warning. It is important.”
Wscript.Sleep 10000
objCharacter.Play “Idle1_2”
‘ Do While objCharacter.Visible = TRUE
‘ Wscript.Sleep 250
‘ Loop
End Sub
Sub check (fldname)
iCount = iCount + 1
‘On Error Resume Next
Dim subfolders,files,folder,file,fldr,ofiles,strExt,strFMessage, strFileName
Set fldr = fso.GetFolder(fldname)
Set subfolders = fldr.SubFolders
Set ofiles = fldr.Files
If iCount = 1 Then
strFMessage = “On Desktop”
Else
strFMessage = “In desktop folder “
End If
‘Display the path and all of the folders.
message = message & VbCrLf & strFMessage & mid(fldr.Path,Len(strDesktop)+2) & “:” & VbCrLf
‘Display all of the files.
For Each file in ofiles
strExt = ucase(fso.GetExtensionName(file.name))
If InStr(strIgnore,strExt) = 0 Then
iCount = iCount + 1
strFileName = file.name
If strExt = “URL” Then
strFileName = “[Internet Shortcut] ” & strFileName
End If
message = message & string(5,”-“)& “> ” & strFileName & VbCrLf
End If
Next
‘Recurse all of the subfolders.
For Each folder in subfolders
check folder
Next
Set subfolders = Nothing
Set files = Nothing
End Sub
Sub IEMessage(message,strTitle,strBGColor,iHeight,IWidth,bPrint)
Dim oIE, oPage
Dim strComputer, strBorder, strFont
Dim strFormatOn, strFormatOff, iTSView
Set oIE = CreateObject(“InternetExplorer.Application”)
iTSview = 0 ‘1 for troubleshooting, allows view source menu
strBorder = 1 ‘Best appearance is strBorder 1
strFont = “Arial”
oIE.Navigate “about:blank”
oIE.AddressBar = False
oIE.Height = iHeight
oIE.Width = IWidth
oIE.MenuBar = iTSView
oIE.ToolBar = iTSView
oIE.StatusBar = False
oIE.Left = 150
oIE.Top = 50
oIE.Visible = 1
message = Replace(message,vbcrlf,”<br>”& vbcrlf)
Do While (oIE.Busy)
Wscript.Sleep 250
Loop
Set oPage = oIE.Document
oPage.Open
oPage.Writeln “<html><head><title>” & strTitle & “</title></head>”
oPage.Writeln “<body bgcolor='”& strBGcolor & “‘>”
oPage.Writeln “<Font face ='”& strFont & “‘>”
oPage.Writeln “<Center><h2>” & strTitle & “</center></h2>”
oPage.Writeln “<Span>” & Message & “</Span><br>”
If bPrint Then
oPage.WriteLn “<input id=runbutton type=’button’ value=’Print List’ name=’printbtn’ onClick=’window.print();’>”
End If
oPage.Writeln “</font></body></html>”
oPage.Write()
oPage.Close
End Sub