Command runs at command prompt but not in batch file

Rundll32 command runs fine at the command prompt but does not execute in a batch file. Any idea why?

this is the command:

rundll32 printui.dll,PrintUIEntry /in /n\\printers\105-XE-ECOM-BW1

\\printers                      is the print server name
105-XE-ECOM-BW1     is the name of the printer
Claude_CardinalAsked:
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.

Bill PrewIT / Software Engineering ConsultantCommented:
What is displayed when run from batch?


»bp
Claude_CardinalAuthor Commented:
The black command screen open and close right away. I don't get the chance to read the error message.  Tried to put a pause at the end of the batch file but looks like the batch file abort before reaching the pause command.
Bill PrewIT / Software Engineering ConsultantCommented:
Try opening a command prompt window first, then running the BAT file in that.  It should stay open and you can see if there is anything displayed on standard output.


»bp
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Claude_CardinalAuthor Commented:
Thanks for the tip. I can now see the error message.

It happened that although everything seems fine when I looked at the batch file, the batch file itself was corrupted. I copied and paste the line in a new batch file and everything works.  The batch file was generated using Powershell and it is the second time that this happens with a batch file generated with Powershell. Totally forgot about it until I saw the error message.

Basically, the error message mentioned the following:

C:\Drivers>105-XE-BUY-BW01.bat

C:\Drivers>■r
'■r' is not recognized as an internal or external command,
operable program or batch file.



Thanks a lot or your help
Bill PrewIT / Software Engineering ConsultantCommented:
Great, glad that helped.


»bp

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
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
PowerShell generates text files in Unicode (UTF-16) by default, that's why that does not work. When creating a batch file by PowerShell code, make sure you add -Encoding ASCII (or OEM if you need non-ASCII characters from the current codepage, above 128 dezimal) to corresponding command (e.g. out-file).
Claude_CardinalAuthor Commented:
Thank you so much Qlemo. This makes total sense. Will try it first thing tomorrow.
Claude_CardinalAuthor Commented:
Tried Qlemo's suggestion and it worked perfectly. Thanks again.
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 Batch

From novice to tech pro — start learning today.