Quite a while I tried to compile a batch file which could start or stop oracle services based on their running status. At last, by altering few codes found through google search, I managed to make one. Below you can find it.
Update: Added prompt(s), bracketing in order to make the script work on Windows 8.x
You must change “net start ” with your installation specific service names!
sc query "OracleOraDb10g_home1TNSListener" | findstr /i running
IF "%ERRORLEVEL%"=="0" (GOTO :RUNNING) ELSE (GOTO :STOPPED)
set /P c=Oracle Services are not running, you want to start them now[Y/N]?
if /I "%c%" EQU "Y" goto :start_them
net start "OracleOraDb10g_home1TNSListener" | sc query "OracleServiceSCT" | findstr /i running
IF NOT "%ERRORLEVEL%"=="0" (net start OracleServiceSCT)
set /P c=Oracle Services are running, you want to stop them now[Y/N]?
if /I "%c%" EQU "Y" goto :stop_them
net stop "OracleOraDb10g_home1TNSListener" | sc query "OracleServiceSCT" | findstr /i running
if "%ERRORLEVEL%"=="0" (net stop OracleServiceSCT)
Just copy and paste the code inside a text file and change the extension to “.cmd” or “.bat”. Make sure to “Run as administrator” if UAC is enabled.
Hope this bit of code is useful for those developers who do not want to strain the limited resources they have with their notebooks/laptops and need the local databases only upon demand.
for Windows7bugs, raj.
4 thoughts on “Single batch file for starting and stopping Oracle services”
could you give me the code for oracle 10g….???
What do you mean by code for 10g? Basically this code is generic for both 10g or later Oracle services. All you need is to change the service names accordingly.
net start & net stop services is not working
I have write two simple batch program to start and stop a service
but both net start and net stop services is not working on my lappy which runs on windows 7 ultimate 64-bit
it is showing access denied…..
please help how can I start or stop a service in a batch program
or any solution of this error
You need elevated admin privileges in Windows 7 to run batch files. Create the batch file, put it over the desktop and then right click and change the properties to “Run as Administrator”