I have to update the windows service.exe and related dll by using console on remote computer.
I tried
net start <servicename>
but it not allowed to query or issue command on the remote computer.
then I tried sc & PsService from SysInternals.
sc \\<ServerName> stop <ServiceName>
PsService \\<ServerName> stop <ServiceName>
the problem is both of them issue stop command and returned the control but I want to sure that service is stopped completely so that
I can update files.
so
I write the following code to do that.
@echo off
set serverName=server1
set serviceName=ervice1
sc \\%serverName% stop %serviceName%
call:check %serviceName%
echo the service %serviceName% on servcer:%serverName% is :stopped
goto:eof
:check
echo serverName: %serverName%
echo seriveName %~1
sc \\%serverName% query %~1 | find /I "State" | find /I "STOPPED"
echo %ERRORLEVEL%
IF ERRORLEVEL 1 (
goto:check %~1
) else (
goto:eof
)