Scripts and Code

Identifying .Net Versions (VBScript)

As various versions of Windows include different versions of the .Net Framework and users can install additional versions through many channels it can be hard to determine exactly which versions of which frameworks are installed. This simple VBscript reports on the currently installed versions and service packs. Simply download the file and run or copy the code below to a .vbs file and save and then double click to run.

Attachments:
Download this file (checknetversion.zip)checknetversion.zip0.6 kB2016-02-01

Read more: Identifying .Net Versions (VBScript)

Importing Photos to PowerPoint (VBA/PowerPoint)

Creating a PowerPoint presentation from a large amount of photos can be very time consuming. Office 2007 and later include a Photo Album feature to assist with importing photos in bulk but this still requires some manual selection of images and can be awkward to use. 

The attached macro enabled powerpoint presentation is a demonstration of how VBA can be used to automate this process. This sample includes functions to import all JPG,PNG and GIF images in the folder of the presentation and additional functions and forms to display a progress bar indicating progress for large volumes of images.

The code included in this presentation can be run as a macro or run as part of the presentation. Details are included on the slideshow. This presentation will work in Office 2007 and later.

Attachments:
Download this file (PhotoImporter.pptm)PhotoImporter.pptm74 kB2015-04-27

Importing Calendar Items to Outlook (VBA/Excel)

Microsoft Outlook includes an import/export feature that can be used to create calendar items from a spreadsheet. This method however only works on your primary mailbox.

If you have direct access to your shared mailboxes or exchange server there are other solutions but as a user this makes it difficult to automatically create calendar items in a shared mailbox. Looking for a solution I discovered an easy way to create a VBA macro that could be used to select and create calendar items in any of my mailboxes. Simply populate this spreadsheet and run the import and you can watch as calendar items are created and meeting requests automatically sent.

Attachments:
Download this file (OutlookImport.xlsm)OutlookImport.xlsm20 kB2015-04-09

Read more: Importing Calendar Items to Outlook (VBA/Excel)

Yo API (Asp)

Yo is a simple application for iOS, Windows Phone and Android that allows you to send a single message, "Yo", to specified users.

Yo has an API designed to allow you to send a notification to users when required.

SendYo is a notification program I have written for Yo to allow it to be used as a Windows notification system.

You can take advantage of the Yo API and related web functionality to use Yo as a notification system. The following ASP pages I have written extend the functionality of Yo and SendYo to provide additional features.

Attachments:
Download this file (yo-asp.zip)yo-asp.zip1 kB2015-01-11

Read more: Yo API (Asp)

Finding Long Running Queries (SQL)

A common challenge for database administrators is identifying queries from an application or user that are impacting the performance of a SQL server. These are usually long running queries that can either slow down performance of the SQL server or cause the TEMPDB (the temporary database used by SQL for processing) to grow in size dramatically. Either of these is likely to have an impact on the user experience. These scripts will help you identify these queries.

These scripts have been tested on SQL 2008 R2 and SQL 2012.

Read more: Finding Long Running Queries (SQL)

Issue Recorder (VBScript)

One of the biggest challenges for IT Support engineer's is understanding the issues that end users are experiencing. Without being able to see their actions getting them to provide the steps they take to perform a function prior to an error occurring is a constant challenge. Fortunately Microsoft have added a fantastic tool called the Problem Steps Recorder to Windows 7 and 8 that solves this challenging by capturing every step that a user takes when replicating an issue. 

While this tool is fantastic it is not accessible in the start menu and does not provide a useful wizard to step end users through the process they need to follow to capture then forward their issue steps to your help desk. This script resolves this issue by providing a wizard to capture the steps of a problem and email them to the relevant people in a few simple steps and without any extra programs or plugins required.

Attachments:
Download this file (issuerecorder.cmd)issuerecorder.cmd2 kB2014-01-27

Read more: Issue Recorder (VBScript)

Make Windows Talk (VBScript)

VBScript allows you to perform many powerful windows functions. There are also many hidden features you are not aware of. If you have ever enabled the accessibility options you may have found an option for Windows to read pages out to you or tell you what you are clicking on. This feature can also be accessed via vbscript to make great scripts that talk to users.

The following is a simple example. Copy these three lines and paste them into a text file called "Speak.vbs". Run this file to hear your computer talk to you. 

strText = "Hi, this is your computer speaking"
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak strText

There are also many great nefarious uses for this script including making a windows login script that speaks to users when they boot their computer or placing a hidden task on a friend's computer to pipe up at regular intervals and say hi. Enjoy.

Printers and Jobs Report (VBScript)

Monitoring printers and print jobs in Windows isn't always easy especially if your printer queues are scattered across multiple servers. If you want near real time monitoring of errors or problems with your printers or print jobs then my application, Print Stalker, can be installed on each server to notify you directly when these issues occur. There are many instances however where you may be required to report on the status of all printers on the network or identify any print jobs that may be causing concern on individual printers. This script produces a detailed color coded report with that information.

This script includes the following features:

  • Command line progress notifications to identify when/if problems occur
  • Tables of printer status and details and print jobs status and details for all servers specified
  • Color coding of printer and job status for easy identification
  • Configurable output location
  • HTML report generation with options to save to file or open in browser automatically
  • CDO email report sending option with ability to include inline header logo image (if file exists)
  • Configurable Options section marked in script to assist beginners in making modifications
  • WMI queries on Win32_Printer and Win32_Printers
Attachments:
Download this file (printers.zip)printers.zip17 kB2013-11-10

Read more: Printers and Jobs Report (VBScript)

Send email using CDO (VBScript)

If you have servers to monitor and require automated email notifications then you need a VBScript that can be scheduled and run automatically. This script allows you to take any HTML file and send it as the content of an email and include another file as an attachment. I have used this in conjunction with scripts that generate server storage space using WMI so I can monitor disk usage. This email can constitute a daily or weekly report simplifying your management and monitoring. This script uses CDO to send mail and can be configured with or without authentication.

To trigger this script from a scheduled task it is recommended to use a command./batch file which is included with 32 bit and 64 bit example. Simply comment out the unrequired section depending on your environment. This script is designed to be run from your C drive but can be easily modified. Remember to configure your email settings before use. I have highlighted the sections you need to modify.

 

Attachments:
Download this file (sendemail.zip)sendemail.zip2 kB2013-04-30

Read more: Send email using CDO (VBScript)

Retrieve DNS Records (VBScript)

As a network administrator you are often working with machines across different domains or subnets in the business and it can be hard to see and access these computers by name. Instead of remembering a long list of fully qualified domain names this script finds your primary DNS server and enumerates all of the PTR records and exports them to an easy to read spreadsheet. For DNS servers with multiple domains this will retrieve all records. If possible it also retrieves the time this information was updated so you can identify computers that have not 'checked in' to the network recently or stale DNS records. This script may require you to have permission to read WMI from the DNS server so is best run by a network administrator on a server however the script can be easily modified so the spreadsheet is generated in a location shared to users.

 

Attachments:
Download this file (extract-dns.zip)extract-dns.zip0.9 kB2013-01-20

Read more: Retrieve DNS Records (VBScript)

Network Deployment Tool (VBScript)

The Network Deployment Tool demonstrates how to use PSEXEC, NETSCAN and VBScript to deploy any application, command or script to all computers in the current domain and subnet. This application is ready to use as is and will prompt for users to configure the appropriate target files for deployment.

When you run the application a HTML Deployment Summary window appears to provide you with details on the progress of your deployment and asks for your confirmation.
On each targeted machine your application files are deployed and then executed as you have configured in a batch file included with the deployed files.

This script is designed to be run on a machine in the same subnet as target computers and with administrative rights and has been tested on Windows 7, Windows 8 and Server 2008 although it should also work on XP SP2 and 2003 SP2 or later machines. A sample deployment which simply pops up a message on each computer is included but I have also included additional code for configuring an email to confirm a test deployment without user intervention.

You can print or email the HTML summary window when complete (some code changes required to email to custom address) and it is also saved to file automatically.

Attachments:
Download this file (networkdeploy.exe)networkdeploy.exe952 kB2012-08-21

Read more: Network Deployment Tool (VBScript)

Godmode (VBScript)

This script creates all of the GodMode shortcuts available in Windows 7 and 8.

Attachments:
Download this file (godmode.zip)godmode.zip2 kB2012-04-30

Read more: Godmode (VBScript)

DNSChanger Malware Infection Test Script (VBScript)

This script checks the DNS settings of your computer to identify whether you are potentially infected with DNSChanger. DNSChanger is a serious malware infection that can change your DNS servers. A temporary global fix has been put in place until July 9 2012. At this time this fix will no longer work and infected machines may not be able to access the internet. For more information from the DNS Changer Working Group see http://dcwg.org/index.html

Read more: DNSChanger Malware Infection Test Script (VBScript)

Detect and Eject CD Drives (VBScript)

This script detects, identifies then ejects CD ROM drives on a Windows machine.

Read more: Detect and Eject CD Drives (VBScript)

Update Windows Owner and Organization (VBScript)

This script updates the Windows Owner and Organisation information on Windows Vista or later.

After completion it will show the Windows registration information.

Read more: Update Windows Owner and Organization (VBScript)

Scan and Defrag (VBScript)

This script performs a chkdisk scan and a defrag of the current machine.

Read more: Scan and Defrag (VBScript)

Enumerate Printers (VBScript)

This script displays information about each installed printer.

Read more: Enumerate Printers (VBScript)

List IP Addresses (VBScript)

This script displays a list of all IP addresses assigned to the current machine.

Read more: List IP Addresses (VBScript)

Retrieve Drive Information (VBScript)

This script uses WMI to retrieve information about the current disk drive.

Read more: Retrieve Drive Information (VBScript)

Last Reboot (VBScript)

This script retrieves the last reboot time from the operating system and converts it into Hours, Minutes and Seconds.

Simply copy and paste the code into notepad and save as uptime.vbs. Double click the file to run.

Read more: Last Reboot (VBScript)

Windows Version Number (VBScript)

Need your Windows Version Number?

The following script returns a dialog box indicating the version number of the operating system.

Read more: Windows Version Number (VBScript)

Mailbox Sizes Exchange 2003 (VBScript)

This script produces a summary of mailbox sizes on an Exchange 2003 server.

This includes; Server Name,Storage Group,User Display Name,Mailbox Size,Total Items,Deleted Items Size.

Read more: Mailbox Sizes Exchange 2003 (VBScript)

Monitoring printers and services (VBScript)

The following script logs printer and service activity on a server.

This script is designed to identify the cause of printer issues by recording changes in the spool service or print job classes.

Read more: Monitoring printers and services (VBScript)

Adding or Removing Printers (VBScript)

Adding or Removing printers using VBScript.

The following script can be triggered by adding the path to the vbs file to the network logon script.
Printers can be added or removed when this script is run.

Read more: Adding or Removing Printers (VBScript)

Move your iTunes Library Completely (VBScript)

There are many reasons you may wish to move your iTunes library. It may be taking up more space than you have on your C drive, you may wish to move it to another computer, or in an office environment you might accidentally be storing your music on the servers. This script is very simple to configure and steps the user through the process.

The full code is shown below. VBScript works on all versions of Windows.

Read more: Move your iTunes Library Completely (VBScript)