I try to write a small batch file that will react differently depending on a parameter. Unfortunately the "if" statement whch does not seem to work as expected in the form of 2 strings:
@echo will close if "% 1" == "" Goto use echo " Parameter:% 1 "IF / I"% 1 "==" START "{echo" Why the hell is% 1 == starting? " SET parameter = geto start: and if / i "% 1" == "pause" {SET parameter = stop goto: execute} echo "parameter% 1% invalid": use echo "synapsis:" echo "switchservices Start "Stop" Goto: EOF: SET SERVICEMENME = DNSSH SET file name = Dnscache.exe Call:% parameter% _Service goto: EOF: stop_Service Echo ... stop service ... net stop% servicename% if (ERRORLEVEL GTR 0) Call: Kill_Service sc config% servicename% start = disabled service closed. Exit / b: kill_Service taskkill / f / im% filename% exit / b: Start_Service Echo ... Starting Service ... sc config% servicename% start = auto net start% servicename% exit / b: EOF
The result is:
< Pre> c: users kollenba documents temp> KapschServices.cmd xxx "Parameter: xxx" "Why the hell is XXX == Start? "... the service is starting ... [SC] ChangeServiceConfig ERFOLG Der Enfford Denst Wurdes Rate Gateartate.
I do not understand why the condition
If / I "% 1" == "Start"
does any sign that does not work as expected?
Precondition: Batch File "Net Start "command must be executed with administrator permissions to allow. Used OS: Windows 7
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.