How to build a check when scm list credentials doesn't return any message and ErrorLevel=0 when not logged in?
Hi all,
I am using RTC CLI 4.0.2 on Win7 64-bit.
You can store (l)scm login credentials with argument '-c' in the command: scm login -r %SrvURI% -u %UserID% -P %UserPwd% -n %SrvURInickname% -c.
When I want a script to check the (l)scm login credentials, you can use command: scm list credentials.
If login credentials are available the return says:
%SrvURI%, %UserID%, %SrvURInickname%, <No certificate>, <No smartcard>, <Password stored>
Enough return values to check and %ERRORLEVEL% is 0, which is as expected.
However, when there are -no- credentials stored, i.e. there's no rtc login, the command 'scm list credentials' doesn't return -any- value and %ERRORLEVEL% is 0.
When I do a: FOR /F %%i IN ('scm list credentials') DO echo Value 1=%%i, I get nothing returned, not even "Value i="
How can I create a check in my batch file to see if a login is available?
Any pointers?
One answer
You can set a variable before the for loop (something like credExists=0) and then inside the for loop set credExists=1. Check for the value of the variable 'credExists' to determine if there was any credential information.
Comments
This workaround works fine, but the command still doesn't return a proper error code.
Probably there could have been a return value indicating that there is no login credentials but currently it is working as designed.
By the way, you could also try using the --json option to output it in json format. In that case you could check if the array is empty.