How to pass the parameters and encrypt the password

June 25, 2013 at 11:19:14
Specs: Windows XP
Hello All
My script calls mutiple batch xml files in single .bat file script in command line while executing giving the input XXX.bat foldername userid and password(encrypted) servername then only it has to execute all the batch xml files ((script.bat set UN pwd server) in one line then hit enter it will execute the batch xml files) something like this.....

1) I removed the below lines to make it work but its not working as expected.
when I ran the script in command line giving input

script.bat set UN pwd server---in one line it is not launching the xml files when I just give the XXX.bat file name it is executing.could you please let me know how to achieve this? Is there any param file for windows batch script to encrypt the password

echo Enter Username and Password and server

set /p user_id=Enter UserID:
set /p password=Enter Password:
set /p server=Enter server:

if /i %user_id%==admin if /i %password%==password if /i %server%==server goto admin1


2) For below these lines I need to pass parameters like %1 %2 %3 %4 could you please let me know how to pass these parameters and use these in my script??

SET "xml_pass=c:\Today\xml-pass.log"

SET "xml_error=c:\Today\xml-error.log"

SET "xml_dir=c:\Today\set"

SET "user_Id= admin"


--------------

Modified Script (please let me know if anything to be modified)

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "xml_pass=c:\Today\xml-pass.log"
SET "xml_error=c:\Today\xml-error.log"
SET "xml_dir=c:\Today\set"

For /f "tokens=1 delims=," %%i in (%Today%) do set user_id=%%i
For /f "tokens=2 delims=," %%j in (%Today%) do set password=%%j
For /f "tokens=3 delims=," %%k in (%Today%) do set server=%%k
For %%z in ("%xml_dir%\*.xml") do (

call scheduleBatch "%%z" %user_id% %password% %server%


echo %errorlevel%

if %errorlevel% == 1 >> %xml_error% echo "%%z" failed
if not %errorlevel% == 1 >> %xml_pass% echo "%%z" succeeded (Do you think I need to modify the error handling part too)

)

Please help me out.


See More: How to pass the parameters and encrypt the password

Report •


#1
June 25, 2013 at 13:28:27
I'm not sure, your post is very confusing to me, but I'll try. To pass parameters inside a batch, you must use "CAll" instead of "GOTO":
call admin %user_id% %password% %server%
goto :eof

:admin
echo user_id: %1
echo passwd: %2
echo server: %3
goto :eof

And yes, I would handle errors differently:
if %errorlevel% == 1 >> %xml_error% echo "%%z" failed
if not %errorlevel% == 1 >> %xml_pass% echo "%%z" succeeded

in case errorlevel is non-zero and something other than 1:

if %errorlevel% neq 0 (echo "%%z" failed) else (echo "%%z" suceeded)

For /f "tokens=1 delims=," %%i in (%Today%) do set user_id=%%i
For /f "tokens=2 delims=," %%j in (%Today%) do set password=%%j
For /f "tokens=3 delims=," %%k in (%Today%) do set server=%%k

i don't know what %today% contains, but it may need quotes around it::
for /f "tokens=1-3 delims=, %%i in ("%today%") do (
set user_id=%%i
set password=%%j
set server=%%k
)

as far as I know, batch doesn't support encryption, but I don't know much, so maybe someone else can teach us both something! fsum could be used to build a password, but it's not native to windows.

Report •

#2
June 25, 2013 at 22:31:31
Thanks for answering. I am trying to call multiple xml files (from a folder "set" which is in path ("c:\Today\set")) in single.bat file.Below is the modified script

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION


//c:\Today\set
This is folder path where I have all the xml files(a.xml,b.xml,c.xml........)//

SET "xml_dir=c:\Today\set "

SET "xml_pass=c:\Today\xml-pass.log"

SET "xml_error=c:\Today\xml-error.log"

SET "FILE=%MAINLOG%"

for /f "tokens=1-3 delims=," %%i in ("%Today%") do (
set user_id=%%i
set password=%%j
set server=%%k
)


//To execute the batch xml files(in set folder) I need to call scheduleBatch.cmd utility file with Un Pwd server//

For %%z in ("%xml_dir%\*.xml") do (
call scheduleBatch "%%z" %user_id% %password% %server%

//The below error handling part is not working.Could you please let me know what changes need to be made to make it work(so once I execute the script it should launch all the xml files(a.xml,b.xml.........)

findstr /R "\<ERROR" %FILE% > ErrCheckfor /F %%A in ("ErrCheck") do If %%~zA NEQ 0 (echo Error in Batch scheduling Process......................... >> %MAINLOG% copy %MAINLOG% %LOG_DIR%\%MAINLOG%-Error.log

DEL /Q ErrCheck) else (echo Batch scheduling Process was successfull......................... >> %MAINLOG%copy %MAINLOG% %LOG_DIR%\%MAINLOG%-Pass.log))


when I run the script in command line and giving the input XXX.bat foldername(set) userid and password(encrypted) servername then only it has to execute all the batch xml files ((script.bat set UN pwd server) in one line then hit enter it will execute the batch xml files) something like this.....
They need everything in one line while excecuting the script in command line(script.bat set UN pwd server) so that it should not prompt(they dont need the user to input one by one.).and then schedule it through windows task sheduler.(daily monthly weekly). Do you any Idea about "Param file" where we can intialize all the parameters (like %1 %2......)and also the pwd encryption and calling that param file in the script.Please help me out.


Report •

Related Solutions


Ask Question