We help IT Professionals succeed at work.

Passing credentials to Service in batch - Using Escape Characters

161 Views
Last Modified: 2015-12-09
I'm trying to complete a silent install batch script and having issues passing the credentials to my service.  The svc account and password both have special characters and I've tried using escape characters to get the credentials to pass through.  I was able to get basic character credentials to pass for testing but that will not work in production.  See attachment for my script, any help would be much appreciated!
passthrough.JPG
Comment
Watch Question

NVITEnd-user support
CERTIFIED EXPERT

Commented:
Can you use other chars besides ! (exclamation)?

Author

Commented:
The real password is a little more complex than the one I gave in my attachment.  However, it does use an ! character and I'm not the owner of the svc account so I think they'd like to keep the pw as is.  I inserted \ before the special characters in my script and it seemed to pass through but still having issues with the password.  When I open the service it looks like it worked but fails when I try to start the service.  Also, when I open the software I'm showing that my user id passed through but the password field is blank.
NVITEnd-user support
CERTIFIED EXPERT

Commented:
Have you tried ^ as escape char?
NVITEnd-user support
CERTIFIED EXPERT

Commented:
For any quotes in the password, double quote it, e.g. "passw""ord!"

Author

Commented:
Just tried using ^ and it outputted options for the sc.exe cmdlet
End-user support
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
Attention! Is you set a var,  the value starts immediately after the equal sign! Depending on where you use the var, it matters.
And yes, using a caret as escape should work. But each time you pass the value thru another level, or further process it, it gets worse and now unpredictable how many carets you need...

If ! is the only big issue, try to disable delayed expansion.

But the best solution is to use VBS or PowerShell (favourable), without using sc.exe.
CERTIFIED EXPERT
Top Expert 2016

Commented:
passing real account credentials by batch or by script is not a good idea. it is very easy to reveal the data for anyone wants to do that. for example a user could break the login by ctrl+c and it is a good chance that it breaks in a command window which shows all the decret data passed. even encrypting a vbs script (vbs to vbe) is a poor method and simple to hack since there are lots of decryption tools free available.

therefore i would recommend to create a key-pair and encrypt your request with the public key and use a method to send it to the service without credentials (for example by socket stream or by web service). the service then would decrypt the request by using the private key. doing it that way is pretty safe and could even be made unbreakable by adding some handshake between client and service.

Sara

Author

Commented:
Thanks Everyone!  I end up using powershell and calling the cmd.exe cmdlet to pass through the credentials.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.