SHARE
TWEET

list_my_programs

aveyo Oct 13th, 2014 (edited) 4,008 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. goto="init" /* List my programs v3 by AveYo
  2. :: includes running processes and services, installed programs, scheduled tasks and application crashing events
  3. :: 2017 March - modernizing this really old, but still useful batch script
  4. :: 2017 December - added application crashing events, scheduled tasks; listing UninstallString; filter svchost.exe; csv-like format
  5. :start [ Batch main ]
  6. set o="%USERPROFILE%\Desktop\List_my_programs.txt"
  7. cd.>%o%
  8. if not exist %o% set o="%TEMP%\List_my_programs.txt"
  9. echo.
  10. echo  Please wait while generating %o% ...
  11. echo [List_my_programs_v3.bat - http://pastebin.com/GMyD7UwK] >%o%
  12. ver >>%o% & echo \\%COMPUTERNAME% %o% %DATE% %TIME% >>%o%
  13. echo.>>%o%
  14. echo [RUNNING PROCESSES] not svchost.exe>>%o%
  15. set "c1=Name,SessionId,ParentProcessId,ProcessId,Priority,WorkingSetSize,PrivatePageCount,PageFaults,PageFileUsage"
  16. set "c2=ThreadCount,HandleCount,WriteOperationCount,ReadOperationCount,OtherOperationCount,ExecutablePath"
  17. set "NOT_SVCHOST=NOT (Name='svchost.exe' AND ExecutablePath=NULL OR ExecutablePath LIKE '%%%WINDIR:\=\\%\\system32\\svchost.exe%%')"
  18. cscript /nologo /e:JScript "%~f0" wbem_query Win32_Process "%c1%,%c2%" "WHERE %NOT_SVCHOST%">>%o%
  19. echo.>>%o%
  20. echo [RUNNING SERVICES] not svchost-based>>%o%
  21. set "c=Name,StartMode,ProcessId,PathName"
  22. set "NOT_SVCHOST_BASED=NOT PathName LIKE '%%%WINDIR:\=\\%\\system32\\svchost.exe%%'"
  23. cscript /nologo /e:JScript "%~f0" wbem_query Win32_Service "%c%" "WHERE State='Running' AND %NOT_SVCHOST_BASED%">>%o%
  24. echo.>>%o%
  25. echo [DISABLED SERVICES]>>%o%
  26. set "c=Name,StartMode,PathName"
  27. cscript /nologo /e:JScript "%~f0" wbem_query Win32_Service "%c%" "WHERE Startmode='Disabled'">>%o%
  28. echo.>>%o%
  29. echo [STARTUP PROGRAMS]>>%o%
  30. set "c=Command,Description,Caption,Name,User,SettingID,Location"
  31. cscript /nologo /e:JScript "%~f0" wbem_query Win32_StartupCommand "%c%">>%o%
  32. echo.>>%o%
  33. echo [SCHEDULED TASKS] not Microsoft\Windows>>%o%
  34. echo TaskName,NextRunTime,Status>>%o%
  35. echo --------,-----------,------>>%o%
  36. schtasks /query /fo csv /nh |find /i /v "\Microsoft\Windows\">>%o%
  37. echo.>>%o%
  38. echo [INSTALLED PROGRAMS HKCU X64]>>%o%
  39. set "c=DisplayName,DisplayVersion,Publisher,InstallDate,UninstallString"
  40. cscript /nologo /e:JScript "%~f0" winst_query 1 "Software\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  41. echo.>>%o%
  42. echo [INSTALLED PROGRAMS HKCU X86]>>%o%
  43. cscript /nologo /e:JScript "%~f0" winst_query 1 "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  44. echo.>>%o%
  45. echo [INSTALLED PROGRAMS HKLM X64]>>%o%
  46. cscript /nologo /e:JScript "%~f0" winst_query 2 "Software\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  47. echo.>>%o%
  48. echo [INSTALLED PROGRAMS HKLM X86]>>%o%
  49. cscript /nologo /e:JScript "%~f0" winst_query 2 "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  50. echo.>>%o%
  51. echo [APPLICATION CRASHING EVENTS] not Apps\Microsoft>>%o%
  52. set "c=RecordNumber,TimeGenerated,Message"
  53. set "NOT_APPS_MICROSOFT=Category=100 AND NOT Message LIKE '%%Apps\\Microsoft%%'"
  54. cscript /nologo /e:JScript "%~f0" wbem_query Win32_NTLogEvent "%c%" "WHERE Logfile='Application' AND %NOT_APPS_MICROSOFT%" >>%o%
  55. echo.>>%o%
  56.  
  57. :: done!
  58. echo  Done!
  59. call :get_reg HKCU\Software\Microsoft\Notepad lfFaceName notepadfont
  60. if exist %o% (
  61. reg add HKCU\Software\Microsoft\Notepad /v lfFaceName /t REG_SZ /d "FixedSys" /f 1>nul 2>nul
  62. start "" notepad %o%
  63. ping -n 2 localhost >nul 2>&1
  64. reg add HKCU\Software\Microsoft\Notepad /v lfFaceName /t REG_SZ /d "%notepadfont%" /f 1>nul 2>nul
  65. )
  66. exit/b
  67.  
  68. :"init" [ Batch main functions ]
  69. @echo off & setlocal disabledelayedexpansion &title AveYo's %~nx0 &color 0B &cls & if "%1"=="_SELF_ADMIN" shift &shift & goto :start
  70. rem reg query "HKEY_USERS\S-1-5-20\Environment" /v temp 1>nul 2>nul && goto :start || echo Requesting admin rights.. & color 7c
  71. rem call cscript /nologo /e:JScript "%~f0" get_rights "%1" & exit & goto :eof
  72. goto :start "to ask for admin rights automatically, uncomment 2 lines above - not required starting with v2"
  73. :get_reg Params: 1=KeyName 2=ValueName 3=TargetVariable
  74. for /f "usebackq delims=? eol=*" %%s in (`reg query "%~1" /v "%~2"`) do set "_r_=%%s" & call set "_r_=%%_r_:    =?%%"
  75. (for /f "delims=? tokens=3* eol=*" %%s in ("%_r_%") do call set "%~3=%%s" & set "_r_=") & exit/b
  76.  
  77. *//* [ JScript functions ] all lines above are ignored by starting script with a js comment */
  78. function get_rights(fn) {WSH.CreateObject('Shell.Application').ShellExecute(fn,'_SELF_ADMIN '+fn+' '+WSH.Arguments(1),'','runas',1)}
  79. function timer(f){var b=new Date();return{end: function(){var e=new Date(),t=e.getTime()-b.getTime();WSH.Echo('[',f,'] :',t,'ms')}}}
  80. function padder(s,n,chr,dir){var p=Array(n+1).join(chr);return (dir<0)? p.substring(0,n - s.length) + s : s + p.slice(s.length - n)}
  81. function table_print(fields,head){
  82.   var p = 0, f = 0, total = fields[0].length, nr = head.length; if (total<3) return 0;
  83.   var pad = Array(nr), i = 0; while (i<nr) pad[i] = head[i++].length;
  84.   while (f<total) {i = 0; while (i<nr) { var p = (fields[i][f]+' ').length; if (p > pad[i]) {pad[i] = p}; i++ }; f++ }
  85.   f = 0; while (f<total) {
  86.     var row='', i = 0; while (i<nr) {row += padder(fields[i][f]+'', pad[i] + 2, ' ', (i==0) ? 1 : !!) i++ }; WSH.Echo(row); f++;
  87.   }
  88. }
  89. function winst_query(rkey,skey,keys) { /*var _timer=timer(skey);*/
  90.   var winst = WSH.CreateObject('WindowsInstaller.Installer'), head=keys.split(','), nr=head.length;
  91.   var fields = Array(nr), i = 0; while (i<nr) { fields[i] = []; fields[i].push(head[i]+' ,'); fields[i].push('-------- ,'); i++ }
  92.   var q = function(_rkey,_skey,_keys){var o=null; try{  o=winst.RegistryValue(parseInt(_rkey), _skey, _keys)  }catch(e){} return o};
  93.   var k = null, v = null, s = null, r = 0; while (r<500) {
  94.     r++; k = q(rkey, skey, -r); if (k==null) continue; i = 0; while (i<nr) {
  95.       s = q(rkey, skey+'\\'+k, head[i]); if (i==0 && s==null) { i = nr } else { fields[i].push( (s==null) ? '' : s+' ,'); i++ }
  96.     }
  97.   }
  98.   table_print(fields,head); /*_timer.end();*/
  99. }
  100. function wbem_query(table,cols,clause) { /*var _timer=timer(skey);*/
  101.   var wbem = WSH.CreateObject('WbemScripting.SWbemLocator').ConnectServer('.', 'root\\cimv2'), head=cols.split(','), nr=head.length;
  102.   var fields = Array(nr), i = 0; while (i<nr) { fields[i] = []; fields[i].push(head[i]+' ,'); fields[i].push('-------- ,'); i++ }
  103.   var q = new Enumerator(wbem.ExecQuery('select ' + cols + ' from ' + table + ' ' + clause));
  104.   while (!q.atEnd()) {
  105.     var i = 0; while (i<nr) { var s=q.item()[ head[i] ] || ''; fields[i].push( s+' ,' ); i++ }
  106.     q.moveNext();
  107.   }
  108.   table_print(fields,head); /*_timer.end();*/
  109. }
  110. if (WSH.Arguments(0)=='get_rights') get_rights(WSH.ScriptFullName);
  111. if (WSH.Arguments(0)=='winst_query') winst_query(WSH.Arguments(1),WSH.Arguments(2),WSH.Arguments(3));
  112. if (WSH.Arguments(0)=='wbem_query') wbem_query(WSH.Arguments(1),WSH.Arguments(2),(WSH.Arguments.length>=4) ? WSH.Arguments(3) : '' )
  113. //
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top