Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


November 2009

Time to Round Up Those Scripts

Don't leave your scripts scattered about
RSS
Subscribe to Windows IT Pro | See More VBScript Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

Listing 1: ScriptRoundUp.vbs

Const adPersistXML  = 1
Const adFldIsNullable = 32
Const adLongVarChar = 201

ColPath = "C:\Scripts\AllScripts\"
DestRoot = ColPath & "ScriptFiles"

strQuery = "Select Drive,Extension,Name,Path from CIM_DataFile " & _
  "Where (Drive='c:' OR Drive='d:') AND (extension='vbs' OR extension='hta')"

Set fso = CreateObject("Scripting.FileSystemObject")

If Not fso.FolderExists(ColPath) Or Not fso.folderExists(DestRoot) Then
  Msgbox "Collection Folder " & ColPath & " or " & DestRoot & " does not exist... Terminating Script"
  WScript.Quit
End If

strMessage = "A message box will appear when process is complete."
strMsgTitle = "Script Round-up"
CreateObject("WScript.Shell").Popup strMessage,10,strMsgTitle,vbInformation

' Begin Callout A
Set objShell = CreateObject("Shell.Application")
Set RootFolder = objShell.NameSpace(DestRoot)
' End Callout A

' Begin Callout B
Set DRS = CreateObject("ADODB.Recordset")
DRS.Fields.Append "Drive",adLongVarChar,256,adFldIsNullable
DRS.Fields.Append "Extension",adLongVarChar,256,adFldIsNullable
DRS.Fields.Append "Name",adLongVarChar,256,adFldIsNullable
DRS.Fields.Append "Path",adLongVarChar,256,adFldIsNullable
DRS.Open
' End Callout B

' Begin Callout C
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colFiles = objWMIService.ExecQuery(strQuery)

For Each objFile In colFiles
  DRS.AddNew
  DRS("Drive") = objFile.Drive
  DRS("Extension") = objFile.Extension
  DRS("Name") = objFile.Name
  DRS("Path") = objFile.Path
Next

DRS.MoveFirst
' End Callout C

' Begin Callout D
Do While Not DRS.EOF
  FolderPath = Replace(DRS.Fields.Item("Drive"),":","") & DRS.Fields.Item("Path")
  Dest = DestRoot & "\" & Replace(DRS.Fields.Item("Drive"),":","") & DRS.Fields.Item("Path")
  If Not fso.FolderExists(Dest) Then
    RootFolder.NewFolder(FolderPath)
  End If
  Set sourcefile = nothing
  Set sourcefile = fso.getFile(DRS.Fields.Item("Name"))
  sourcefile.Copy Dest
  DRS.MoveNext
Loop
' End Callout D

If fso.FileExists(ColPath & "Scripts.xml") Then
  fso.DeleteFile(ColPath & "Scripts.xml")
End If

DRS.Save ColPath & "Scripts.xml",adPersistXML
DRS.Close
MsgBox "Done"

End of Article

   Previous  1  2  [3]  Next  


Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Related Articles Divide and Conquer Mega-Sized Text and Log Files

Accessing Database Data with ADO

Introduction to ADO

Make Sure Your Scripts Have Some Protection

Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

Take Control of Storage & eDiscovery Costs with Unified Content Archiving

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement