SC function failing when using variables

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

SC function failing when using variables

#1 Post by SIMMS7400 » 17 Nov 2016 15:46

Hi Folks -

At one of my clients, I'm running into an issue when using SC to STOP and START services.

The messgae I get is as follows:

OpenSCManager Failed 1722


My code is as follows:

Code: Select all

:EXEC_ACTION
PING -n 10 127.0.0.1>nul

IF [%1] == [] GOTO Usage
IF [%2] == [] GOTO Usage
IF [%3] == [] GOTO Usage

SET ACTION=%1
SET SERVICENAME=%2
SET SYSTEMNAME=%3

IF %ACTION%==stop ( SET ACTION=STOP)^
   ELSE IF %ACTION%==STOP    ( SET ACTION=STOP)^
   ELSE IF %ACTION%==start   ( SET ACTION=START)^
   ELSE IF %ACTION%==START   ( SET ACTION=START)^
   ELSE IF %ACTION%==restart ( SET ACTION=RESTART)^
   ELSE IF %ACTION%==RESTART ( SET ACTION=RESTART)^
   ELSE GOTO Usage

SET STATE=
SET CURRENT_STATUS=
SET /A DEFAULT_DELAY=5
SET /A SLEEP_COUNT=0
SET /A RESTARTED=0
SET /A MAX_WAIT_PERIODS=5

ECHO Process Info:                                             >>%logfile%
ECHO.                                                                       >>%logfile%
ECHO Server Name  : %SYSTEMNAME%                                            >>%logfile%
ECHO Action       : %ACTION%                                                >>%logfile%
ECHO Service Name : %SERVICENAME%                                           >>%logfile%
ECHO.                                                                       >>%logfile%
ECHO Attempting to %ACTION% service %SERVICENAME% on computer %SYSTEMNAME%  >>%logfile%

SC \\%SYSTEMNAME% query %SERVICENAME% | FIND "FAILED 1060" >nul 2>&1
IF %ERRORLEVEL%==0 IF NOT %ERRORLEVEL%==1 (
    ECHO.                                             >>%logfile%
    ECHO Failure! Service %SERVICENAME% is not valid! >>%logfile%
    EXIT /B 0
)
SC \\%SYSTEMNAME% query %SERVICENAME% | FIND "STATE" >nul 2>&1
IF %ERRORLEVEL%==1 IF NOT %ERRORLEVEL%==2 (
    ECHO.                                                                                         >>%logfile%
    ECHO Failure! Server \\%SYSTEMNAME% or service %SERVICENAME% is not accessible or is offline! >>%logfile%
    EXIT /B 0
)

:Dispatch
FOR /f "tokens=*" %%i IN ('SC \\%SYSTEMNAME% query %SERVICENAME% ^| FIND "STATE"') DO SET STATE=%%i

ECHO %STATE% | FINDSTR /C:"1" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=STOPPED
ECHO %STATE% | FINDSTR /C:"2" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=START_PENDING
ECHO %STATE% | FINDSTR /C:"3" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=STOP_PENDING
ECHO %STATE% | FINDSTR /C:"4" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=RUNNING
ECHO %STATE% | FINDSTR /C:"5" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=CONTINUE_PENDING
ECHO %STATE% | FINDSTR /C:"6" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=PAUSE_PENDING
ECHO %STATE% | FINDSTR /C:"7" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=PAUSED

ECHO Current status of service is %CURRENT_STATUS% >>%logfile%

IF NOT "%CURRENT_STATUS%"=="RUNNING" IF NOT "%CURRENT_STATUS%"=="STOPPED" IF NOT "%CURRENT_STATUS%"=="PAUSED" (
    IF "%SLEEP_COUNT%"=="%MAX_WAIT_PERIODS%" (
        ECHO Service state won't change. Script exececution is canceled.>>%logfile%
        EXIT /B 0
    )
    ECHO Service State is changing, waiting %DEFAULT_DELAY% seconds...>>%logfile%
    SLEEP %DEFAULT_DELAY%
    SET /A SLEEP_COUNT+=1
    GOTO Dispatch
)

IF %ACTION%==START (
    IF %CURRENT_STATUS%==RUNNING (
       ECHO.                                              >>%logfile%
        ECHO Service %SERVICENAME% is currently running.   >>%logfile%
      ECHO No further action is necessary                >>%logfile%
      ECHO.                                              >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StartService
    )
) ELSE IF %ACTION%==RESTART (
    IF %CURRENT_STATUS%==RUNNING (
        IF %RESTARTED%==1 (
          ECHO.                                          >>%logfile%
            ECHO Service %SERVICENAME% has been restarted. >>%logfile%
         ECHO No further action is necessary            >>%logfile%
         ECHO.                                          >>%logfile%
            GOTO EndExit
        )
        SET /A SLEEP_COUNT=0
        GOTO StopService
    ) ELSE (
        SET /A RESTARTED=1
        GOTO StartService
    )
) ELSE IF %ACTION%==STOP (
    IF %CURRENT_STATUS%==STOPPED  (
       ECHO.                                            >>%logfile%
        ECHO Service %SERVICENAME% is currently stopped. >>%logfile%
      ECHO No further action is necessary              >>%logfile%
      ECHO.                                            >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StopService
    )
)

:StartService
ECHO Starting %SERVICENAME% on \\%SYSTEMNAME%  >>%logfile%
SC \\%SYSTEMNAME% start %SERVICENAME%          >>%logfile%
ECHO.                                          >>%logfile%
ECHO Confirming service has been started..     >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch

:StopService
ECHO Stopping %SERVICENAME% on \\%SYSTEMNAME%  >>%logfile%
SC \\%SYSTEMNAME% stop %SERVICENAME%           >>%logfile%
ECHO.                                          >>%logfile%
ECHO Confirming service has been stopped...    >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch


However, if I hard code the values for the SC command, it works fine.

Code: Select all

SC \\SERVER1 stop "SERVICE NAME"  


File and printer sharing on the remote computer has also been confirmed that it's enabled.

Could it be a Firewall issue?

Thanks!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: SC function failing when using variables

#2 Post by Squashman » 17 Nov 2016 20:30

What is the point of this code?

Code: Select all

IF %ACTION%==stop ( SET ACTION=STOP)^
   ELSE IF %ACTION%==STOP    ( SET ACTION=STOP)^
   ELSE IF %ACTION%==start   ( SET ACTION=START)^
   ELSE IF %ACTION%==START   ( SET ACTION=START)^
   ELSE IF %ACTION%==restart ( SET ACTION=RESTART)^
   ELSE IF %ACTION%==RESTART ( SET ACTION=RESTART)^
   ELSE GOTO Usage


What happens when I pass in StOp as the first argument of the script? Regardless of that I see no point in upper casing this string at all. The SC command is not dependent on the casing of the command. Also your script will fail if someone passes in the first argument "QUOTE" surrounded. If you really want it upper cased for the sake of seeing it that way in your log file then use the /I switch with the IF command and you would have it down to THREE lines of code.

Why are you doing this?

Code: Select all

IF %ERRORLEVEL%==0 IF NOT %ERRORLEVEL%==1

If the errorlevel is not 0 it will never reach the second IF. If the errorlevel is 0, errorlevel will never be 1 in the second IF.

Now this set of code really baffles me because I know you know how to use a FOR /F command with the TOKENS option!

Code: Select all

FOR /f "tokens=*" %%i IN ('SC \\%SYSTEMNAME% query %SERVICENAME% ^| FIND "STATE"') DO SET STATE=%%i

ECHO %STATE% | FINDSTR /C:"1" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=STOPPED
ECHO %STATE% | FINDSTR /C:"2" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=START_PENDING
ECHO %STATE% | FINDSTR /C:"3" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=STOP_PENDING
ECHO %STATE% | FINDSTR /C:"4" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=RUNNING
ECHO %STATE% | FINDSTR /C:"5" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=CONTINUE_PENDING
ECHO %STATE% | FINDSTR /C:"6" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=PAUSE_PENDING
ECHO %STATE% | FINDSTR /C:"7" >nul
IF %ERRORLEVEL%==0 SET CURRENT_STATUS=PAUSED


All this code could be replaced by one simple FOR command.

Code: Select all

for /f "tokens=3* delims= " %%G in ('SC \\%SYSTEMNAME% query %SERVICENAME% ^| FIND "STATE"') do SET CURRENT_STATUS==%%H

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

Re: SC function failing when using variables

#3 Post by SIMMS7400 » 18 Nov 2016 07:34

Sqush -

You're absolutely right - my code was disgusting.

Cleaned up:

Code: Select all

:EXEC_ACTION
PING -n 10 127.0.0.1>nul

IF [%1] == [] GOTO Usage
IF [%2] == [] GOTO Usage
IF [%3] == [] GOTO Usage

SET ACTION=%1
SET SERVICENAME=%2
SET SYSTEMNAME=%3

SET "str=%ACTION%"
FOR /f "usebackq delims=" %%I IN (`powershell "\"%str%\".toUpper()"`) DO SET "ACTION=%%~I"

SET STATE=
SET CURRENT_STATUS=
SET /A DEFAULT_DELAY=10
SET /A SLEEP_COUNT=0
SET /A RESTARTED=0
SET /A MAX_WAIT_PERIODS=5

ECHO Process Info:                                             >>%logfile%
ECHO.                                                                       >>%logfile%
ECHO Server Name  : %SYSTEMNAME%                                            >>%logfile%
ECHO Action       : %ACTION%                                                >>%logfile%
ECHO Service Name : %SERVICENAME%                                           >>%logfile%
ECHO.                                                                       >>%logfile%
ECHO Attempting to %ACTION% service %SERVICENAME% on computer %SYSTEMNAME%  >>%logfile%

SC \\%SYSTEMNAME% query %SERVICENAME% | FIND "FAILED 1060" >nul 2>&1
IF %ERRORLEVEL%==0 (
    ECHO.                                             >>%logfile%
    ECHO Failure! Service %SERVICENAME% is not valid! >>%logfile%
    EXIT /B 0
)
SC \\%SYSTEMNAME% query %SERVICENAME% | FIND "STATE" >nul 2>&1
IF %ERRORLEVEL%==1 (
    ECHO.                                                                                         >>%logfile%
    ECHO Failure! Server \\%SYSTEMNAME% or service %SERVICENAME% is not accessible or is offline! >>%logfile%
    EXIT /B 0
)

:Dispatch
FOR /f "tokens=4" %%S IN ('SC \\%SYSTEMNAME% query %SERVICENAME% ^| FIND "STATE"') DO SET CURRENT_STATUS=%%S

ECHO Current status of service is %CURRENT_STATUS% >>%logfile%

IF NOT "%CURRENT_STATUS%"=="RUNNING" IF NOT "%CURRENT_STATUS%"=="STOPPED" IF NOT "%CURRENT_STATUS%"=="PAUSED" (
    IF "%SLEEP_COUNT%"=="%MAX_WAIT_PERIODS%" (
        ECHO Service state won't change. Script exececution is canceled.>>%logfile%
        EXIT /B 0
    )
    ECHO Service State is changing, waiting %DEFAULT_DELAY% seconds...>>%logfile%
    PING -n 10 127.0.0.1>nul
    GOTO Dispatch
)

IF %ACTION%==START (
    IF %CURRENT_STATUS%==RUNNING (
       ECHO.                                              >>%logfile%
        ECHO Service %SERVICENAME% is currently running.   >>%logfile%
      ECHO No further action is necessary                >>%logfile%
      ECHO.                                              >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StartService
    )
) ELSE IF %ACTION%==RESTART (
    IF %CURRENT_STATUS%==RUNNING (
        IF %RESTARTED%==1 (
          ECHO.                                          >>%logfile%
            ECHO Service %SERVICENAME% has been restarted. >>%logfile%
         ECHO No further action is necessary            >>%logfile%
         ECHO.                                          >>%logfile%
            GOTO EndExit
        )
        SET /A SLEEP_COUNT=0
        GOTO StopService
    ) ELSE (
        SET /A RESTARTED=1
        GOTO StartService
    )
) ELSE IF %ACTION%==STOP (
    IF %CURRENT_STATUS%==STOPPED  (
       ECHO.                                            >>%logfile%
        ECHO Service %SERVICENAME% is currently stopped. >>%logfile%
      ECHO No further action is necessary              >>%logfile%
      ECHO.                                            >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StopService
    )
)

:StartService
ECHO Starting %SERVICENAME% on \\%SYSTEMNAME%  >>%logfile%
SC \\%SYSTEMNAME% start %SERVICENAME%          >>%logfile%
ECHO.                                          >>%logfile%
ECHO Confirming service has been started..     >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch

:StopService
ECHO Stopping %SERVICENAME% on \\%SYSTEMNAME%  >>%logfile%
SC \\%SYSTEMNAME% stop %SERVICENAME%           >>%logfile%
ECHO.                                          >>%logfile%
ECHO Confirming service has been stopped...    >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch

:Usage
>>%logfile%(
ECHO.
ECHO Warning! %ACTION% Process has been aborted.
ECHO Action, Service or Server could not be identified
ECHO.
)
ECHO This script can start/stop/restart a local or remote service, waiting for the service to stop/start ^(if necessary^).
ECHO.
ECHO Usage:
ECHO %0 ^<start^|stop^|restart^> ^<SERVICE^> [SYSTEM]
ECHO.
ECHO If any pareameter is missing, the script will default to the usage section and not execute
EXIT /B 0

:EndExit
GOTO :EOF


Still unsure as to why SC will not function properly when I use a variable in the command... hmmm

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: SC function failing when using variables

#4 Post by Squashman » 18 Nov 2016 11:56

SIMMS7400 wrote:Still unsure as to why SC will not function properly when I use a variable in the command... hmmm

Hard to say because we cannot see you physically execute the batch file with the command line arguments. As I alluded to in my previous comments, you still have some failure points in your code depending on how the batch file is executed with the command line arguments.

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: SC function failing when using variables

#5 Post by pieh-ejdsch » 18 Nov 2016 12:35

The RPC server is not available.
- this is the ERROR 1722

the programme gives you in every case a message. read the output to find out the kind of the error.
If you error values to read out used, take a CALL around in a routine to jump and to make there a suitable operation.
If a suitable subroutine does not exist, your batch will go on,
nevertheless and you can bring with the determination (what a miracle) of error a suitable output.

Squashman, Simms would like to limit the error only,
so that he can do an operation for this special error.
This if error and If not error thing is suitable of my opinion very badly for it.

Code: Select all

sc query Something
rem the Output of SC
if not errorlevel 1 goto :Script1
if errorlevel 1 call :%errorlevel%
if not errorlevel 1 set /a Error=0 &goto :EndErrors
if errorlevel 1 echo  This time no explanation was delivered for this error. &set /a Error=1 & goto :EndErrors

:EndErrors
Exit /b 1

:1722
echo The Server is not reached
echo something ...
Exit /b 0

:1060
echo Not Installed
 rem ExitCodes must be put only on 0 if previous programmes which displayed.
Exit /b 0

:EndErrors
 rem somthing does ....
Exit /b %Error%

:Script1
 rem here go on
 ...
 


Phil

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

Re: SC function failing when using variables

#6 Post by SIMMS7400 » 18 Nov 2016 13:54

I've been able to get it to work. For some reason, the SC command didn't like passing in a variable or using a parameters (i.e. %3). However, I decided to go with PsService since I use some other PsTools frequently. Here too PsService gave me some trouble.

PsService \\%variable% did not work
PsService \\%3 works fine

Why would that be?

I also cleaned up the code a touch more:

Code: Select all

::-- Call function to pass in ACTION ^| SERVICE ^| SERVER --::

CALL :EXEC_ACTION %1 %2 %3

ECHO ************************************************************************>>%logfile%
ECHO ALERT : Server %3 is done being processed - Exiting Server              >>%logfile%
ECHO ------------------------------------------------------------------------>>%logfile%                                                                       
ECHO.

CALL :ARCHIVE
EXIT /B

::::::::::::::::::::::::::::::
::-- Functions Below Here --::
::::::::::::::::::::::::::::::

:EXEC_ACTION
PING -n 10 127.0.0.1>nul

IF [%1] == [] GOTO Usage
IF [%2] == [] GOTO Usage
IF [%3] == [] GOTO Usage

SET ACTION=%~1
SET SERVICENAME=%2
SET SYSTEMNAME=%~3

SET "str=%ACTION%"
FOR /f "usebackq delims=" %%I IN (`powershell "\"%str%\".toUpper()"`) DO SET "ACTION=%%~I"

SET STATE=
SET CURRENT_STATUS=
SET /A DEFAULT_DELAY=10
SET /A SLEEP_COUNT=0
SET /A RESTARTED=0
SET /A MAX_WAIT_PERIODS=5


SET PUP=-u %PSUSer% -p %PSPass%
SET PSSERVICE=CALL %PSTOOLSPATH%PsService.exe %PUP%


ECHO ************************************************************************  >>%logfile%
ECHO Process Info  :                                                           >>%logfile%
ECHO ------------------------------------------------------------------------  >>%logfile%                                                                 
ECHO Server Name   : %SYSTEMNAME%                                              >>%logfile%
ECHO Action        : %ACTION%                                                  >>%logfile%
ECHO Service Name  : %SERVICENAME:"=%                                          >>%logfile%
ECHO.                                                                          >>%logfile%
ECHO Attempting to %ACTION% service %SERVICENAME% on computer %SYSTEMNAME%     >>%logfile%
ECHO.                                                                          >>%logfile%

%PSSERVICE% \\%3 query %SERVICENAME% | FIND "FAILED 1060" >nul 2>&1
IF %ERRORLEVEL%==0 (
    ECHO.                                             >>%logfile%
    ECHO Failure! Service %SERVICENAME% is not valid! >>%logfile%
   ECHO.                                             >>%logfile%
    EXIT /B 0
)
%PSSERVICE% \\%3 query %SERVICENAME% | FIND "STATE" >nul 2>&1
IF %ERRORLEVEL%==1 (
    ECHO.                                                                               >>%logfile%
    ECHO Failure! Server \\%3 or service %SERVICENAME% is not accessible or is offline! >>%logfile%
   ECHO.                                                                               >>%logfile%
    EXIT /B 0
)

:Dispatch
FOR /f "tokens=4" %%S IN ('%PSSERVICE% \\%3 query %SERVICENAME% ^| FIND "STATE"') DO SET CURRENT_STATUS=%%S

ECHO Current State : Service is %CURRENT_STATUS% >>%logfile%

IF NOT "%CURRENT_STATUS%"=="RUNNING" IF NOT "%CURRENT_STATUS%"=="STOPPED" IF NOT "%CURRENT_STATUS%"=="PAUSED" (
    IF "%SLEEP_COUNT%"=="%MAX_WAIT_PERIODS%" (
       ECHO.                                                           >>%logfile%
        ECHO Service state won't change. Script exececution is canceled.>>%logfile%
      ECHO.                                                           >>%logfile%
        EXIT /B 0
    )
   ECHO.                                                             >>%logfile%
    ECHO Service State is changing, waiting %DEFAULT_DELAY% seconds...>>%logfile%
   ECHO.                                                             >>%logfile%
    PING -n 10 127.0.0.1>nul
   SET /A SLEEP_COUNT+=1
   GOTO Dispatch

)

IF %ACTION%==START (
    IF %CURRENT_STATUS%==RUNNING (
        ECHO.                                                  >>%logfile%
        ECHO Warning! Service %SERVICENAME% is already running >>%logfile%
      ECHO.                                                  >>%logfile%
        ECHO No further processing required                    >>%logfile%
        ECHO.                                                  >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StartService
    )
) ELSE IF %ACTION%==RESTART (
    IF %CURRENT_STATUS%==RUNNING (
        IF %RESTARTED%==1 (
         ECHO.                                                           >>%logfile%
         ECHO Warning! Service %SERVICENAME% has been already restarted  >>%logfile%
         ECHO.                                                           >>%logfile%
            ECHO No further processing required                             >>%logfile%
         ECHO.                                                           >>%logfile%
            GOTO EndExit
        )
        SET /A SLEEP_COUNT=0
        GOTO StopService
    ) ELSE (
        SET /A RESTARTED=1
        GOTO StartService
    )
) ELSE IF %ACTION%==STOP (
    IF %CURRENT_STATUS%==STOPPED  (
      ECHO.                                                           >>%logfile%
        ECHO Warning! Service %SERVICENAME% is already stopped.         >>%logfile%
      ECHO.                                                           >>%logfile%
      ECHO No further processing required                             >>%logfile%
      ECHO.                                                           >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StopService
    )
)

:StartService
ECHO.                                          >>%logfile%
ECHO Starting %SERVICENAME% on \\%SYSTEMNAME%  >>%logfile%
%PSSERVICE% \\%3 start %SERVICENAME%           >>%logfile%
ECHO.                                          >>%logfile%
ECHO Verifying service has been started...     >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch

:StopService
ECHO.                                          >>%logfile%
ECHO Stopping %SERVICENAME% on \\%SYSTEMNAME%  >>%logfile%
%PSSERVICE% \\%3 stop %SERVICENAME%            >>%logfile%
ECHO.                                          >>%logfile%
ECHO Verifying service has been started...     >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch

:Usage

>>%logfile%(
ECHO.
ECHO Warning! %ACTION% Process has been aborted.
ECHO Action, Service or Server could not be identified
ECHO.
)
ECHO This script can start/stop/restart a local or remote service, waiting for the service to stop/start ^(if necessary^).
ECHO.
ECHO Usage:
ECHO %0 ^<start^|stop^|restart^> ^<SERVICE^> [SYSTEM]
ECHO.
ECHO If any pareameter is missing, the script will default to the usage section and not execute
EXIT /B 0

:EndExit
GOTO :EOF

:ARCHIVE:
::-- Archive Log Files Based on Date --::
       
FOR %%f IN (%MAINPATH%%LOGPATH%*) DO (
   IF NOT EXIST "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" (
      MKDIR "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
   )
MOVE %%f "%MAINPATH%%LOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)

::-- Archive Error Files Based on Date --::

FOR %%f IN (%MAINPATH%%ERRORPATH%*) DO (
   IF NOT EXIST "%MAINPATH%%ERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" (
      MKDIR "%MAINPATH%%ERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
   )
MOVE %%f "%MAINPATH%%ERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
)

GOTO :EOF



Also, there is a service that PsService and SC both think is down however when viewing the service, it says it's up. Therefore, when I run my PsService \\Server start TroubleService , it claims it's already running. And do to that, it just spools and spools because for some reason, it's not setting my "counter" variable to cease trying after 5 tries.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: SC function failing when using variables

#7 Post by Squashman » 18 Nov 2016 14:47

You still have not proven anything nor provided a verifiable example of your code not working. We can't see how you are executing the script nor see the output.
http://stackoverflow.com/help/mcve

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: SC function failing when using variables

#8 Post by Squashman » 18 Nov 2016 15:32

In its simplest form this is your code to start and stop services.

Code: Select all

@echo off
setlocal
SET "ACTION=%~1"
SET "SERVICENAME=%~2"
SET "SYSTEMNAME=%~3"

sc \\%SYSTEMNAME% %ACTION% %SERVICENAME%
endlocal


Query, Stop, Query, Start, Query the service using the environmental variables.

Code: Select all


E:\SC>scntl.bat query wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>scntl.bat stop wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>scntl.bat query wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>scntl.bat start wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 5668
        FLAGS              :

E:\SC>scntl.bat query wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>


Now I am going to change the code to use the command line arguments only.

Code: Select all

@echo off
setlocal
sc \\%~3 %~1 %~2
endlocal


Query, Stop, Query, Start, Query the service using the command line arguments.

Code: Select all

E:\SC>scntl.bat query wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>scntl.bat stop wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>scntl.bat query wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>scntl.bat start wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 3712
        FLAGS              :

E:\SC>scntl.bat query wdpostman MYSERVER

SERVICE_NAME: wdpostman
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

E:\SC>


You can even put quotes around your command line arguments and around the variables in the SC command and it will still work.

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

Re: SC function failing when using variables

#9 Post by SIMMS7400 » 19 Nov 2016 06:31

Thank you for your help Squash! For some reason, SC still wont work with regular variable - it will only work for command argurments.

However, I've still reverted to using PsService. Here's a sample process to STOP EPM Services. I've been able to clean up my scripts nicely. Althought, I'm sure they still need. They are behaving as expected now though.

Stop_EPM_Services.cmd

Code: Select all

::-- Set Working Directory as Script Path --::

cd /d %~dp0

::-- Call Environment File --::

call _env.cmd

::-- Set EPM Services process specific variables --::

SET PLOGPATH=EPM_Services_Logs\
SET PERRORPATH=EPM_Services_Errors\
SET ACTION=start

SET RPT_SRVR=DIDRHYPRPT03VW
SET ESSB_SRVR=DIDRHYPESS03VW

echo ********************************************************
echo %ACTION:s=S% EPM Services on Reporting                           
echo ********************************************************

FOR %%S IN (
 
 "OracleProcessManager_ohsInstance4262192120"^
 "HyS9FoundationServices"^
 "HyS9RAFramework"^
 "HyS9RAFrameworkAgent"^
 "HyS9FRReports"^
 "HyS9FRPrint"^
 "HyS9WebAnalysis"^
 "Hyperion RMI Registry"^
 "HyS9Planning"
 
 ) DO (

CALL SafeStopStartRestart.cmd %ACTION% %%S %RPT_SRVR% %PLOGPATH% %PERRORPATH%

)

echo ********************************************************
echo %ACTION:s=S% EPM Services on Essbase Server                              
echo ********************************************************

FOR %%S IN (
 
 "opmn_EPM_epmsystem2"^
 "OracleProcessManager_ohsInstance1728229954"^
 "HyS9aps"^
 "HyS9eas"
 
 ) DO (

CALL SafeStopStartRestart.cmd %ACTION% %%S %RPT_SRVR% %PLOGPATH% %PERRORPATH%

)

echo ********************************************************
echo End of Main Script Processing                               
echo ********************************************************
echo ********************************************************
echo Performing Post-Execution Tasks                              
echo ********************************************************

::-- Merge all script output into 1 file --::

SET OUTPUT=%MAINPATH%%LOGPATH%%PLOGPATH%All_Started_EPM_Services.log

FOR %%O IN (%MAINPATH%%LOGPATH%%PLOGPATH%*) DO TYPE "%%O" >> %OUTPUT%

::-- Call function to archive output files in YYYY_MMDD subdirectory --::

CALL :ARCHIVE

::--Exit entire batch session --::
EXIT /B

::::::::::::::::::::::::::::::
::-- Functions Below Here --::
::::::::::::::::::::::::::::::

:ARCHIVE:
::-- Archive Log Files Based on Date --::
       
FOR %%f IN (%MAINPATH%%LOGPATH%%PLOGPATH%*) DO (
   IF NOT EXIST "%MAINPATH%%LOGPATH%%PLOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" (
      MKDIR "%MAINPATH%%LOGPATH%%PLOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
   )
MOVE %%f "%MAINPATH%%LOGPATH%%PLOGPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%\%%~nf_%timestamp%%%~xf"
)

::-- Archive Error Files Based on Date --::

FOR %%f IN (%MAINPATH%%ERRORPATH%%PERRORPATH%*) DO (
   IF NOT EXIST "%MAINPATH%%ERRORPATH%%PERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%" (
      MKDIR "%MAINPATH%%ERRORPATH%%PERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%"
   )
MOVE %%f "%MAINPATH%%ERRORPATH%%PERRORPATH%%date:~-4,4%_%date:~-10,2%%date:~-7,2%\%%~nf_%timestamp%%%~xf"
)

GOTO :EOF


Now, this is script is called by ALL my Stop/Starts scripts:

SafeStopStartRestart.cmd

Code: Select all

::-- Set Working Directory as Script Path --::

cd /d %~dp0

::-- Call Environment File --::

call _env.cmd

::-- Set Main Intrapath Variables --::
::-- Set Process in variables below i.e. EPMA_Logs\

SET PLOGPATH=%4
SET PERRORPATH=%5

SET intrapath=%MAINPATH%%LOGPATH%%PLOGPATH%
SET errorintrapath=%MAINPATH%%ERRORPATH%%PERRORPATH%

IF NOT EXIST %intrapath%      MKDIR %intrapath%
IF NOT EXIST %errorintrapath% MKDIR %errorintrapath%

::-- Prepare Main Log and Error Files  --::

FOR /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set timestamp=%%a%%b)
FOR /f "tokens=* delims= " %%c in ("%timestamp%") do (set timestamp=%%c)

SET logfile=%intrapath%%1_%2_%date:~-4,4%%date:~-10,2%%date:~-7,2%.log
SET errorfile=%errorintrapath%%1_%2_%date:~-4,4%%date:~-10,2%%date:~-7,2%.log

IF EXIST %logfile% DEL %logfile%
IF EXIST %errorfile% DEL %errorfile%

::-- Call function to pass in ACTION ^| SERVICE ^| SERVER --::

CALL :EXEC_ACTION %1 %2 %3

::-- Return to main script to process more commands or exit session --::

EXIT /B

::::::::::::::::::::::::::::::
::-- Functions Below Here --::
::::::::::::::::::::::::::::::

:EXEC_ACTION
PING -n 5 127.0.0.1>nul

::-- Ensure command line argurement exist before processing --%
IF [%1] == [] GOTO Usage
IF [%2] == [] GOTO Usage
IF [%3] == [] GOTO Usage

::-- Set command line arguements to variable for easier reading --::
SET ACTION=%~1
SET SERVICENAME=%2
SET SYSTEMNAME=%~3

::-- Uppercase action values --::
SET "str=%ACTION%"
FOR /f "usebackq delims=" %%I IN (`powershell "\"%str%\".toUpper()"`) DO SET "ACTION=%%~I"

::-- Set Main Script Variables --::
SET STATE=
SET CURRENT_STATUS=
SET /A DEFAULT_DELAY=10
SET /A SLEEP_COUNT=0
SET /A RESTARTED=0
SET /A MAX_WAIT_PERIODS=5

::-- Used to shorten command line --::
SET PUP=-u %PSUSer% -p %PSPass%
SET PSSERVICE=PsService.exe %PUP%

ECHO ************************************************************************  >>%logfile%
ECHO Process Info  :                                                           >>%logfile%
ECHO ------------------------------------------------------------------------  >>%logfile%                                                                 
ECHO Server Name   : %SYSTEMNAME%                                              >>%logfile%
ECHO Action        : %ACTION%                                                  >>%logfile%
ECHO Service Name  : %SERVICENAME:"=%                                          >>%logfile%
ECHO.                                                                          >>%logfile%
ECHO Attempting to %ACTION% service %SERVICENAME% on computer %SYSTEMNAME%     >>%logfile%
ECHO.                                                                          >>%logfile%

::-- Ensure Service and^/or Server is valid, accessiable, and not offline --::
%PSSERVICE% \\%3 query %SERVICENAME% | FIND "FAILED 1060" >nul 2>&1
IF %ERRORLEVEL%==0 (
    ECHO.                                             >>%logfile%
    ECHO Failure! Service %SERVICENAME% is not valid! >>%logfile%
   ECHO.                                             >>%logfile%
    GOTO EndExit
)
%PSSERVICE% \\%3 query %SERVICENAME% | FIND "STATE" >nul 2>&1
IF %ERRORLEVEL%==1 (
    ECHO.                                                                               >>%logfile%
    ECHO Failure! Server \\%3 or service %SERVICENAME% is not accessible or is offline! >>%logfile%
   ECHO.                                                                               >>%logfile%
    GOTO EndExit
)

:Dispatch

::-- Parse output of command and set STATE as a variable for script processing --::
FOR /f "tokens=4" %%S IN ('%PSSERVICE% \\%3 query %SERVICENAME% ^| FIND "STATE"') DO SET CURRENT_STATUS=%%S

ECHO Current State : Service is %CURRENT_STATUS% >>%logfile%

::-- Perform required checks and balances after service has been stopped or started --::
IF NOT "%CURRENT_STATUS%"=="RUNNING" IF NOT "%CURRENT_STATUS%"=="STOPPED" IF NOT "%CURRENT_STATUS%"=="PAUSED" (
    IF "%SLEEP_COUNT%"=="%MAX_WAIT_PERIODS%" (
       ECHO.                                                           >>%logfile%
        ECHO Service state won't change. Script exececution is canceled.>>%logfile%
      ECHO.                                                           >>%logfile%
        GOTO EndExit
    )
   ECHO.                                                             >>%logfile%
    ECHO Service State is changing, waiting %DEFAULT_DELAY% seconds...>>%logfile%
   ECHO.                                                             >>%logfile%
    PING -n 10 127.0.0.1>nul
   SET /A SLEEP_COUNT+=1
   GOTO Dispatch

)

IF %ACTION%==START (
    IF %CURRENT_STATUS%==RUNNING (
        ECHO.                                                  >>%logfile%
        ECHO Warning! Service %SERVICENAME% is already running >>%logfile%
      ECHO.                                                  >>%logfile%
        ECHO No further processing required                    >>%logfile%
        ECHO.                                                  >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StartService
    )
) ELSE IF %ACTION%==RESTART (
    IF %CURRENT_STATUS%==RUNNING (
        IF %RESTARTED%==1 (
         ECHO.                                                           >>%logfile%
         ECHO Warning! Service %SERVICENAME% has been already restarted  >>%logfile%
         ECHO.                                                           >>%logfile%
            ECHO No further processing required                             >>%logfile%
         ECHO.                                                           >>%logfile%
            GOTO EndExit
        )
        SET /A SLEEP_COUNT=0
        GOTO StopService
    ) ELSE (
        SET /A RESTARTED=1
        GOTO StartService
    )
) ELSE IF %ACTION%==STOP (
    IF %CURRENT_STATUS%==STOPPED  (
      ECHO.                                                           >>%logfile%
        ECHO Warning! Service %SERVICENAME% is already stopped.         >>%logfile%
      ECHO.                                                           >>%logfile%
      ECHO No further processing required                             >>%logfile%
      ECHO.                                                           >>%logfile%
        GOTO EndExit
    ) ELSE (
        GOTO StopService
    )
)

:StartService

::-- Ensure conlficts are captured and addressed appropriately --::
::-- For instance, a service could have a status of STOPPED and an action of START --::
::-- When SC or PsService goes to start it, it fails because infact it's already started --::

SET WARNING=
SET FND_STRNG=Error %1ing BITS on \\%3:

FOR /f "tokens=* delims=" %%G IN (
   '%PSSERVICE% \\%3 start %SERVICENAME% ^|findstr /i /R "%FND_STRNG%"'
   ) DO IF %errorlevel% NEQ 0 (
         ECHO.                                     >>%logfile%
         ECHO Verifying service has been started...>>%logfile%
         ECHO.                                     >>%logfile%
         SET SLEEP_COUNT=0
         GOTO Dispatch
      ) ELSE (
            ECHO.                                          >>%logfile%
            ECHO Warning! A service conflicts exists:      >>%logfile%
            ECHO.                                          >>%logfile%
            ECHO The action was to %ACTION%                >>%logfile%
            ECHO %~2 returned a %CURRENT_STATUS% status    >>%logfile%
            ECHO PsService = FAILED because it was STARTED >>%logfile%
            ECHO.                                          >>%logfile%
            ECHO Please verify the false status setting    >>%logfile%
            ECHO.                                          >>%logfile%
            GOTO EndExit
         )
   
:StopService
ECHO.                                          >>%logfile%
ECHO Stopping %SERVICENAME% on \\%SYSTEMNAME%  >>%logfile%
%PSSERVICE% \\%3 stop %SERVICENAME%            >>%logfile%
ECHO.                                          >>%logfile%
ECHO Verifying service has been stopped...     >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch


:Usage

>>%logfile%(

ECHO.
ECHO Warning! EPM Services processing has been aborted
ECHO.
ECHO %1,%2, or %3 has been provided in an incorrect format
ECHO.
ECHO See usage below:
ECHO.
ECHO This script can start/stop/restart a local or remote service, waiting for the service to stop/start ^(if necessary^).
ECHO.
ECHO Usage:
ECHO *_EPM_Services.cmd ^<start^|stop^|restart^> ^<SERVICE^> ^[SYSTEM^]
ECHO.
)
GOTO EndExit


:EndExit
ECHO ************************************************************************>>%logfile%
ECHO ALERT : Server %3 is done being processed - Exiting Server              >>%logfile%
ECHO ------------------------------------------------------------------------>>%logfile%                                                                       
ECHO.
GOTO :EOF



You'll in the :StartService label section (near the bottom), I have some additional syntax:


Code: Select all

:StartService

::-- Ensure conlficts are captured and addressed appropriately --::
::-- For instance, a service could have a status of STOPPED and an action of START --::
::-- When SC or PsService goes to start it, it fails because infact it's already started --::

SET WARNING=
SET FND_STRNG=Error %1ing BITS on \\%3:

FOR /f "tokens=* delims=" %%G IN (
   '%PSSERVICE% \\%3 start %SERVICENAME% ^|findstr /i /R "%FND_STRNG%"'
   ) DO IF %errorlevel% NEQ 0 (
         ECHO.                                     >>%logfile%
         ECHO Verifying service has been started...>>%logfile%
         ECHO.                                     >>%logfile%
         SET SLEEP_COUNT=0
         GOTO Dispatch
      ) ELSE (
            ECHO.                                          >>%logfile%
            ECHO Warning! A service conflicts exists:      >>%logfile%
            ECHO.                                          >>%logfile%
            ECHO The action was to %ACTION%                >>%logfile%
            ECHO %~2 returned a %CURRENT_STATUS% status    >>%logfile%
            ECHO PsService = FAILED because it was STARTED >>%logfile%
            ECHO.                                          >>%logfile%
            ECHO Please verify the false status setting    >>%logfile%
            ECHO.                                          >>%logfile%
            GOTO EndExit
         )


For some reason, my code tags a particular service as STOPPED, when in reality its started. Therefore, when the action of the script is to START, PsService will start but fail. Then, when it goes back to the dispatch section it wasn't able to branch because it didn't meet a condition. Therefore, I handled int he :StartService section. When I tried to add a condition section above it where the other's are, it would never catch for some reason. It's working now but not sure its best practice.

Thanks!

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

Re: SC function failing when using variables

#10 Post by SIMMS7400 » 19 Nov 2016 07:31

So instead of trying to capture the conflict within the :StartService section, I added it above where it should be. But as I said earlier, for some reason it's not catching:

Code: Select all

IF "%CURRENT_STATUS%"=="STOPPED" (
    IF %ACTION%==STOP IF %WARN%==TRUE (
       ECHO.                                                           >>%logfile%
        ECHO Service state won't change. Script exececution is canceled.>>%logfile%
      ECHO.                                                           >>%logfile%
        PAUSE
    )
   ECHO.                                                             >>%logfile%
    ECHO Service State is changing, waiting %DEFAULT_DELAY% seconds...>>%logfile%
   ECHO.                                                             >>%logfile%
   PAUSE
    PING -n 10 127.0.0.1>nul
   SET /A SLEEP_COUNT+=1
   GOTO Dispatch

)
:StartService

SET FND_STRNG=Error %1ing BITS on \\%3:

FOR /f "tokens=* delims=" %%G IN (
   '%PSSERVICE% \\%3 start %SERVICENAME% ^|findstr /i /R "%FND_STRNG%"'
   ) DO IF %errorlevel%==0 SET WARN=TRUE

ECHO.                                          >>%logfile%
ECHO Verifying service has been stopped...     >>%logfile%
ECHO.                                          >>%logfile%
SET SLEEP_COUNT=0
GOTO Dispatch


It just keeps looping through Dispatch -> StartService indefinitely.

If you want to test, pick a service, add to the calling script (Start_EPM_Services) (remove the irrelevant other sections) then change this line:

Code: Select all

FOR /f "tokens=4" %%S IN ('%PSSERVICE% \\%3 query %SERVICENAME% ^| FIND "STATE"') DO SET CURRENT_STATUS=%%S


to this

Code: Select all

FOR /f "tokens=4" %%S IN ('%PSSERVICE% \\%3 query %SERVICENAME% ^| FIND "STATE"') DO SET CURRENT_STATUS=STOPPED



Thanks!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: SC function failing when using variables

#11 Post by Squashman » 19 Nov 2016 12:57

SIMMS7400 wrote:Thank you for your help Squash! For some reason, SC still wont work with regular variable - it will only work for command argurments.


So you tested my EXACT code and it still did not work?

As I said before you have not provided a verifiable example of it not working.

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

Re: SC function failing when using variables

#12 Post by SIMMS7400 » 20 Nov 2016 19:58

Hi Squash -

SC still will not work on my computer when passing in arguments. Therefore, I've resorted to PsService and it's working as it should with command line arguments.

Thank you for your help!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: SC function failing when using variables

#13 Post by Squashman » 20 Nov 2016 20:27

SIMMS7400 wrote:Hi Squash -

SC still will not work on my computer when passing in arguments. Therefore, I've resorted to PsService and it's working as it should with command line arguments.

Thank you for your help!

You must have the same virus the rest of my family has on their computers. It's the virus that only makes their computers malfunction when I am not the person between the keyboard and chair.

Post Reply