Listing 1: DellSerial.js var SCRIPT_NAME = "DellSerial.js"; WScript.Quit(main()); function usage() { WScript.Echo("Retrieves a machine's Dell service tag and Express Service Code (ESC).\n" + "\n" + "Usage: " + SCRIPT_NAME + " | /tag:\n" + "\n" + "If you specify a computer name, the program will retrieve the computer's\n" + "service tag over the network. You can also specify an arbitrary service tag,\n" + "and the program will convert it to the equivalent Express Service Code value."); WScript.Quit(0); } function hex(n) { if (n < 0) return (n + 0x100000000).toString(0x10).toUpperCase(); else return n.toString(0x10).toUpperCase(); } function main() { var args, computer, servicetag, output, wmi, enclosures, expresscode, n; args = WScript.Arguments; // If an unnamed argument exists, use it as the computer name; // otherwise, parse the /tag parameter. if (args.Unnamed.length > 0) computer = args.Unnamed.Item(0); else { if (args.Named.Exists("tag")) { servicetag = args.Named.Item("tag"); if ((servicetag == undefined) || servicetag == "") usage(); } } // Display the usage statement if /? exists, or if neither a // computer name or service tag has been specified. if ((args.Named.Exists("?")) || ((computer == undefined) && (servicetag == undefined))) usage(); output = ""; // ******* BEGIN CALLOUT A ******* // If a computer name has been specified, use WMI to connect // to the computer and retrieve the first instance of the computer's // Win32_SystemEnclosure object. This object's SerialNumber property // is the computer's service tag. if (computer != undefined) { try { wmi = GetObject("winmgmts:{impersonationlevel=impersonate}!" + "//" + computer + "/root/cimv2"); } catch(err) { WScript.Echo("Error 0x" + hex(err.number) + " connecting to " + computer); return err.number; } // ******* END CALLOUT A ******* enclosures = new Enumerator(wmi.InstancesOf("Win32_SystemEnclosure")); servicetag = enclosures.item().SerialNumber; output += "Computer name: " + computer + "\n"; } // ******* BEGIN CALLOUT B ******* // Create an array containing the digits in the service tag. Note // the argument to the parseInt function to specify base 36. expresscode = parseInt(servicetag, 36).toString().split(""); // ******* END CALLOUT B ******* // ******* BEGIN CALLOUT C ******* // Insert a hyphen (-) after every third digit, starting at the fourth // position (index 3). We have to increment in "fours" to account // for the insertions. for (n = 3; n < expresscode.length; n += 4) expresscode.splice(n, 0, "-"); output += "Service tag: " + servicetag + "\n" + "Express service code: " + expresscode.join(""); // ******* END CALLOUT C ******* WScript.Echo(output); return 0; }