Archive for the ‘VBScript’ Category

How to List Installed Softwares on a machine using VBScript?

December 26, 2008

Here is a handy code to list down all the installed softwares on a machine with their installation information:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("D:\Test\softwares.tsv", True)

strComputer = "."
Set objWMIService = GetObject("winmgmts:"_
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product")

objTextFile.WriteLine "Caption" & vbtab & _
"Description" & vbtab & "Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Install State" & vbtab & "Name" & vbtab & _
"Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
& "Version"

For Each ObjSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & _
objSoftware.Description & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate2 & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.InstallState & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.SKUNumber & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version
Next

objTextFile.Close

Hope this helps 🙂

Advertisements

How to Create a Process on Remote Computer using VBScript WMI?

December 25, 2008

Here is a sample code to start the notepad.exe on a remote computer. This code works well with all the Windows operating system except for the advance OS like Windows XP the notepad opens in an invisible mode. In the code below you need to replace “server” with the name of the computer where you want to start the process.

strComputer = "server"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
Error = objWMIService.Create("notepad.exe", null, null, intProcessID)
If Error = 0 Then
Wscript.Echo "Notepad was started with a process ID of " & intProcessID & "."
Else
Wscript.Echo "Notepad could not be started due to error" & Error & "."
End If

Hope this helps!

How to assign a static IP address using VBScript?

December 25, 2008

This type of scripts are always in demand by the network proffessionals. Here is a handy script that assigns a static IP address to a machine:

strComputer = "."
Set objWMIService = GetObject ("winmgmts:" & "{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.202")
strSubnetMask= Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errorEnable = objNetAdapter.EnableStatic(strIPAddress,strSubnetMask)
errorGateway= objNetAdapter.SetGateways(strGateway, strGatewayMetric)
If errorEnable = 0 Then
WScript.Echo "The IP Address has been changed successfully!!"
Else
WScript.Echo "Their was an error, the IP Address could not be changed!"
End If
Next

Hope this helps 🙂

How to Start, Stop and Pause a Web Server on IIS using VBScript?

December 25, 2008

Here is a VBScript code to start, stop and pause a web server running in IIS:

Start a Web Server

strComp = "LocalHost"
Set objIIS = GetObject("IIS://" & strComp & "/W3SVC/2142295254")
objIIS.Start

Stop a Web Server

strComp = "LocalHost"
Set objIIS = GetObject("IIS://" & strComp & "/W3SVC/2142295254")
objIIS.Stop


Pause a Web Server

strComp = "LocalHost"
Set objIIS = GetObject("IIS://" & strComp & "/W3SVC/2142295254")
objIIS.Pause

Hope this helps 🙂