Advertisement
RJSN

EXE to TXT

Nov 4th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.73 KB | None | 0 0
  1. '==============================================================================
  2. '
  3. ' NAME: getExeInfo.vbs
  4. '
  5. ' SITE  : HTTP://ITTECHLOG.WORDPRESS.COM
  6. '
  7. ' COMMENT: This script lists all exe files from a given path, incl FileVersion
  8. '          It also checks if a found exe-file is installed as a Service.
  9. '==============================================================================
  10.  
  11. Option Explicit
  12. On Error Resume Next
  13.  
  14. Dim strDir, strScriptPath, strTextFile
  15. Dim qryServices
  16. Dim objFSO, objDir, objWMIService, objService
  17.  
  18. strDir = "Q:\"
  19.  
  20. Set objFSO = CreateObject("Scripting.FileSystemObject")
  21. Set objDir = objFSO.GetFolder(strDir)
  22. Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
  23. Set qryServices = objWMIService.ExecQuery ("Select * from Win32_Service")
  24.  
  25. strScriptPath = objFSO.GetParentFolderName(wscript.ScriptFullName)
  26.  
  27. Set strTextFile = objFSO.CreateTextFile(strScriptPath & "\FileInfo.txt", True)
  28.  
  29. FindFiles(objDir)
  30.  
  31. strTextFile.Close
  32.  
  33. Wscript.echo "Done"
  34.  
  35.  
  36. Sub FindFiles(strCurrentDir)
  37.     Dim strFile, strService
  38.     For Each strFile In strCurrentDir.Files
  39.         If LCase(Right(Cstr(strFile.Name), 4)) = ".exe" Then
  40.                                    
  41.             'check if exe is listed as service
  42.             For Each objService in qryServices
  43.                 If (InStr(objService.PathName,strFile.Name)) Then
  44.                     strService = objService.DisplayName & " (" & objService.PathName & ")"                                 
  45.                 Else
  46.                     strService = ""
  47.                 End If             
  48.             Next
  49.             'list exe with FileVersion and Service
  50.             strTextFile.WriteLine(strFile.Name & vbTab & vbTab & vbTab & objFSO.GetFileVersion(strCurrentDir & "\" & strFile.Name)) & vbTab & strService
  51.         End If
  52.     Next
  53.  
  54.     For Each strFile In strCurrentDir.SubFolders
  55.         FindFiles(strFile)
  56.     Next
  57. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement