Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @set @v=4 /* List my programs by AveYo
- :: includes running processes and services, installed programs, scheduled tasks and application crashing events
- :: 2017 March - modernizing this really old, but still useful batch script
- :: 2017 December - added application crashing events, scheduled tasks; listing UninstallString; filter svchost.exe; csv-like format
- :: 2019 July - replace quotes, use | delimiter as , appears frequently in program names and breaks csv import
- @echo off & setlocal disabledelayedexpansion &title List my programs by AveYo &color 0B &cls
- set o="%USERPROFILE%\Desktop\List_my_programs.txt"
- cd.>%o%
- if not exist %o% set o="%TEMP%\List_my_programs.txt"
- echo.
- echo Please wait while generating %o% ...
- echo [List_my_programs_v4.bat - http://pastebin.com/GMyD7UwK] >%o%
- ver >>%o% & echo \\%COMPUTERNAME% %o% %DATE% %TIME% >>%o%
- echo.>>%o%
- echo [RUNNING PROCESSES] not svchost.exe>>%o%
- set "c1=Name,SessionId,ParentProcessId,ProcessId,Priority,WorkingSetSize,PrivatePageCount,PageFaults,PageFileUsage"
- set "c2=ThreadCount,HandleCount,WriteOperationCount,ReadOperationCount,OtherOperationCount,ExecutablePath"
- set "NOT_SVCHOST=NOT (Name='svchost.exe' AND ExecutablePath=NULL OR ExecutablePath LIKE '%%%WINDIR:\=\\%\\system32\\svchost.exe%%')"
- cscript /nologo /e:JScript "%~f0" wbem_query Win32_Process "%c1%,%c2%" "WHERE %NOT_SVCHOST%">>%o%
- echo.>>%o%
- echo [RUNNING SERVICES] not svchost-based>>%o%
- set "c=Name,StartMode,ProcessId,PathName"
- set "NOT_SVCHOST_BASED=NOT PathName LIKE '%%%WINDIR:\=\\%\\system32\\svchost.exe%%'"
- cscript /nologo /e:JScript "%~f0" wbem_query Win32_Service "%c%" "WHERE State='Running' AND %NOT_SVCHOST_BASED%">>%o%
- echo.>>%o%
- echo [DISABLED SERVICES]>>%o%
- set "c=Name,StartMode,PathName"
- cscript /nologo /e:JScript "%~f0" wbem_query Win32_Service "%c%" "WHERE Startmode='Disabled'">>%o%
- echo.>>%o%
- echo [STARTUP PROGRAMS]>>%o%
- set "c=Command,Description,Caption,Name,User,SettingID,Location"
- cscript /nologo /e:JScript "%~f0" wbem_query Win32_StartupCommand "%c%">>%o%
- echo.>>%o%
- echo [INSTALLED PROGRAMS HKCU X64]>>%o%
- set "c=DisplayName,DisplayVersion,Publisher,InstallDate,UninstallString"
- cscript /nologo /e:JScript "%~f0" winst_query 1 "Software\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
- echo.>>%o%
- echo [INSTALLED PROGRAMS HKCU X86]>>%o%
- cscript /nologo /e:JScript "%~f0" winst_query 1 "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
- echo.>>%o%
- echo [INSTALLED PROGRAMS HKLM X64]>>%o%
- cscript /nologo /e:JScript "%~f0" winst_query 2 "Software\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
- echo.>>%o%
- echo [INSTALLED PROGRAMS HKLM X86]>>%o%
- cscript /nologo /e:JScript "%~f0" winst_query 2 "Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" "%c%" >>%o%
- echo.>>%o%
- echo [SCHEDULED TASKS] not Microsoft\Windows>>%o%
- echo TaskName,NextRunTime,Status>>%o%
- echo --------,-----------,------>>%o%
- ::schtasks /query /fo csv /nh |find /i /v "\Microsoft\Windows\">>%o%
- schtasks /query /fo table /nh|findstr /v "^$">>%o%
- echo.>>%o%
- echo [APPLICATION CRASHING EVENTS] not Apps\Microsoft>>%o%
- set "c=RecordNumber,TimeGenerated,Message"
- set "NOT_APPS_MICROSOFT=Category=100 AND NOT Message LIKE '%%Apps\\Microsoft%%'"
- cscript /nologo /e:JScript "%~f0" wbem_query Win32_NTLogEvent "%c%" "WHERE Logfile='Application' AND %NOT_APPS_MICROSOFT%" >>%o%
- echo.>>%o%
- :: done!
- echo Done!
- call :reg_query notepadfont "HKCU\Software\Microsoft\Notepad" lfFaceName
- if exist %o% (
- reg add HKCU\Software\Microsoft\Notepad /v lfFaceName /t REG_SZ /d "FixedSys" /f 1>nul 2>nul
- start "" notepad %o%
- ping -n 2 localhost >nul 2>&1
- reg add HKCU\Software\Microsoft\Notepad /v lfFaceName /t REG_SZ /d "%notepadfont%" /f 1>nul 2>nul
- )
- exit/b
- :reg_query [USAGE] call :reg_query ResultVar "HKCU\KeyName" "ValueName"
- (for /f "skip=2 delims=" %%s in ('reg query "%~2" /v "%~3" /z 2^>nul') do set ".=%%s" & call set "%~1=%%.:*) =%%") & exit/b
- *//* [ JScript functions ] all lines above are ignored by starting script with a js comment */
- function timer(f){var b=new Date();return{end: function(){var e=new Date(),t=e.getTime()-b.getTime();WSH.Echo('[',f,'] :',t,'ms')}}}
- 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)}
- function table_print(fields,head){
- var p = 0, f = 0, total = fields[0].length, nr = head.length; if (total<3) return 0;
- var pad = Array(nr), i = 0; while (i<nr) pad[i] = head[i++].length;
- while (f<total) {i = 0; while (i<nr) { var p = (fields[i][f]+' ').length; if (p > pad[i]) {pad[i] = p}; i++ }; f++ }
- f = 0; while (f<total) {
- var row='', i = 0; while (i<nr) {row += padder(fields[i][f]+'', pad[i] + 2, ' ', (i==0) ? 1 : !!) i++ }; WSH.Echo(row); f++;
- }
- }
- function winst_query(rkey,skey,keys) { /*var _timer=timer(skey);*/
- var winst = WSH.CreateObject('WindowsInstaller.Installer'), head=keys.split(','), nr=head.length;
- var fields = Array(nr), i = 0; while (i<nr) { fields[i] = []; fields[i].push(head[i]+' | '); fields[i].push('-------- | '); i++ }
- var q = function(_rkey,_skey,_keys){var o=null; try{ o=winst.RegistryValue(parseInt(_rkey), _skey, _keys) }catch(e){} return o};
- var k = null, v = null, s = null, r = 0; while (r<500) {
- r++; k = q(rkey, skey, -r); if (k==null) continue; i = 0; while (i<nr) {
- s = q(rkey, skey+'\\'+k, head[i]);
- if (i==0 && s==null) { i = nr } else { fields[i].push( (s==null) ? '' : s.split('"').join("'")+' | '); i++ }
- }
- }
- table_print(fields,head); /*_timer.end();*/
- }
- function wbem_query(table,cols,clause) { /*var _timer=timer(skey);*/
- var wbem = WSH.CreateObject('WbemScripting.SWbemLocator').ConnectServer('.', 'root\\cimv2'), head=cols.split(','), nr=head.length;
- var fields = Array(nr), i = 0; while (i<nr) { fields[i] = []; fields[i].push(head[i]+' | '); fields[i].push('-------- | '); i++ }
- var q = new Enumerator(wbem.ExecQuery('select ' + cols + ' from ' + table + ' ' + clause));
- while (!q.atEnd()) {
- var i = 0; while (i<nr) { var s=q.item()[ head[i] ]+'' || ''; fields[i].push( s.split('"').join("'")+' | ' ); i++ }
- q.moveNext();
- }
- table_print(fields,head); /*_timer.end();*/
- }
- if (WSH.Arguments(0)=='winst_query') winst_query(WSH.Arguments(1),WSH.Arguments(2),WSH.Arguments(3));
- if (WSH.Arguments(0)=='wbem_query') wbem_query(WSH.Arguments(1),WSH.Arguments(2),(WSH.Arguments.length>=4) ? WSH.Arguments(3) : '' )
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement