TranceAddict Forums

TranceAddict Forums (www.tranceaddict.com/forums)
- Chill Out Room
-- Applet Question


Posted by UglyDave on Mar-11-2004 22:52:

Applet Question

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!!


Posted by UglyDave on Mar-11-2004 22:56:

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??


Posted by DigiNut on Mar-12-2004 00:10:

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.


Posted by whiskers on Mar-12-2004 00:20:

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.


Posted by UglyDave on Mar-12-2004 00:23:

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]


Posted by UglyDave on Mar-12-2004 00:24:

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!


Posted by whiskers on Mar-12-2004 00:29:

script, applet, whatever

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


Posted by UglyDave on Mar-12-2004 00:32:

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 shit 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..


Posted by DigiNut on Mar-12-2004 00:32:

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.


Posted by UglyDave on Mar-12-2004 00:35:

mis read whiskers first post!

u guys "are teh 1ee7est"

i shal never use "teh" again


Posted by UglyDave on Mar-12-2004 00:37:

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!



Powered by: vBulletin
Copyright © 2000-2021, Jelsoft Enterprises Ltd.