Python - credentials in a .bat file

Dear Experts,

I would need to create a .bat file under Windows, which is able to:

1) run a .py so Python file and
2) also containing credentials as the Python code needs to connect to SQL and download data.

Could you please advise about the syntax how such .bat file should look like concretely?

Actually having the following try but it does not work (it executes the Python code but not asking for the password for the user):

@echo off
runas /netonly /user:smea\csehz
"C:\Python27\python.exe" "C:\Users\csehz\Desktop\HelloWorld.py"
pause

Open in new window


Thanks in advance,
LVL 1
csehzIT consultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Best to use an existing .ini or .yaml parser.

There are many. Just take a look at your options + pick one.

Tip: Best to use YAML as the config language is far more expressive than INI file syntax.
csehzIT consultantAuthor Commented:
Thank you David.

I have also found a solution per the original concept, concretely through VBScript

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("runas /netonly /user:emea\actextzc ""C:\Python27\python.exe C:\Users\ac324485\Desktop\Auto\HelloWorld.py""")
WScript.Sleep 200
objShell.SendKeys "xxx"
objShell.SendKeys "{Enter}"
Set objShell = Nothing

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.