I hope you guys can help me out...
i have a little applet which caused me lot of problems.
i'm new to java and i hardly managed to put all the code together,
what does the script? here:
users visit my website, and from their account they can upgrade a driver and some files for one game.
the script works well on windows XP, and when it comes to Windows Vista or Windows 7 i gate a stupid error. here is the error:

Ignored exception: java.lang.NullPointerException
Ignored exception: java.lang.NullPointerException
java.io.FileNotFoundException: C:\Program Files\Drivers (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at fontapplet.fileUrl(fontapplet.java:81)
at fontapplet.fileDownload(fontapplet.java:65)
at fontapplet.start(fontapplet.java:18)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at fontapplet.fileUrl(fontapplet.java:96)
at fontapplet.fileDownload(fontapplet.java:65)
at fontapplet.start(fontapplet.java:18)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionR unnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NullPointerException

Windows 7 / vista users with User Account Control (UAC) turned off can run and execute the applet correctly.
All Windows 7 / vista users which get this error, if they run Internet Explorer by using the "Run As Administrator" funciton, they also can run and execute the application.

So i want all the users to be able to run and execute the application, without getting the stupid Access is denied error.

here is the piece of code i wrote:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;

public class myapplet extends Applet {
	public void init(){
	}
	public void start(){

	String DestDir="";
	String GetFile="http://www.mywebsite:80/magicdriver.inf";
	boolean errorControl = checkDir("C:/temp");

	DestDir="C:/Program Files/drivers/";
	if(checkDir(DestDir)){
	fileDownload(GetFile,DestDir);
	}
	loadPage();
	}
	

	public void fileDownload(String fAddress, String destinationDir){
		int slashIndex =fAddress.lastIndexOf('/');
		int periodIndex =fAddress.lastIndexOf('.');

		String fileName=fAddress.substring(slashIndex + 1);

		if (periodIndex >=1 &&  slashIndex >= 0 && slashIndex < fAddress.length()-1){
			fileUrl(fAddress,fileName,destinationDir);
		}
		else{
			System.err.println("path or file name.");
		}
	}

	public void	fileUrl(String fAddress, String localFileName, String destinationDir) {
		OutputStream outStream = null;
		URLConnection  uCon = null;
		InputStream is = null;
		try {
			URL Url;
			byte[] buf;
			int ByteRead,ByteWritten=0;
			Url= new URL(fAddress);
			outStream = new BufferedOutputStream(new FileOutputStream(destinationDir+"\\"+localFileName));

			uCon = Url.openConnection();
			is = uCon.getInputStream();
			buf = new byte[1024];
			while ((ByteRead = is.read(buf)) != -1) {
				outStream.write(buf, 0, ByteRead);
				ByteWritten += ByteRead;
		}
	}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			try {
			is.close();
			outStream.close();
			}
			catch (IOException e) {
			e.printStackTrace();
			}
		}
	}
	private void loadPage() {
		try {
		this.getAppletContext().showDocument(new URL("http://www.mywebsite.com/members/thankyou.php"));
		}
		catch (Exception e) { 
		e.printStackTrace(); 
		}
	}
	public boolean checkDir(String fAddress) {
		File filePath = new File(fAddress);
		boolean success = filePath.isDirectory();
		if (success){
			return true;
		}else{
			return false;
		}
	}
}

here is the applet code in html:

<applet code="myapplet.class" archive="myapplet.jar" width="100px" height="50px">
	<param name="progressbar" value="true" />
    <PARAM NAME="java_type" VALUE="application/x-java-applet;jpi-version=1.7.0">
	<param name="progresscolor" value="102,102,102" />
	<param name="boxmessage" value="Loading..." />
<hr>
<strong><center>You need to have Java installed to view this page! <a href="http://www.java.com/en/download/manual.jsp">[Java download page]</a></strong></center>
  <hr>
</APPLET>

Please i'd like to fix it, but i don't know how. if there is anything wrong with it please tell me.
What to do?

Recommended Answers

All 5 Replies

Its called security. You would need to get the users to "turn it off". What do you think would happen if browser applications could simply modify/create files anywhere on the file system? Do the terms "trojan" and/or "virus" (whether malicious or not) ring any bells?

i know what a trojan or a virus is, but my application is not!
if i sign my applet with a CA trust certificate issued by a company like verising or any third party company will this help me?

No one said it was one, but how is the system to know that? And simply signing probably will not help, as it looks as though you are trying to write into "Program Files" which the user cannot with UAC on.

the website has instructions, and notify user it will install the driver. the user know about this, and proceed to the page with the applet.
only windows7 and windows vista users face this access denied problem. they users don't have full administrator rights. to gain full rights the user must run the browser with Run As Administrator, then the applet is working fine.
why is this happening? what should i do? this applet will get signed with a CA third party trust certificate, so it won't be any doubts about it's authenticity.
but before i spend my money on such a certificate, i must be sure the applet is working properly.

Like I said it is the UAC. Users do not have normal access to write to the "Program Files" directory without Administrator rights, and, in fact, even then not without starting the browser under "run as administrator". You are not going to be able to change that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.