Remove All Mapped Drives in VBScript

On Error Resume Next

Set objNetwork = CreateObject("Wscript.Network")

Set colDrives = objNetwork.EnumNetworkDrives

For i = 0 to colDrives.Count-1 Step 2
    objNetwork.RemoveNetworkDrive colDrives.Item(i)
Next

Little syntax help:

objNetwork.RemoveNetworkDrive(strName, [bForce], [bUpdateProfile])

Key:

objNetwork : A WScript.Network object

strName : The mapped drive you want to remove.

bForce : Force the removal of the mapped drive (TRUE/FALSE).

bUpdateProfile : Remove the mapping from the user’s profile (TRUE/FALSE).

Getting Dell Service Tag (Serial Number) using WMI

For Each strComputer In wscript.Arguments
 Set objWMIService = GetObject(“winmgmts:” _ & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
 Set colSMBIOS = objWMIService.ExecQuery _ (“Select * from Win32_SystemEnclosure”)
 For Each objSMBIOS in colSMBIOS
  Wscript.Echo strComputer & “: ” & objSMBIOS.SerialNumber
 Next
Next

Script: put user picture to Active Directory

Little script in vbScript:

Function PictureToAD(szADSOBJ, szFileName)
 Dim objUser, bytesRead, adoStreamRead
 Const adTypeBinary = 1
 Set adoStreamRead = CreateObject("ADODB.Stream")
 adoStreamRead.Type = adTypeBinary
 adoStreamRead.Open
 adoStreamRead.LoadFromFile szFileName
 bytesRead = adoStreamRead.Read()
 adoStreamRead.Close
 Set objUser = GetObject(szADSOBJ)
 objUser.Put "thumbnailPhoto", bytesRead
 objUser.SetInfo
End Function

Execute process remotely with WMI (VBScript)

How can I start a process and then wait until that process quits before terminating the script?

It offers the capability to execute process with the limitation of not allowing any user interaction – the process will run in the background without showing any interface on user’s session, which is a perfect feature for running non-interactive processes.

WMI, below is the code snippet in VBScript:

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
intReturn = objWMIService.Create("command", Null, Null, intProcessID)

Reference: http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec06/hey1208.mspx