return to tranceaddict TranceAddict Forums Archive > Main Forums > Chill Out Room

 
Applet Question
View this Thread in Original format
UglyDave
right folks

i've written an applet which retrieves a clients local machine username and writes it to a file.

however, when i the applet as an applet, it doesn't work.

when i run it in BlueJ (by creating an object & calling the methods), it works perfectly.

i didn't write all the code myself, some came from another app.

here's the code:

code:
import java.applet.*; import java.awt.Graphics; public class ntApplet extends Applet { public String userName = "unknown"; public void init(){ try { com.sun.security.auth.module.NTSystem ntSystem = new com.sun.security.auth.module.NTSystem(); userName = ntSystem.getName(); toFile(getUserName()); System.out.println(getUserName()); } catch (Exception e) { System.out.println("Error : " + e + "\n"); } } public void paint (Graphics g){ super.paint(g); g.drawString("Username:"+userName, 25,25); } public void toFile(String st){ try{ file f = new file("users.txt"); f.openForAppend(); f.print(st); f.close(); } catch (Exception e){ System.out.println("Error: " + e ); } } public String getUserName() { return this.userName; } }


and the html:

code:



any help greatly appreciated!!
UglyDave
basically, when in run it from BlueJ, i get the output i want. but when i run it from a browser it gives me "unknown"

anyone have any suggestions??
DigiNut
Oi vey Dave, you don't make this easy for troubleshooters do you.

1. What is the error?
2. Does the applet run at all?
3. What system are you running, and what system is the web server running?
4. What is the actual filename of the class? Are you sure it's practicals.ntApplet.class?
5. Hurry up, my sobriety won't last much longer tonight.
whiskers
yeah... aren't you not supposed to be able to get someone's username simply by running a script on their machine?


might be a browser issue.
UglyDave
quote:
Originally posted by DigiNut
1. What is the error?

ok, BlueJ allows u to creat instances of classes to test them etc.. when i run it in bluej, i run it, run the methods and it works fine. it returns the username.

2. Does the applet run at all?
yes, it displays "username: unknown"

basically. it runs ok when i create an object and run the methods that way. but it wont work when i run it from a browser.

3. What system are you running, and what system is the web server running?

runnin win2k at the min. just runnin the applets from my local machine


4. What is the actual filename of the class? Are you sure it's practicals.ntApplet.class?

ntApplet.class - in the practicals directory - also practicals directory

5. Hurry up, my sobriety won't last much longer tonight.[/COLOR]
there.. about 12 mins :) not a bad responce time!!
[/FONT]
UglyDave
quote:
Originally posted by whiskers
yeah... aren't you not supposed to be able to get someone's username simply by running a script on their machine?


point me in the direction of this script!
whiskers
script, applet, whatever

getting pc username is a security issue and i doubt browsers would allow that. then again, i might be wrong.
UglyDave
quote:
Originally posted by whiskers
script, applet, whatever

getting pc username is a security issue and i doubt browsers would allow that. then again, i might be wrong.


well, i'm just tryin to keep track of the users who post on my messageboard.. this wasy if someone comes on and says "David is gay"

i might have some means by which i can find out hwo it is..
DigiNut
Lordy...

quote:
Originally posted by UglyDave
ok, BlueJ allows u to creat instances of classes to test them etc.. when i run it in bluej, i run it, run the methods and it works fine. it returns the username.

So there's no error at all, it just says unknown? That means that the call to the getName() failed, or possibly the program failed to create an instance of the NTSystem class.

quote:
yes, it displays "username: unknown"

basically. it runs ok when i create an object and run the methods that way. but it wont work when i run it from a browser.

That really doesn't surprise me. You're totally confusing the client and server, Dave. The program is running on the web server - you'll never be able to retrieve an NT username from the client machine. If the call you are making doesn't fail, then it will retrieve the SERVER'S username, not the clients. But the call is probably failing because the web user (probably IUSR_ or IWAM_) doesn't have the privileges to execute those functions.

quote:
runnin win2k at the min. just runnin the applets from my local machine

Keep in mind that even if you got it working on your machine, there is no chance it would ever work on a UNIX server and might not work on an external NT server either if their security isn't set up the same as yours.


quote:
there.. about 12 mins not a bad responce time!!

I'd give it about another half hour before I'm completely out.

P.S. whiskers said that you CAN'T get someone's username, which I'll have to agree with. He didn't say there was a script that can.

Edit: for debugging purposes, you might want to try to check to see if the NTSystem class was created or if it is null - try adding something to the effect of "if ntSystem == nil userName = 'failed';" or something like that. Or, use separate try/except clauses for each statement at the top and see where the program is failing. There's no way to tell without proper debugging info. But I'd hazard a guess that you simply can't do what you're trying to do, at all, no matter what.
UglyDave
mis read whiskers first post!

u guys "are teh 1ee7est"

i shal never use "teh" again

UglyDave
aah well, i'll arse about for a while longer. see if i can find any exceptions.

later dudes!
cheers for the help!

have fun drinkin Digi!
CLICK TO RETURN TO TOP OF PAGE
 
Privacy Statement