Add And Remove Services Entries

This is a quick script I’ve used to add and remove entries to the windows services file. It ignores commented lines (lines starting with a hash (#)), and it also doesn’t validate the format of the host or port/protocol so use with care!

Usage

cscript.exe services.vbs “Add” “localhost” “8080/http”
cscript.exe services.vbs “Remove” “localhost” “8080/http”

and here’s an example of how it can be called from another vbscript:

 

Add and Remove Hosts Entries

This is a quick script I’ve used to add and remove entries to the windows hosts file. It ignores commented lines (lines starting with a hash (#)), and it also doesn’t validate the format of the host or IP address so use with care!

Usage

cscript.exe hosts.vbs “Add” “10.10.10.10” “example”
cscript.exe hosts.vbs “Remove” “10.10.10.10”

 

Search for a File Inside a Merge Module

Description

Sometimes I need to find if a file exists inside a merge module.  Since I don’t know which specific merge module I’m looking for, I wrote this script to iterate through every merge module in a specific folder to find a specific file in the File table.

Usage

CScript.exe {Script} {FileToSearchFor}

 

Clean Up the Windows Start Menu

Sometimes after an install or an uninstall we want to clean up the start menu – usually this involves removing shortcuts to uninstall the application, shortcuts that link to help files and/or shortcuts that attempt to install additional components.  This tidy script (tested on Windows 7) can be used to populate file(s) and folder(s) names that require deleting.

 

Create Lnk Shortcut using VBScript

 

Wait for a Process to Complete

Description:

Useful when we want to wait for a process to complete until we continue execution of a script.

Source:

NA

Script:

This script waits until notepad.exe and iexplore.exe are no longer running:

 

Cascading Dropdown List using VBScript, XPATH and an XML back-end

I’ve been working on more toolsets recently, and we needed a way to populate multiple dropdown lists in a HTA file, and make them cascade. Cascading is basically where the results in the second dropdown list are dictated by the selection in the first dropdown list. For example:

Let’s say our first dropdown list contained car manufacturers, and the second dropdown list contained models. If I selected ‘Ford’ from the manufacturers dropdown list, I would want the model dropdown list to show me a list of all cars made by Ford (Fiesta, Mondeo, Escort etc etc) and so on.

Anyway, in our example we’ll use a good ol’ list of football clubs.  In dropdown list 1, we want a list of football clubs.  And in dropdown list 2, we want to see a list of players.  We also want to keep track of the stadium that each clubs plays in.  Here’s our sample XML chunk – we’ll call it ‘footballclubs.xml’:

You can see that the football clubs are: Manchester Utd, Chelsea and Arsenal. You should also be able to see the players for each club, and the stadium they play in.

Now we’ll write a HTA file, and save it in the same location as ”footballclubs.xml’:

 

Using VBScript, CAML queries and SOAP to Read from a Sharepoint List

We use a Sharepoint list to track various information. The toolsets that we create should ideally read from these lists, so that every team member shares the same information and can see real-time data. To do this, we used VBScript (we made a HTA actually…).

It uses a SOAP request to ‘ask’ for information from Sharepoint. Part of this request uses a CAML query to specify exactly what we’re after.

**UPDATE**

The example above pulls back ALL fields from the list.  We may want to refine this to only pull back specific fields by adding the following to our SOAP request:

The first viewFields tag above should be at the same level as the <query> tag in the example above.  In other words, you can paste this code directly above the <query> line in the SOAP request.