mystuff

Your IP Address is: 38.107.191.102
Last site update: 23 March 2009
You are visitor number: 

  home | wsname | wallpaper creator | delphi stuff | vb script stuff | other stuff | contact me

Google
Web Site
Here's a collection of Visual Basic (vb) Script functions I've collected over the years.

Services
   Check if a particular service is running

File System
   Delete a file
   Find a file if it's in the path
   Find the CDROM Drive
   Find CDROM Drive with Media
   Generate a filename and path for a working file in the %temp% directory
   Find the size of a file
   Find the location of PST files and log them in a SQL database

Network
   Renew a DHCP lease
   Ping a host (using WMI)
   Ping a host using the external ping.exe
   Convert an IP Address Mask to Slashed Notation
   Set a static IP address from a text file

Registry
   Search through the registry using recursion

Misc
   Including common functions and statement in your scripts
   Open the Control Panel Dialogue to the "Connections" option
   Convert a Binary File to a String
   Check if you're running on a Desktop or Laptop

Working With Data Files (INI, XML, SQL) files
   Using SQL to Generate a Self Incrementing Computer Naming System
   Read a Value from an INI File (GetINI)
   Write to an INI file (WriteINI)
   Read a whole section of an INI file
   Write a whole section to an INI file
   Read a value from an XML file

LDAP, AD, Exchange etc
   Get User Information from an Exchange 5.5 GAL
   Check to see if a User Account Exists in AD
   Get Members of an AD Group
   Update the Terminal Services Profile Path to point to a new Server
   Set Exchange 'Send As' and 'Receive As' Permissions


 Using SQL to Generate a Self Incrementing Computer Naming System


Lets say you want to call your workstations WKS-1, WKS-2, WKS-3 and so on, but you're too busy or too lazy to set up a data file manually. You could create a simple text file using script and have the workstations add themselves, but the problem with using text files is that if two or more computers try to update it at the same time you will loose data. This example uses SQL to create a table of machine names based on MAC addresses and shells out to WSName if the name in SQL is not the same as the current name.

Create a database and table in SQL
First off create your database and table, the table is very simple we only need two columns, call the first one "ID" and make its data type "int". Set this as a primary key and Identity Increment and Identity Seed values to "1". This will make is value increment itself every time we add a value to the next column. Call the second column "MAC" and make its data type VarChar(50). Assign a user with rights to read and write to the table and then we are all done.

Grab the script from here and update the Consts with the relevant settings for your environment.

How it works
It's all pretty basic, first of all the script gets your MAC address and the current name of your computer. Then it passes the MAC address to SQL, if it gets nothing back it adds the MAC address to the table and tries again. As we set the ID to auto increment each MAC address is assigned a unique ID number. So now the script has a unique ID number for your computer, it appends this to your default workstation prefix (in the example WKS-) and checks the result against your current computer name. If the names match the script completes, if they are different it calls WSName to rename your machine with the new name.