1

The university I work for allows students to register their bikes for indoor storage during the winter. This is done through a website. At the end of the process, a DYMO label printer connected to the network is supposed to print out a label that will be stuck to the bike.

Here is the process:

  1. User and bike data is entered into a web form by a staff member. (this works)
  2. User and bike data is stored in an Oracle database. (this works)
  3. PHP running on the web server saves the user and bike data into a CSV file. (this works)
  4. PHP running on the web server calls a VBScript. (this works)
  5. The VBScript opens a Word document that loads the CSV data and prints a label. (problem)

Now, the VBScript works correctly. If I manually run the VBScript, it will open Word, load the CSV data, print a label, and close Word.

Likewise, if I add a bit of code to the end of the VBScript to write a .txt file (for testing purposes) the text file gets written whether I run the script manually or allow it to be run by the website.

As such, I suspect there is a permissions problem preventing the VBScript from accessing Word and/or the printer when run from the web. Any suggestions on how to solve this problem?

The web server is Windows Server 2003 running XAMPP.

If it helps, here is the line in PHP that calls the VBScript:

exec('wscript "D:\CSWebHousing\wwwroot\portal2\bikes\testcode.vbs"');

Here is the relevant portion of the VBScript:

Sub TestCode
Set ws = WScript.CreateObject("WScript.Shell")

OFFICE_PATH = "C:\path_to\Office12"

    file_to_open = CHR(34) & "D:\path_to\Label.doc" & CHR(34)

ws.Run CHR(34)& OFFICE_PATH & "\winword.exe" & CHR(34) & file_to_open, 0, false 


'These lines tab and enter past a dialog box
intTime = 3000
Wscript.Sleep(intTime)
ws.Sendkeys "{TAB}"
intTime = 500
Wscript.Sleep(intTime)
ws.Sendkeys "{TAB}"
intTime = 500
Wscript.Sleep(intTime)
ws.Sendkeys "{ENTER}"
intTime = 4000
Wscript.Sleep(intTime)
ws.Sendkeys "%fx"
End Sub

I think it is a permissions problem, but any ideas would be appreciated.

Thank you.

rjc
  • 11
  • 3
  • Interesting. Why use word to open CSV files? – tombull89 Nov 19 '13 at 20:20
  • It's basically doing a single mail-merge to put the user/bike data into the proper spots on the label. This who setup was created 3 years ago by my predecessor, thrice removed. As such, I don't have a lot of information about the hows and whys, I just need to get it working again. My predecessor last year was unable to get it working and all bike labels were written out by hand. I hope to do better. :( The person before him was able to get it working, but said it was a pain. And the person before him wrote it, but is unavailable for comment. – rjc Nov 19 '13 at 20:21
  • 1
    You say the vbscript works. What user account is running the script when it fires off on the server? Is that account interactively logged on or not? That's where I would guess the issue lies. – TheCleaner Nov 19 '13 at 20:37
  • I remote desktop in as Administrator and double-click the VBScript when I run it manually. I am not sure which user account XAMPP is using when the website runs the script. – rjc Nov 19 '13 at 20:46
  • That would be what I would find out, and I would think the interactive session issue might also be part of it. You might have to end up asking over on SO after you find out that part how to correct the script though. I'm not sure on that part, just think the above needs to be known first. – TheCleaner Nov 19 '13 at 20:50
  • 2
    In all honesty, this sounds like a badly written tool (ie Rube Goldberg). Since you are at a University can't you try to talk someone in the CS department into re-writing this? You have PHP, VBScript, and word being used. If they wrote something in .Net it seems like it should be possible to do the entire process in a single application. – Zoredache Nov 19 '13 at 21:37
  • I agree. I'd write something myself if I had time, but I do not. Maybe for next year. Right now, I just need to get this contraption working. – rjc Nov 19 '13 at 21:43

2 Answers2

0

Having done a large number of scripted installs with vbscript...

I think the issue is SendKey.

SendKey is great if you're launching a vbscript as a person. The focus sometimes gets lost when you're launching the script as some kind of automated process.

It so happens that there's a handy Stack Overflow question on maintaining your window focus with SendKey here: https://stackoverflow.com/questions/16173315/windows-batch-file-not-working-consistently

I hope that helps.

Katherine Villyard
  • 18,550
  • 4
  • 37
  • 59
  • Thank you for the suggestion, but that did not solve my problem. – rjc Nov 20 '13 at 18:14
  • Have you tried running it as the web server account? Have you tried logging in as the web server account and getting the web service to launch it while you were logged in as the web service account? (If that solves the problem, you might need to leave a kludgy command line window open or something.) – Katherine Villyard Nov 20 '13 at 20:17
  • I'm still trying to figure out what account the web server uses. Sadly, XAMPP has very little documentation and nobody responded to my question on their support forum. It's possible that it was a dumb question. I used to work with unix-style servers, and there are surely a lot of obvious Windows Server things I just don't know. – rjc Nov 21 '13 at 13:10
  • If you go into Services, there's a log on tab where you can probably find this information. – Katherine Villyard Nov 21 '13 at 20:54
0

Since you already assumed it to be the problem - I think you should check if permissions are an issue here.

If the php script is starting the VB script, then the user running the webserver will run the VB script. And this user then needs access to the script location and to the csv file. The easiest test would be to allow access to both files to everyone (which must be reverted after successfull testing!) - then you know if it is a permission problem.

You could also test both parts of you problem individually:

  • Modify the script to print out any text - just to see if the website is able to start the VB script at all.
  • Try to output the content of the csv file on the website to see if you are able to access this file with the script.
Tobias
  • 1,236
  • 1
  • 13
  • 25