SHARE
TWEET

list_my_programs_v2

aveyo Oct 13th, 2014 (edited) 2,637 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* 2>nul&goto init %~nx0
  2. :start [ Batch main ] List my programs v2 by AveYo, all right reserved
  3. :: includes running processes, services and installed programs
  4. :: 2017 March - modernizing this really old, but still useful batch script
  5.  
  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_v2.bat - http://pastebin.com/GMyD7UwK] >%o%
  12. ver >>%o% & echo \\%COMPUTERNAME% %o% %DATE% %TIME% >>%o%
  13. set WSH="%WINDIR%\SYSTEM32\cscript.exe"
  14. if defined PROCESSOR_ARCHITEW6432 set WSH="%WINDIR%\Sysnative\cscript.exe"
  15. echo.>>%o%
  16. echo [RUNNING PROCESSES]>>%o%
  17. set "c1=Name,SessionId,ParentProcessId,ProcessId,Priority,WorkingSetSize,PrivatePageCount,PageFaults,PageFileUsage"
  18. set "c2=ThreadCount,HandleCount,WriteOperationCount,ReadOperationCount,OtherOperationCount,ExecutablePath"
  19. %WSH% /nologo /e:JScript "%~f0" wbem_query Win32_Process "%c1%,%c2%" >>%o%
  20. echo.>>%o%
  21. echo [RUNNING SERVICES]>>%o%
  22. set "c=Name,ProcessId,StartMode,PathName"
  23. %WSH% /nologo /e:JScript "%~f0" wbem_query Win32_Service "%c%" "where state='Running'">>%o%
  24. echo.>>%o%
  25. echo [DISABLED SERVICES]>>%o%
  26. set "c=Name,StartMode,PathName"
  27. %WSH% /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. %WSH% /nologo /e:JScript "%~f0" wbem_query Win32_StartupCommand "%c%">>%o%
  32. echo.>>%o%
  33. echo [INSTALLED PROGRAMS HKCU X64]>>%o%
  34. set "c=DisplayName,DisplayVersion,Publisher,InstallDate,InstallLocation"
  35. %WSH% /nologo /e:JScript "%~f0" winst_query 1 "Software\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  36. echo.>>%o%
  37. echo [INSTALLED PROGRAMS HKCU X86]>>%o%
  38. %WSH% /nologo /e:JScript "%~f0" winst_query 1 "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  39. echo.>>%o%
  40. echo [INSTALLED PROGRAMS HKLM X64]>>%o%
  41. %WSH% /nologo /e:JScript "%~f0" winst_query 2 "Software\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  42. echo.>>%o%
  43. echo [INSTALLED PROGRAMS HKLM X86]>>%o%
  44. %WSH% /nologo /e:JScript "%~f0" winst_query 2 "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
  45. :: done!
  46. echo  Done!
  47. call :get_reg HKCU\Software\Microsoft\Notepad lfFaceName notepadfont
  48. if exist %o% (
  49. reg add HKCU\Software\Microsoft\Notepad /v lfFaceName /t REG_SZ /d "FixedSys" /f 1>nul 2>nul
  50. start "" notepad %o%
  51. ping -n 2 localhost >nul 2>&1
  52. reg add HKCU\Software\Microsoft\Notepad /v lfFaceName /t REG_SZ /d "%notepadfont%" /f 1>nul 2>nul
  53. )
  54. goto :eof
  55.  
  56. :init [ Batch main functions ]
  57. @echo off & setlocal disabledelayedexpansion &title AveYo's %~nx0 &color 0B &cls & if "%1"=="_SELF_ADMIN" shift &shift & goto :start
  58. rem reg query "HKEY_USERS\S-1-5-20\Environment" /v temp 1>nul 2>nul && goto :start || echo Requesting admin rights.. & color 7c
  59. rem call cscript /nologo /e:JScript "%~f0" get_rights "%1" & exit & goto :eof
  60. goto :start "to ask for admin rights automatically, uncomment 2 lines above - not required in this version"
  61. :get_reg Params: 1=KeyName 2=ValueName 3=TargetVariable
  62. for /f "usebackq delims=? eol=*" %%s in (`reg query "%~1" /v "%~2"`) do set "_r_=%%s" & call set "_r_=%%_r_:    =?%%"
  63. (for /f "delims=? tokens=3* eol=*" %%s in ("%_r_%") do call set "%~3=%%s" & set "_r_=") & goto :eof
  64.  
  65. *//* [ JScript functions ] all lines above are ignored by starting script with a js comment */
  66. function get_rights(fn) {WSH.CreateObject('Shell.Application').ShellExecute(fn,'_SELF_ADMIN '+fn+' '+WSH.Arguments(1),'','runas',1)}
  67. function timer(f){var b=new Date();return{end: function(){var e=new Date(),t=e.getTime()-b.getTime();WSH.Echo('[',f,'] :',t,'ms')}}}
  68. 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)}
  69. function table_print(fields,head){
  70.   var p = 0, f = 0, total = fields[0].length, nr = head.length; if (total<3) return 0;
  71.   var pad = Array(nr), i = 0; while (i<nr) pad[i] = head[i++].length;
  72.   while (f<total) {i = 0; while (i<nr) { var p = (fields[i][f]+' ').length; if (p > pad[i]) {pad[i] = p}; i++ }; f++ }
  73.   f = 0; while (f<total) {
  74.     var row='', i = 0; while (i<nr) {row += padder(fields[i][f]+'', pad[i] + 2, ' ', (i==0) ? 1 : !!) i++ }; WSH.Echo(row); f++;
  75.   }
  76. }
  77. function winst_query(rkey,skey,keys) { /*var _timer=timer(skey);*/
  78.   var winst = WSH.CreateObject('WindowsInstaller.Installer'), head=keys.split(','), nr=head.length;
  79.   var fields = Array(nr), i = 0; while (i<nr) { fields[i] = []; fields[i].push(head[i]); fields[i].push('--------'); i++ }
  80.   var q = function(_rkey,_skey,_keys){var o=null; try{  o=winst.RegistryValue(parseInt(_rkey), _skey, _keys)  }catch(e){} return o};
  81.   var k = null, v = null, s = null, r = 0; while (r<500) {
  82.     r++; k = q(rkey, skey, -r); if (k==null) continue; i = 0; while (i<nr) {
  83.       s = q(rkey, skey+'\\'+k, head[i]); if (i==0 && s==null) { i = nr } else { fields[i].push( (s==null) ? '' : !!) i++ }
  84.     }
  85.   }
  86.   table_print(fields,head); /*_timer.end();*/
  87. }
  88. function wbem_query(table,cols,clause) { /*var _timer=timer(skey);*/
  89.   var wbem = WSH.CreateObject('WbemScripting.SWbemLocator').ConnectServer('.', 'root\\cimv2'), head=cols.split(','), nr=head.length;
  90.   var fields = Array(nr), i = 0; while (i<nr) { fields[i] = []; fields[i].push(head[i]); fields[i].push('--------'); i++ }
  91.   var q = new Enumerator(wbem.ExecQuery('select ' + cols + ' from ' + table + ' ' + clause));
  92.   while (!q.atEnd()) {
  93.     var i = 0; while (i<nr) { var s=q.item()[ head[i] ] || ''; fields[i].push( s+'' ); i++ }
  94.     q.moveNext();
  95.   }
  96.   table_print(fields,head); /*_timer.end();*/
  97. }
  98. if (WSH.Arguments(0)=='get_rights') get_rights(WSH.ScriptFullName);
  99. if (WSH.Arguments(0)=='winst_query') winst_query(WSH.Arguments(1),WSH.Arguments(2),WSH.Arguments(3));
  100. if (WSH.Arguments(0)=='wbem_query') wbem_query(WSH.Arguments(1),WSH.Arguments(2),(WSH.Arguments.length>=4) ? WSH.Arguments(3) : '' )
  101. //
RAW Paste Data
Top