#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Icon256-32.ico #AutoIt3Wrapper_Outfile=WindowsMountPoints.exe #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_Description=Zabbix Windows Mountpoints Auto-Discovery #AutoIt3Wrapper_Res_Fileversion=1.0.0.25 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_LegalCopyright=2015 Bernhard Linz #AutoIt3Wrapper_Res_Language=1031 #AutoIt3Wrapper_Res_Field=Website|http://znil.net #AutoIt3Wrapper_Res_Field=Manual|http://znil.net/index.php?title=Zabbix:Template_Windows_Mountpoints_-_Windows_Festplatten_Mountpoints_entdecken #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include Opt('MustDeclareVars', 1) ; ########################################################################################################################## ; ########################################################################################################################## ; # WindowsMountpoints.exe --> Tool for Auto-Discovery Windows Mountpoints (Volumes without Driveletter, mounted at Folder)# ; # 2015 Bernhard Linz / Bernhard@znil.de / http://znil.net # ; # # ; # Latest Version of this Program and Template # ; # http://znil.net/index.php?title=Zabbix:Template_Windows_Mountpoints_-_Windows_Festplatten_Mountpoints_entdecken # ; # # ; # ________ .__ __. __ __ .__ __. _______ .___________. # ; # | / | \ | | | | | | | \ | | | ____|| | # ; # `---/ / | \| | | | | | | \| | | |__ `---| |----` # ; # / / | . ` | | | | | | . ` | | __| | | # ; # / /----.| |\ | | | | `----.__| |\ | | |____ | | # ; # /________||__| \__| |__| |_______(__)__| \__| |_______| |__| # ; # # ; ########################################################################################################################## ; ########################################################################################################################## ; Catch all Error while using the WMI-Interface with own Error-Function Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"), $f_COMError = False ; And the Error-Function itself Func MyErrFunc() Local $HexNumber=hex($oMyError.number,8) ;~ ConsoleWriteError("We intercepted a COM Error !" & @CRLF & _ ;~ "Number is: " & $HexNumber & @CRLF & _ ;~ "WinDescription is: " & $oMyError.windescription & @CRLF & _ ;~ "Source is: " & $oMyError.source & @CRLF & _ ;~ "ScriptLine is: " & $oMyError.scriptline & @CRLF) ConsoleWrite("ZBX_NOTSUPPORTED" & @CRLF) Exit 1 Endfunc ; ########################################################################################################################## ; ########################################################################################################################## ; Function for catching the special characters - hey we using the old DOS-Console and the Console did'nt like them Func _ANSI2OEM($text) $text = DllCall('user32.dll', 'Int', 'CharToOem', 'str', $text, 'str', '') Return $text[2] EndFunc ;==>_ANSI2OEM ; ########################################################################################################################## ; ########################################################################################################################## ; Other needed Variables Dim $wbemFlagReturnImmediately = 0x10 Dim $wbemFlagForwardOnly = 0x20 Dim $colItems = "" Dim $strComputer = "localhost" Dim $o_WMI Dim $o_colListOfVolumes Dim $s_JSONOutput Dim $s_Mointpoint2IgnoreFile = @ScriptDir & "\WindowsMountPoints-ignore.txt" Dim $h_Mountpoint2IgnoreFile Dim $a_Mountpoint2Ignore[1] = [ 0 ] Dim $b_IgnoreMountpoint = False Dim $i_ServiceType Dim $s_temp Dim $i Dim $s_spaces = ' ' ; 5 Spaces ; ########################################################################################################################## ; ########################################################################################################################## ; Some of the mountpoints are irritating, just ignore them - read items from a file If FileExists($s_Mointpoint2IgnoreFile) = 1 Then $h_Mountpoint2IgnoreFile = FileOpen($s_Mointpoint2IgnoreFile, 0) While 1 $s_temp = FileReadLine($h_Mountpoint2IgnoreFile) If @error = -1 Then ExitLoop Else If StringLen($s_temp) > 2 Then ; at least 3 or more chars $a_Mountpoint2Ignore[0] = $a_Mountpoint2Ignore[0] + 1 ReDim $a_Mountpoint2Ignore[$a_Mountpoint2Ignore[0] + 1] ;That's AutoIt - Redim an Array without data-loss $a_Mountpoint2Ignore[$a_Mountpoint2Ignore[0]] = $s_temp EndIf EndIf WEnd EndIf ; ########################################################################################################################## ; ########################################################################################################################## ; Get the WMI-Interface at local Computer (= .) $o_WMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") ; Test whether it worked and go on If IsObj($o_WMI) Then ; Get List of all Autostart-Services $o_colListOfVolumes = $o_WMI.ExecQuery("SELECT * FROM Win32_Volume", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) ; Ok, we have the List, now look if we were interrupted last Time ; Start creating the JSON Output: $s_JSONOutput = '{"data":[' & '@CRLF' ; Loop: Add the Services to JSON Output String Line for Line but nor more than 4000 Chars For $objMountpoint In $o_colListOfVolumes $b_IgnoreMountpoint = False ; Do nothing until we found the Service of last Run ; Will start after the first Part found the Service of last Time or will run from beginning if there was no last time ; Test 1: But first check if the service is one of the bad one we wanna ignore If $a_Mountpoint2Ignore[0] > 0 Then For $i = 1 To $a_Mountpoint2Ignore[0] ;ConsoleWrite($objMountpoint.DisplayName & "<--->" & $a_Mountpoint2Ignore[$i] & @CRLF) If StringInStr($objMountpoint.DeviceID, $a_Mountpoint2Ignore[$i]) > 0 Then $b_IgnoreMountpoint = True EndIf If StringInStr($objMountpoint.Name, $a_Mountpoint2Ignore[$i]) > 0 Then $b_IgnoreMountpoint = True EndIf Next EndIf ; Skip all normal Mountpoints with Driveletters like C:\ or D:\ If StringRight($objMountpoint.Name, 2) = ":\" Then $b_IgnoreMountpoint = True EndIf ; Ignore SnapShots! If StringLeft($objMountpoint.Name, 4) = "\\?\" Then $b_IgnoreMountpoint = True EndIf ; Ok, all Tests processed, now add the service to list (if we don't wanna ignore this service) If $b_IgnoreMountpoint = False Then $s_JSONOutput = $s_JSONOutput & _ $s_spaces & '{' & '@CRLF' & _ $s_spaces & $s_spaces & '"{#ZNILFSTYPE}":"' & $objMountpoint.FileSystem & '",' & '@CRLF' & _ $s_spaces & $s_spaces & '"{#ZNILFSNAME}":"' & StringReplace(StringTrimRight($objMountpoint.Name, 1),"\", "/") & '"' & '@CRLF' & _ $s_spaces & '},' & '@CRLF' EndIf Next ; Delete the last -> , <- $s_JSONOutput = StringTrimRight($s_JSONOutput, StringLen(',' & '@CRLF')) $s_JSONOutput = $s_JSONOutput & ']}' ; SpecialChars replace $s_JSONOutput = StringReplace($s_JSONOutput, "@CRLF", @CRLF, 0, 1) If StringLen($s_JSONOutput) < 11 Then ConsoleWrite('{"data":[]}' & @CRLF) Else ConsoleWrite(_ANSI2OEM($s_JSONOutput)) EndIf EndIf Exit 0