Script without put ran as administrator leaves no file [closed]
Try the following code snippet:
@ECHO OFF
SETLOCAL EnableExtensions
SC QUERY state= all | FINDSTR "Fax"
REM alternatively: SC QUERY Fax | FINDSTR "Fax"
IF ERRORLEVEL 2 (
REM Findstr: Wrong syntax
) else (
IF ERRORLEVEL 1 (
REM "Fax": A match not found
) else (
REM "Fax": A match is found in at least one line of the query
>> "%~dp0log.txt" SC CONFIG Fax START= DISABLED
)
)
Explanation:
- note that
SC QUERY
without any option enumerates only running services (defaultstate= active
), seeSC /?
; - check
IF ERRORLEVEL number
in descending order asERRORLEVEL number
specifies a true condition if the last program run returned an exit code equal to or greater than the number specified (i.e.IF ERRORLEVEL 0
is always valid), seeIF /?
; -
%~dp0
expands%0
to a drive letter and path (incl. trailing backslash), seecall /?
. Note that%~dp0
will return the Drive and Path to the batch script, see Links relative to the Batch Script) -
>> "%~dp0log.txt" SC …
- see redirection.