Option Explicit wscript.echo "Machine information lookup 080307HK + NewSID launcher" & chr(10) ' ----------- ' Declairations ' ----------- CONST iNormalFocus = 1 CONST vbExclaimation = 48 CONST ForWriting = 2 DIM objShell: Set objShell = WScript.CreateObject("Wscript.Shell") DIM objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject") DIM inputname,inputdescript,promptTitle,promptMessage,RunWhat,result,resultTitle,resultMessage DIM mdbfile,strComputer,txtOutFile,compDescTxt, ResourcePath, SIDit ' Command Line Arguments array DIM Args: Set Args = WScript.Arguments DIM TotArgs: TotArgs = Args.Count ' ------------- ' Init ' ------------- 'If TotArgs > 0 Then SIDit = Args(0) Else SIDit = 0 SIDit = "/ns" 'SIDit = 0 ResourcePath = fncHomePath mdbfile = ResourcePath & "MachineList.mdb" compDescTxt = ResourcePath & "compdesc.txt" RunWhat = "newsid /a " promptTitle = "Unknown Computer with MAC: " promptMessage = "Enter network name for NewSID to apply. " & chr(13) & "(ie: 140xxxLIBSTK)" resultMessage = "Please Wait - NewSID Is Now Running" & chr(13) & "The system will reboot automatically in a few minutes" ' -------------- ' Main ' -------------- inputname = LookupMACAttrib(fncLocalMACs,1) inputdescript = LookupMACAttrib(fncLocalMACs,4) If inputname = "na" Then inputname = inputbox(promptMessage,promptTitle & "Insert MAC here") inputdescript = inputbox("Enter a Computer Description","Computer Description") End If if inputname = "" Then inputdescript = "Computer Name Unspecified" wscript.echo "Canceled" WriteToText compDescTxt,inputdescript wscript.quit End If resultTitle = "Executing: " & RunWhat & inputname wscript.echo resultTitle WriteToText compDescTxt,inputdescript If SIDit = "/ns" Then RunNewSID result = MsgBox(resultMessage, vbExclaimation + vbOKOnly + vbSystemModal, resultTitle) Else wscript.echo chr(10) & "Just looking up - To actually run NewSID use /ns" End If wscript.quit ' -------------- ' End Main ' -------------- Sub RunNewSID wscript.echo "NewSID to be run" wscript.echo Runwhat & inputname ' inputname = "" ' RunWhat = "newsid.lnk" objShell.Run RunWhat & inputname,iNormalFocus End Sub Sub WriteToText(textOutFile,WhatToWrite) DIM objTextFile Set objTextFile = objFSO.OpenTextFile(textOutFile, ForWriting) objTextFile.Write WhatToWrite objTextFile.Close wscript.echo WhatToWrite & " > " & textOutFile End Sub Function LookupMACAttrib(strMACtoFind,AttribToGet) Const adOpenStatic = 3 ' does not continually refresh to see if database changed by something else Const adLockOptimistic = 3 ' does not exclusively lock the database to itself Const adUseClient = 3 ' script does its work locally vs over network DIM inx, FoundCount: FoundCount = 0 DIM objConnection: Set objConnection = CreateObject("ADODB.Connection") DIM objRecordSet: Set objRecordSet = CreateObject("ADODB.Recordset") DIM strConnect: strConnect = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & mdbfile objConnection.Open strConnect objRecordset.CursorLocation = adUseClient objRecordset.Open "SELECT * FROM MachineList" , objConnection, adOpenStatic, adLockOptimistic DIM strSearchCriteria, SCrit For Each SCrit in strMACtoFind If SCrit = "" Then ' wscript.echo "Skip it!" Else strSearchCriteria = "MACAddress = '" & SCrit & "'" objRecordSet.Find strSearchCriteria wscript.echo strSearchCriteria If objRecordSet.EOF Then ' wscript.echo "Not Found" Else FoundCount = FoundCount + 1 wscript.echo "Fetch Element " & AttribToGet & ": " & objRecordSet(AttribToGet) ' wscript.echo objRecordSet(0) ' Index ' wscript.echo objRecordSet(1) ' Network Name ' wscript.echo objRecordSet(2) ' BOOTTAB Name ' wscript.echo objRecordSet(3) ' MAC Address ' wscript.echo objRecordSet(4) ' Computer Description ' wscript.echo objRecordSet(5) ' future LookupMACAttrib = objRecordSet(AttribToGet) End If End If Next objConnection.Close If FoundCount = 0 Then LookupMACAttrib = "na" End If wscript.echo FoundCount & " MACs were Known" End Function ' ----------- ' Return Array with local MAC addresses ' ----------- Function fncLocalMACs 'Const NetConnectStatusUp = 2 'Const NetConnectStatusDn = 7 strComputer = "." DIM mldex:mldex = 0 DIM maclist(10) DIM objWMIService Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") DIM colAdapters Set colAdapters = objWMIService.ExecQuery _ ("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus = 2") DIM objAdapter For Each objAdapter in colAdapters maclist(mldex) = lcase(Replace(objAdapter.MACAddress, ":", "")) ' wscript.echo mldex & ":" & maclist(mldex) mldex = mldex + 1 Next fncLocalMacs = maclist End Function ' ------------------------ ' Retrieve path where script is actually located. ' ------------------------ Function fncHomePath DIM WshShell: Set WshShell = WScript.CreateObject("WScript.Shell") DIM path: path = WScript.ScriptFullName ' Script filename fncHomePath = Left(path, InStrRev(path, "\")) End Function