Advertisment

Automate Windows Admin Tasks 

author-image
PCQ Bureau
New Update

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. 

Advertisment

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. 

Advertisment

STEP ONE

Write script 

Type the following in Notepad.

Advertisment

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.

Advertisment

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 “


objNewFile.WriteLine “Process Report


objNewFile.WriteLine “





objNewFile.WriteLine “

Process Report – Date: “ & Now() & _















” & vbCrLf



For Each objAdapter in colAdapters





objNewFile.WriteLine _



Machine Name: “ & objAdapter.DNSHostName & “









Next





objNewFile.WriteLine “





For Each objprocess in colServices





objNewFile.WriteLine “




objNewFile.WriteLine “


Process Name:



Advertisment





objNewFile.WriteLine “ ” & objProcess.Name & “





objNewFile.WriteLine “ Executable Path:





objNewFile.WriteLine “ ” objProcess.ExecutablePath & “

Advertisment





objNewFile.WriteLine “





Next


objNewFile.WriteLine “





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

Advertisment