0

I create simple unity application, there is button that give user print a picture. When button is clicked, it will run a command in cmd but I get this message, 'cd' is not recognized as an internal or external command, operable program or batch file.

I search the web, it says I need to change encoding type but I have do it in Notepad++ (I change it from UTF-8 BOM to ANSI) but it still no work.

Here is my code, in case I am wrong.

string fullCommand = "rundll32 C:/WINDOWS/system32/shimgvw.dll,ImageView_PrintTo " + filePath + printerName
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.CreateNoWindow = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.Arguments = "/c " + fullCommand;
process.Start();

This is my reference How to direct printing of photo or text using Unity without preview

I expect it to print the expected file but it do not. I hope someone can guide me. Thank you for helping.

Cheers

Kev

  • Can you show the type and values of filepath and printername? dont you normally have spaces between those parameters too? would you not use rundll32 not cmd.exe as the process filename? – BugFinder May 02 '19 at 12:07
  • @BugFinder both are string type and for the value its; printerName = "HP Deskjet 2540 series" and filePath = "D:/FORFUN/PRINTAPPS/Assets/screenshots/screen_2550x3300_2019-04-21_02-43-16". I refer to the link before so I use cmd.exe as the process filename, but I will try to use rundll32 now to see any difference. – Kevin Chin May 02 '19 at 12:28
  • Im pretty sure you would need a space between the filepath and the printer name, or a comma... such as described by https://social.msdn.microsoft.com/Forums/vstudio/en-US/83b88818-8fb8-491f-b0ab-220285167bf8/print-with-shimgvwdll?forum=csharpgeneral where there is a space – BugFinder May 02 '19 at 12:31
  • I have add space between the filepath and printername and tried to use rundll32 as well as cmd.exe but its still not working. – Kevin Chin May 02 '19 at 12:37
  • that link and also this https://microsoft.public.platformsdk.shell.narkive.com/dRwz4aTp/how-to-print-using-imageview-printto suggest you need to do /pt before the file name/printername, they both also suggest both parameters should be quoted. Grab your string and play with it on command line until the command line works – BugFinder May 02 '19 at 12:39
  • thanks, there is much progress now but i face another thing. it said that I have filename, directory name or volume label syntax incorrect. I have checked that there is no extra spaces, no wrong filename and directory. This is my command line now: "RUN rundll32.exe C:\Windows\System32\shimgvw.dll,ImageView_PrintTo /pt "D:\FORFUN\PRINTAPPS\Assets\screenshots\screen_2550x3300_2019-04-27_15-29-32.png" "HP Deskjet 2540 series" just to make sure, volume label syntax means that there is an extra space right? I searched it and it says that but idk if there is more than that. – Kevin Chin May 02 '19 at 13:23

0 Answers0