by August 9, 2003 0 comments



With MST (Microsoft Scripting Technologies), administrators can automate many routine tasks in Windows–such as, clearing log files, changing user passwords and system inventory–by simply executing small scripts rather than going through the usual manual processes. You can also
use Windows scripting as user login scripts. 

MST includes Visual Basic Scripting, Windows Script Host, Active Directory Service Interface and Windows Management Instrumentation. To automate a particular administrative task, you have to write and execute a small script. 

And, the good news is that to write Windows scripts, you require little programming knowledge. In fact, you can download pre-written scripts from Microsoft’s website
(www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/winxppro/proddocs/sag_CMprocsStartCM.asp) and modify them to suit your requirements. You’ll also find some of these scripts on this month’s 
PCQEssential CD. 

Now, let’s look at one common task that you can use MST for–mapping a network share to a drive on your Windows machine. 

STEP ONE

Write script 

Type the following in Notepad.

Set objNetwork = CreateObject(“WScript.Network”) ‘ Initialization (creates net work object)
objNetwork.MapNetworkDrive “K:”, \\system2\users 
‘ call function to map the share as K:
Wscript.Echo “The Drive K: is mapped to \\system2\users.”
‘ Displays the given mes sage

STEP TWO

Execute script
After writing the script, save the file with a .vbs extension. You will need to set the File Type filter to All Files. Now execute this script, by double-clicking on it. After execution the script, you will find the newly mapped drive (K) in My Computer.
Given below is a more complex script. Running it will display all the running process on your machine on a Web page.

set objIdDictionary = CreateObject(“Scripting.Dictionary”)
strComputer = “.”
Set objWMI = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\cimv2”)
Set colServices = objWMI.ExecQuery _
(“Select * from Win32_PROCESS”)
Set colAdapters = objWMI.ExecQuery 
(“Select * from Win32_NetworkAdapterConfiguration “ _
& “Where IPEnabled = True”)
Set objFS = CreateObject(“Scripting.FileSystemObject”)
Set objNewFile = objFS.CreateTextFile(“report.htm”)
objNewFile.WriteLine “<html><head>”
objNewFile.WriteLine “<title>Process Report</title>”
objNewFile.WriteLine “</head><body>”
objNewFile.WriteLine “<h1>Process Report – Date: “ & Now() & _
“</h1>” & vbCrLf
For Each objAdapter in colAdapters

objNewFile.WriteLine _
“<h3>Machine Name: “ & objAdapter.DNSHostName & “</h3>”
Next

objNewFile.WriteLine “<table BORDER=1>”
For Each objprocess in colServices

objNewFile.WriteLine “<tr>”
objNewFile.WriteLine “<td>Process Name:</td>”
objNewFile.WriteLine “<td>” & objProcess.Name & “</td>”
objNewFile.WriteLine “<td>Executable Path:</td>”
objNewFile.WriteLine “<td>” objProcess.ExecutablePath & “</td>”
objNewFile.WriteLine “</tr>”
Next
objNewFile.WriteLine “</table></body></html>”
objNewFile.Close

This script will create a Web page with the name of Report.htm, which contains all the processes running on your system, with their executable path.

Sanjay Majumder

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

Your data will be safe!Your e-mail address will not be published. Also other data will not be shared with third person.