Alan's Blog

"Yeah. I wrote a script that will do that."

Menu
  • About My Blog
Menu

Files on Desktop

Posted on May 23, 2008March 7, 2009 by Alan

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

Leave a Reply

You must be logged in to post a comment.

Search

Please Note

All the scripts are saved as .txt files. Newer files have a “View Script” button which will let you save or open a script in notepad. For earlier posts, the easiest way to download with IE is to right click on the link and use “Save Target As”. Rename file from Name_ext.txt to Name.ext.

To see a full post after searching, please click on the title.

PowerShell Scripts were written with version 3 or later.

https connections are supported.

All new users accounts must be approved, as are comments. Please be patient.  If you find a post error or a script which doesn’t work as expected, I appreciate being notified.  My email is my first name at the domain name, and you are welcome to contact me that way.

Tags

1E ACLS Active Directory ActiveDirectory ADSI Advanced Functions Audit Change Administrator Password COMObject Computer Groups DateTime Desktop DNS Excel FileScriptingObject Forms General GPO GPS Group Policy Hacks ISE Lockout logons NAV740 Nessus OU OU permissions Outlook Pick Folder Power PowerShell Powershell Scriptlets RDP SCCM schedule reboot Scripting Security Shell.Application user information VBA Windows Update WMI WordPress WPF

Categories

akaplan.com

  • Back to Home Page

Archives

Scripting Sites

  • A Big Pile of Small Things
  • Adam, the Automator
  • Art of the DBA
  • Ashley McGlone
  • Boe Prox
  • Carlo Mancini
  • DexterPOSH
  • Doug Finke
  • Jaap Brasser's Blog
  • JeffOps The Scripting Dutchman
  • Jonathan Medd's Blog
  • Keith Hill's Blog
  • LazyWinAdmin
  • Nana Lakshmanan
  • PowerShell Magazine
  • PowerShell Team Blog
  • PowerShell.org
  • PwrShell.net
  • Richard Siddaway's Blog
  • Ryan Yates' Blog
  • Skatterbrainz
  • The Lonely Administrator

SQL Site

  • Art of the DBA

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2025 Alan's Blog | Theme by SuperbThemes

Terms and Conditions - Privacy Policy