if statement - Open Specific RDP connection using "IF" or "GOTO" in Batch file -


i have tried multiple things , fails. having log in various terminal service rdp , want able control them .bat. following latest failed attempt. when run it, opens both connections.

@echo off  rem sets parameter network id. set /p server = "server> " set user = "user"  set pass = "password"   if "%server%" =="233" (   goto 233 ) else if "%server%" =="234" (   goto 234 )  rem rdp connection server 234 :234  cmdkey /generic:termsrv/rdc234 /user:%user% /pass:%pass%   mstsc /v:rdc234  rem rdp connection server 233 :233  cmdkey /generic:termsrv/rdc233 /user:%user% /pass:%pass%   mstsc /v:rdc233  pause 

@echo off  rem sets parameter network id. set /p server="server> " set "user=user"  set "pass=password"   if "%server%"=="233" goto valid if "%server%"=="234" goto valid echo invalid server "%server%" specified goto end  :valid     rem rdp connection valid server cmdkey /generic:termsrv/rdc%server% /user:%user% /pass:%pass%   mstsc /v:rdc%server%  :end  pause 

it's not clear code whether you're inputting values user , pass (which should follow server pattern) or setting user , pass values you've suppressed.

either way, spaces on each side of = significant, code sets "userspace" not "user" instance.

using quotes in manner have shown ensure value assigned not include trailing spaces present on line. posted originally, value assigned include quotes.

it's quite illogical use if condition goto else... if condition false, next line executed, so

if condition goto ... if anothercondition goto ... rem here if neither first nor second condition. 

would seem far clearer.

since insructions executed in :233 , :244 identical, bar server value, can use %server% in manner shown butt-up value of fixed-text prefix rdc.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -