Set an environnent variable from a label
10/06/2017 539 views
Is it possible to set an environment variable from a label? Our classroom are tag like this ens.<city>.<building>.<room> and it could be useful for us to set an environment variable like %KACE_LABEL%. Does any of you ever did it and how ?
Answer Chosen by the Author
Please log in to answer
I finaly found how to did it.
- First you need a mysql client. I took this one https://dev.mysql.com/downloads/file/?id=471341
- Extract it take copy the mysql.exe and mysql_config_editor.exe to your working directory.
- With mysql_config_editor.exe create a crypted login file :
mysql_config_editor.exe set --login-path=k1000 --host=k1000.kbox.com --user=R1 --password
Now you have you credentials in %APPDATA%\MySQL\.mylogin.cnf
- copy the .mylogin.cnf file in your working directory
- now you can run this batch script :
:: setting variables
:: Building the query
:: you can change the "Where" part to adapt it to your needs
ECHO SELECT LABEL.NAME FROM LABEL LEFT JOIN MACHINE_LABEL_JT ON LABEL.ID = MACHINE_LABEL_JT.LABEL_ID LEFT JOIN MACHINE ON MACHINE_LABEL_JT.MACHINE_ID = MACHINE.ID WHERE MACHINE.NAME = '%COMPUTERNAME%' AND LABEL.NAME like '%%.%%.%%.%%' AND LABEL.NAME NOT LIKE '%%all'; > %SQL%
:: Copying the credential file to the current user roaming profile
copy "%~dp0.mylogin.cnf" "%APPDATA%\Mysql"
:: running the query and store the label in %TEMP%\LABEL.TXT
%MY% --login-path=k1000 -s -D ORG1 < %SQL% > %TEMP%\LABEL.TXT
:: Setting the environement variable
SETX KACE_LABEL /F %TEMP%\LABEL.TXT /A 0,0 /M
:: deletion of the credential file
rmdir /q /s "%APPDATA%\Mysql"
That's it !
Answered 10/13/2017 by: gwir