0

Firstly, please excuse my ignorance as I am completely new to scripting.. Here is what I am planning to do

  1. Stop the service

    (it would be good if i could check if service exists in the first place, otherwise, it should still continue on with the script correct?)

  2. Check if Win2k or WinXP, Uninstall the service and delete files according to OS type

  3. Install new application

  4. Start service

Here is what I have at the moment. Can someone please review and suggest ways of improvement? Many thanks in advance.

@echo off  
net stop "service name"  

Here, I want to check if the service exists, if yes, just go ahead and stop it, else, echo "Service not installed" and go ahead to uninstall_and_install routine, can i do as below?

if ERRORLEVEL 0 GOTO uninstall_and_install IF NOT echo Service not found GOTO uninstall_and_install  
:uninstall_and_install  
C:  
IF NOT EXIST c:\Windows GOTO Win2k  
cd Windows\system32\  
"insert commands to uninstall and install 

:Win2k  
cd Winnt\system32\  
"insert commands to uninstall and install 

exit 
molecule
  • 83
  • 1
  • 4
  • 12

1 Answers1

0

You might take some hints from the example below.

@echo off
set SERVICENAME=w32time

REM Check if the service is installed
REM ==================================================
    sc query %SERVICENAME% > nul 2>nul
    if %ERRORLEVEL% == 1060 goto serviceDoesNotExist

:serviceDoesExist
    net stop %SERVICENAME%

:serviceDoesNotExist
    REM Get Operating System Version
    for /F "usebackq delims==" %%i IN (`ver`) DO (set OSVersion=%%i)

    echo %OSVersion% | find "Microsoft Windows [Version 6.1.7600]"
    if %ERRORLEVEL% NEQ 0 GOTO :windows7

:windows7
    echo Install the Application the Windows 7 way
pacey
  • 3,833
  • 1
  • 16
  • 31