1

Thanks for reading / helping. On an old win2003 server, in this scenario:

Const WshRunning = 0
Const WshFinished = 1
Const WshFailed = 2
Dim shell, exec, strOutput

Set shell = CreateObject("WScript.Shell")
Set exec = shell.Exec("cmd.exe /c echo hello world") ' << this line changes in each example

If exec.Status = WshFailed Then
    strOutput = exec.StdErr.ReadAll
Else
    strOutput = exec.StdOut.ReadAll
End If
response.write strOutput

I get the perfect response: "Helllo world", both in CMD and in ASP. also with

Set exec = shell.Exec("cmd.exe /c ping 127.0.0.1")

Again, perfect response, both in CMD and in ASP.

But I need to know how big a pdf is. So I tried 2 tools:

Set exec = shell.Exec("cmd.exe /c qpdf --show-npages c:\utils\b.pdf")
Set exec = shell.Exec("cmd.exe /c pdfinfo -v c:\utils\b.pdf")

Both work in cmd, it outputs what I want to know, but I get no response in asp. Both tools have IUSR rights. What am I missing? Thanks a lot,

Alex

My comments below properly readable:

Good point. I forgot to mention that I did include in the system variables:

var: pdfinfo val: c:\Program Files\Utils\xpdf\pdfinfo.exe

var: qpdf val: c:\WINDOWS\system32\qpdf.exe

relevant part of PATH:

%SystemRoot%\system32;

C:\Program Files\Utils\xpdf\;

C:\utils\;

But, funny enough:

Set exec = shell.Exec("cmd.exe /c pdfinfo -meta c:\utils\b.pdf")

CMD.exe starts, that's all. But, on your suggestion, I tried

Set exec = shell.Exec("cmd.exe /c ""c:\Program Files\Utils\xpdf\pdfinfo.exe"" -meta c:\utils\b.pdf")

as well: (sometimes, not all the time) Process Explorer shows pdfinfo being started up by cmd as well. Still no response to ASP though. Thank you for helping :-)

AlexPM
  • 43
  • 4
  • Welcome to SO. Are `qpdf` and `pdfinfo` executables? What happens if you fully-qualify the path to both and specify the file extensions? My guess is that classic ASP might not be able to locate those files by searching the %PATH%. For example, `Set exec = shell.Exec("cmd.exe /c ""C:\Program Files (x86)\PDF24\qpdf\bin\qpdf.exe"" --show-npages c:\utils\b.pdf")` – leeharvey1 Apr 08 '20 at 12:59
  • Good point. I forgot to mention that I did include in the system variables: var: pdfinfo val: c:\Program Files\Utils\xpdf\pdfinfo.exe var: qpdf val: c:\WINDOWS\system32\qpdf.exe relevant part of PATH: %SystemRoot%\system32; C:\Program Files\Utils\xpdf\; C:\utils\; – AlexPM Apr 08 '20 at 14:52
  • But, funny enough: Set exec = shell.Exec("cmd.exe /c pdfinfo -meta c:\utils\b.pdf") > CMD.exe starts, that's all. But, on your suggestion, I tried Set exec = shell.Exec("cmd.exe /c ""c:\Program Files\Utils\xpdf\pdfinfo.exe"" -meta c:\utils\b.pdf") > and (sometimes, not all the time) Process Explorer shows pdfinfo being started up by cmd as well still no response though. (sorry I cannot get the "2 spaces = line breaks" to work ) And thank you for helping :-) – AlexPM Apr 08 '20 at 14:56
  • 2
    Can you redirect standard output to a file, then read-in the contents of the file after the executables run? For example, `Set exec = shell.Exec("cmd.exe /c ""C:\Program Files (x86)\PDF24\qpdf\bin\qpdf.exe"" --show-npages c:\utils\b.pdf > c:\utils\output.txt")` Then, open c:\utils\output.txt, read all its contents, and parse it. This assumes there's content saved into c:\utils\output.txt after the executable runs. – leeharvey1 Apr 08 '20 at 16:48
  • Hi LeeHarvey, yes I assume that could be a workaround. One I was hoping to avoid, as a web application is all about speed :-). But maybe I can trick the user by presenting the info later on :-) – AlexPM Apr 08 '20 at 18:28
  • Try to redirect output as suggested above. If not working (i.e. no output.txt generated) it means asp/IIS process has no permissions to properly run qpdf.exe and you will need to fix permissions. Alternative try is to run as admin/poweruser, see https://stackoverflow.com/questions/13060215/vbscript-single-line-as-administrator or https://superuser.com/questions/1171404/launch-a-bat-file-without-a-command-window-as-administrator – user2316116 Apr 09 '20 at 08:23

1 Answers1

0

The problem has finally been solved. Can't say for 100% certain what solved it, but for anyone reading this: this code

Set exec = shell.Exec("cmd.exe /c qpdf --show-npages c:\utils\b.pdf")

was correct but not working. It started to work after I changed:

  • qpdf.exe ( in system32) had full control on IUSR, qpdf13.dll did not. Changed.

  • C:\utils\b.pdf had full control on IUSR, but the folder C:\utils did not. Changed the test to folder C:\test\ which did have Full Control on IUSR.

  • restarted just in case.

Thank you for the help!

AlexPM
  • 43
  • 4