VBScript Tim Sirgo www personal kent edutsirgonmproject ppt
VBScript Tim Sirgo www. personal. kent. edu/~tsirgo/nmproject. ppt
Comparison n VB. Net n n GUI Visual Studio n VBScript n n Plain Text Use text editor (e. g. Notepad)
WMI n Windows Management Instrumentation (WMI) is a scalable system management infrastructure that uses a single, consistent, standards-based, extensible, objectoriented interface.
WMI n Provides a way to interact with system management information
WMI 1. Connect to WMI object n 2. Run a query against it n n Query is structured similar to SQL n “Select * from …”
SWBEM n Instead of WMI “moniker string” n n "{impersonation. Level=impersonate}!\" Use domain credentials n objswbemlocator. connectserver(strcomputer, "rootcimv 2", "nm. xyz" & strusername, strpassword)
Code In following slides n www. personal. kent. edu/~tsirgo n
Credentials do until strusername <> "" strusername = inputbox("Enter user name", "username") if isempty(strusername) then wscript. quit end if loop do until strpassword <> "" strpassword = inputbox("Enter password WARNING: THE PASSWORD WILL NOT BE HIDDEN", "password") if isempty(strpassword) then wscript. quit end if loop
Output Files set 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, Auto. Sense, Description, Device. ID, Index, MAC, Manufacturer, Speed, MAX Speed, Connection Status") IPoutfile. writeline("Computer Name, IPAddress")
SWbem set objswbemlocator = createobject("wbemscripting. swbemlocator") set objswbemservices = objswbemlocator. connectserver(strcomputer, "rootcimv 2", "nm. xyz" & strusername, strpassword) set colswbemobjectset = objswbemservices. execquery("Select * from Win 32_Network. Adapter. Configuration Where IPEnabled = TRUE")
IP Address for each ipconfig in colswbemobjectset if not isnull(ipconfig. ipaddress) then for i=lbound(ipconfig. ipaddress) to ubound(ipconfig. ipaddress) IPoutfile. writeline(strcomputer & ", " & ipconfig. ipaddress(i)) next end if next
NIC set colswbemobjectset = objswbemservices. execquery("Select * from Win 32_Network. Adapter") for each objitem in colswbemobjectset select case objitem. adaptertypeid case 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 = "Local. Talk" 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. device. ID & ", " & objitem. index & ", " & objitem. macaddress & ", " & objitem. manufacturer & ", " & objitem. speed & ", " & objitem. maxspeed & ", " & objitem. netconnectionstatus) next loop
Errors
Resource Sites Microsoft Tech. Net Script Center n W 3 schools n Dev. Guru n
- Slides: 26