' File di esempio realizzato da Michele Nasi, IlSoftware.it - www.ilsoftware.it - versione 1.0 * http://creativecommons.org/licenses/by-nc/2.5/ ' --------------------------------------------------------------------------------------------------------------------------------------------- ' credits: ' Hey, Scripting Guy! Blog - http://blogs.technet.com/b/heyscriptingguy/archive/2007/02/14/how-can-i-automatically-open-new-files-added-to-a-folder.aspx ' Geek Speak, NateRice.com - http://www.naterice.com/articles/66 ' ****************************************************************************** ' RIGA DA MODIFICARE: ' ****************************************************************************** cartella = "C:\Users\Michele\Downloads" ' ****************************************************************************** Set objShell = CreateObject("Wscript.Shell") strComputer = "." cartella = Replace(cartella,"\","\\\\") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceCreationEvent WITHIN 3 WHERE " _ & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _ & "TargetInstance.GroupComponent= " _ & "'Win32_Directory.Name="""& cartella &"""'") Do Set objLatestEvent = colMonitoredEvents.NextEvent strNewFile = objLatestEvent.TargetInstance.PartComponent arrNewFile = Split(strNewFile, "=") strFileName = arrNewFile(1) strFileName = Replace(strFileName, "\\", "\") strFileName = Replace(strFileName, Chr(34), "") filnamelong=strFileName virustotal=leggipagina("https://www.virustotal.com/latest-scan/"& MD5Hash(strFileName)) if instr(virustotal,"File not found")=0 then if instr(virustotal,"0 /")=0 then messaggio="" if instr(virustotal,"1 /")>0 then messaggio="E' possibile che si tratti di un falso positivo dal momento che un solo motore di scansione antivirus ha indicato il file come potenzialmente dannoso." Msgbox "Il file "& filnamelong &" è stato rilevato da VirusTotal come nocivo."&vbcrlf&vbcrlf&messaggio,16 end if end if Loop Function leggipagina (url) Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") xmlhttp.open "GET", url, 0 xmlhttp.send "" p=xmlhttp.responseText Set xmlhttp=Nothing leggipagina=p End Function Public Function MD5Hash(sFileName) 'This script is provided under the Creative Commons license located 'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not 'be used for commercial purposes with out the expressed written consent 'of NateRice.com Const OpenAsDefault = -2 Const FailIfNotExist = 0 Const ForReading = 1 Dim oMD5CmdShell, oMD5CmdFSO, sTemp, sTempFile, fMD5CmdFile, sPath Dim fResultsFile, sResults Set oMD5CmdShell = CreateObject("WScript.Shell") Set oMD5CmdFSO = CreateObject("Scripting.FileSystemObject") sTemp = oMD5CmdShell.ExpandEnvironmentStrings("%TEMP%") sTempFile = sTemp & "\" & oMD5CmdFSO.GetTempName '------Verify Input File Existance----- If Not oMD5CmdFSO.FileExists(sFileName) Then MD5Hash = "Failed: Invalid Input File." Else Set fMD5CmdFile = oMD5CmdFSO.GetFile(sFileName) sPath = fMD5CmdFile.ShortPath sFileName = sPath Set fMD5CmdFile = Nothing End If '-------------------------------------- oMD5CmdShell.Run "%comspec% /c md5.exe -n " & sFileName & _ " > " & sTempFile, 0, True Set fResultsFile = _ oMD5CmdFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsDefault) sResults = fResultsFile.ReadAll sResults = trim(Replace(sResults, vbCRLF,"")) fResultsFile.Close oMD5CmdFSO.DeleteFile sTempFile If len(sResults) = 32 And IsHex(sResults) Then MD5Hash = sResults Else MD5Hash = "Failed." End If Set oMD5CmdShell = Nothing Set oMD5CmdFSO = Nothing End Function Private Function IsHex(sHexCheck) 'This script is provided under the Creative Commons license located 'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not 'be used for commercial purposes with out the expressed written consent 'of NateRice.com Dim sX, bCharCheck, sHexValue, sHexValues, aHexValues sHexCheck = UCase(sHexCheck) sHexValues = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F" aHexValues = Split(sHexValues, ",") For sX = 1 To Len(sHexCheck) bCharCheck = False For Each sHexValue In aHexValues If UCase(Mid(sHexCheck,sX,1)) = sHexValue Then bCharCheck = True Exit For End If Next If bCharCheck <> True Then IsHex = False Exit Function End If Next IsHex = True End Function