26
VBScript Tim Sirgo www.personal.kent.edu/~tsirgo/ nmproject.ppt

VBScript Tim Sirgo tsirgo/nmproject.ppt

  • View
    219

  • Download
    2

Embed Size (px)

Citation preview

VBScriptTim Sirgo

www.personal.kent.edu/~tsirgo/nmproject.ppt

Comparison VB.Net

GUI Visual Studio

VBScript Plain Text Use text editor (e.g.

Notepad)

WMI Windows Management Instrumentation

(WMI) is a scalable system management infrastructure that uses a single, consistent, standards-based, extensible, object-oriented interface.

WMI Provides a way to interact with system

management information

WMI 1. Connect to WMI object 2. Run a query against it

Query is structured similar to SQL “Select * from …”

SWBEM Instead of WMI “moniker string”

"{impersonationLevel=impersonate}!\\"

Use domain credentials objswbemlocator.connectserver(strcomputer,

"root\cimv2", "nm.xyz\" & strusername, strpassword)

Code In following slides www.personal.kent.edu/~tsirgo

Credentialsdo until strusername <> ""

strusername = inputbox("Enter user name", "username")if isempty(strusername) then

wscript.quitend if

loopdo until strpassword <> ""

strpassword = inputbox("Enter password - WARNING: THE PASSWORD WILL NOT BE HIDDEN", "password")if isempty(strpassword) then

wscript.quitend if

loop

Output Filesset objfso = createobject("scripting.filesystemobject")

set IPoutfile = objfso.createtextfile("IPAddresses.txt", True)

set NICoutfile = objfso.createtextfile("NIC.txt", True)

NICoutfile.writeline("Computer Name, Adapter Type ID, AutoSense, Description, DeviceID, Index, MAC, Manufacturer, Speed, MAX Speed, Connection Status")

IPoutfile.writeline("Computer Name, IPAddress")

SWbem

set objswbemlocator = createobject("wbemscripting.swbemlocator")

set objswbemservices = objswbemlocator.connectserver(strcomputer, "root\cimv2", "nm.xyz\" & strusername, strpassword)

set colswbemobjectset = objswbemservices.execquery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE")

IP Address

for each ipconfig in colswbemobjectsetif not isnull(ipconfig.ipaddress) then

for i=lbound(ipconfig.ipaddress) to ubound(ipconfig.ipaddress)

IPoutfile.writeline(strcomputer & ", " & ipconfig.ipaddress(i))

nextend ifnext

NIC

set colswbemobjectset = objswbemservices.execquery("Select * from Win32_NetworkAdapter")for each objitem in colswbemobjectset

select case objitem.adaptertypeidcase 0 stradaptertype = "Ethernet 802.3"case 1 stradaptertype = "Token Ring 802.5"case 2 stradaptertype = "FDDI - Fiber"case 3 stradaptertype = "Wide Area Network"case 4 stradaptertype = "LocalTalk"case 5 stradaptertype = "Ethernet using DIX header"case 6 stradaptertype = "ARCNet"case 7 stradaptertype = "ARCNET 878.2“case 8 stradaptertype = "ATM"

end select

NIC (cont.)

(for each objitem in colswbemobjectset)

NICoutfile.writeline(strcomputer & ", " & stradaptertype & ", " & objitem.autosense & ", " & objitem.description & ", "

& objitem.deviceID & ", " & objitem.index & ", " & objitem.macaddress & ", " & objitem.manufacturer & ", " & objitem.speed & ", " & objitem.maxspeed & ", " & objitem.netconnectionstatus)

nextloop

Errors

Resource Sites Microsoft TechNet Script Center W3schools DevGuru