Jump to content

Using SC (Service Controller) command in a batch file


Comos

Recommended Posts

Hi All,

Im using a little batch file for configuring a remote shell service for a specific account.The only problem is,that the password when wanted to leave as default by the batch (Admin) is somehow not set by the service and I have to do it manually then.

Here is the code:

echo Now configuring the Remote Shell Service

echo Stopping the Service
sc stop RshSvc

echo Enter the Password for Admin account or ENTER to leave it as Admin
set /p adminpwd=:
if "%adminpwd%"=="" set pwd=Admin
if %errorlevel%==0 set pwd=%adminpwd%

sc config RshSvc type= own obj= %computername%\Admin password= %pwd%

echo Starting the service
sc start RshSvc

Any idea where's the bug?

Link to comment
Share on other sites


Any idea where's the bug?

Cannot say if it is a bug, but usually with this kind of batches it is better to use "negative logic".

@ECHO OFFSET Defaultpwd=Adminecho Now configuring the Remote Shell Serviceecho Stopping the Servicesc stop RshSvcecho Enter the Password for Admin account or ENTER to leave the default oneset /p adminpwd=Type password or press [ENTER] to leave the Default one.IF NOT DEFINED adminpwd SET adminpwd=%Defaultpwd%sc config RshSvc type= own obj= %computername%\Admin password= %adminpwd%echo Starting the servicesc start RshSvc

jaclaz

Link to comment
Share on other sites

What happens if you change it like this:

@echo offsetlocalecho=Now configuring the Remote Shell Serviceecho=Stopping the Servicesc stop RshSvcecho=Enter the Password for Admin account or ENTER to leave it as Adminset /p "adminpwd = "if not defined adminpwd (set adminpwd=Admin)sc config RshSvc obj= "Admin" password= "%adminpwd%"echo=Starting the servicesc start RshSvc
Link to comment
Share on other sites

The %errorlevel% is of the previews "set pwd=Admin" command? Which is supposed to be the default password? Maybe the correct syntax would be "if "%adminpwd%"=="" set %adminpwd%=Admin"? I think that as it is writen if %adminpwd% is null it remains so and pwd becomes null also.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...