List services with wild card

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bwilson
Posts: 1
Joined: 13 Nov 2017 18:21

List services with wild card

#1 Post by bwilson » 13 Nov 2017 18:27

Is there a better way to script this? I am not getting the results expected:

Code: Select all

for %%x in ('sc query ^| find "Oracle*"') do (for %%g in (%%x) do (echo %%g >>tempfile.txt))

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: List services with wild card

#2 Post by SIMMS7400 » 13 Nov 2017 19:08

I work with Oracle services every day :mrgreen: This script will write all service starting with "Oracle" to tempfile.txt.

Code: Select all

@echo off &setlocal
set "SERVICE_NAME="
for /f "tokens=1* delims=: " %%i in ('sc query ^| findstr /vbc:" "') do if not defined SERVICE_NAME (set "%%i=%%j") else (
  set "%%i=%%j"
  setlocal EnableDelayedExpansion
  if /i "!DISPLAY_NAME:~,6!"=="Oracle" echo "!SERVICE_NAME!" "!DISPLAY_NAME!">>tempfile.txt
  endlocal
  set "SERVICE_NAME="
)
pause
Output on my environment:

Code: Select all

"HyS9aifWeb_epmsystem1" "Oracle Hyperion FDM Enterprise Edition - Java Web Application (epmsystem1)"
"HyS9aps_epmsystem1" "Oracle Hyperion Provider Services - Java Web Application (epmsystem1)"
"HyS9CALC_epmsystem1" "Oracle Hyperion CALC Manager - Java Web Application (epmsystem1)"
"HyS9Disclosure_epmsystem1" "Oracle Hyperion Disclosure Management - Java Web Application (epmsystem1)"
"HyS9eas_epmsystem1" "Oracle Hyperion Administration Services - Java Web Application (epmsystem1)"
"HyS9EPMADataSynchronizer_epmsystem1" "Oracle Hyperion EPMA Data Synchronizer - Java Web Application (epmsystem1)"
"HyS9EPMAServer_epmsystem1" "Oracle Hyperion EPMA Server (epmsystem1)"
"HyS9EPMAWebTier_epmsystem1" "Oracle Hyperion EPMA Web Tier - Java Web Application (epmsystem1)"
"HyS9EssbaseStudio_epmsystem1" "Oracle Hyperion Essbase Studio Server (epmsystem1)"
"HyS9FinancialManagementJavaServer_epmsystem1" "Oracle Hyperion Financial Management - Java Server (epmsystem1)"
"HyS9FinancialManagementWeb_epmsystem1" "Oracle Hyperion Financial Management - Web Tier (epmsystem1)"
"HyS9FoundationServices_epmsystem1" "Oracle Hyperion Foundation Services - Managed Server (epmsystem1)"
"HyS9FRReports_epmsystem1" "Oracle Hyperion Financial Reporting - Java Web Application (epmsystem1)"
"HyS9HsfSrv_epmsystem1" "Oracle Hyperion Strategic Finance - Server (epmsystem1)"
"HyS9HsfWeb_epmsystem1" "Oracle Hyperion Strategic Finance - Java Web Application (epmsystem1)"
"HyS9Planning_epmsystem1" "Oracle Hyperion Planning - Java Web Application (epmsystem1)"
"HyS9RaFrameworkAgent_epmsystem1" "Oracle Hyperion Reporting and Analysis Framework (epmsystem1)"
"HyS9RaFramework_epmsystem1" "Oracle Hyperion Reporting and Analysis Framework - Java Web Application (epmsystem1)"
"HyS9RMIRegistry_epmsystem1" "Oracle Hyperion RMI Registry (epmsystem1)"
"Oracle DRM Service" "Oracle DRM Service"
"OracleProcessManager_EPM_epmsystem1" "Oracle Process Manager (epmsystem1)"
"OracleProcessManager_ohsInstance3193331783" "Oracle Process Manager (ohsInstance3193331783)"

Post Reply