I am trying to get a Java class to first take a screen cap (print screen) and then run a batch file which invokes some VBScript to attach this screenshot to a blank mail message that opens up in Outlook (the location of the screenshot is predetermined on the user's workstation).
The structure of my application is the following:
All the files reside in the package com/utils/mailsender
Inside this package, I have a simple Java class called RunBat which has the following line of code to run the batch file (ignoring the other lines of course):
The exec.bat file is present in the same package and runs a VBScript file to attach the sreenshot (The .vbs file is present under com/utils/mailsender/vbs/). It works perfectly when double clicked.
The code above, when executed, gives the following error:
Now, I am given to understand that error=2 is a naming error (?), so I included the full path, like this:
Now the code executes without any runtime error, but it does not invoke the batch file (i.e. nothing happens).
My questions are:
1.) Is there a way to make the batch file run? I understand that this way of running batch files is not very reliable (I have actually run the batch file using the same code before on my workstation, but now it appears not to be working...has the "packaging" of the Java class got something to do with it?)
2.) Are there any better ways to make a batch file run from a Java class?
3.) I certainly want to avoid supplying the full path of the batch file as it will make the code dependent on my workstation (which sort of defeats the purpose). Any hinters on that?
Your help is much appreciated as always.
[ June 19, 2008: Message edited by: Sridhar Venkataraman ]
I'll try those out and report back here if they are successful.
[ June 23, 2008: Message edited by: Maki Jav ]
Thanks for your replies.
I realized something fundamentally wrong about my thinking about this whole issue, beg your pardons. (A disucssion is HERE)
The problem at hand is that I want to get a screen capture of the client's window, but I am running the code for doing this from the server. Effectively, this won't solve the problem, because code run at the server side is going to take a screencap of the server-side workstation, when what I want is a screencap of the client's workstation.
I have done extensive research and participated in discussions which can somehow get client-side scripting languages to capture a screenshot, but it doesn't look possible because of security reasons.
I would now like to know whether there is any way to run code on the server side that can capture screenshots at the client side, even if it involves getting the client's permission.
Any ideas on whether this is possible at all? My ideal flow is something like this:
1.) User clicks a link on the webpage
2.) A screenshot of the user's workstation is taken and attached to a mail message (since this is an intranet app, firing up Outlook is enough)
3.) It is upto the user to mod the message and send it across if he/she wishes to
[ June 23, 2008: Message edited by: Sridhar Venkataraman ]
Originally posted by Joe Ess:
java.awt.Robot can take a screen shot. You could run it in an applet. Of course, applets run under restrictions, so you'd need to digitally sign it to use Robot.
The JavaMail API can send mail to an SMTP server, so that may be another piece of your puzzle.
Thanks for your reply. Yeah, I had the applet based implementation in mind as well.
I would like to avoid using the Java Mail API as much as possible because I'll have to configure the Outlook server used here in my organization within the application. But I guess if it comes to that, it has to be done.
How am I going to get the client's e-mail address if I use the Java Mail API to send a mail message through Outlook? With VBScript, it's easy to just fire up the client's Outlook application with a mail message.
These were the steps I followed:
a.) I first converted the Java class which is supposed to take a screenshot of the client's workstation and save it as a JPG in a pre-determined location, into an applet by extending the Applet class
b.) Then, I packaged this class into a jar file and signed it with a standard keystore
c.) I put this jar into the 'lib' folder of the root directory of my web application, and added the applet using the <applet> tag on the JSP page where it was needed
d.) I then wrote a JScript file with a function to call a public method present this applet (takeScreenShot()) [inspired by THIS ARTICLE], and stored in in the 'js' folder of the root directory of the my web application (This file also contains code to call a VBScript function [present in a separate .vbs file of course] to send the screenshot taken as an attachment in an e-mail by firing up Outlook)
e.) I created a link which calls upon the JScript function to do the above. Of course, I added references to the JScript and VBScript files in my JSP page
So, after setting up all this, I tested my application and here are the results:
The applet got added successfully to the page, though I would prefer it to be invisible to the user (i.e. when the applet fired, it took up a blank area on the JSP page, which I would like to avoid since it has no GUI). The security certificate showed up as well, and I OKed it.
On clicking the link on the page, the JScript was fired, but IE returned an error on the page. The error was:
Error: Path does not exist. Make sure the path is correct.
Now, the JScript does get fired and calls on the VBScript sucessfully because Outlook does open up, though the new e-mail message is not created. This is because the takeScreenShot() method of the applet apparently is not doing it's job, and the VBScript is not finding the screenshot where it's supposed to be.
I'd like to know whether I need to sign the applet or modify its code in a different way such that when the user OKs the certificate, it can have access to the local file system. I am leaving all the lifecycle methods in the applet blank. All it has currently is a takeScreenShot() method which will behave the same way as a normal Java class.
I'd also like to know if an Applet can be added and its methods can be accessed without actually making it take up space on the JSP page (After the security certificate is OKed and the applet control activated, it doesn't take up space anymore...but is there a way to avoid this as well?)
Thank you everyone.
[ June 25, 2008: Message edited by: Sridhar Venkataraman ]
[ June 26, 2008: Message edited by: Sridhar Venkataraman ]
Did you find the solution for taking the screen shot of the client browser page. If yes will you please post your code.