Solved

Logon user name using API for window95

Posted on 1998-07-21
9
203 Views
Last Modified: 2010-03-30
SDK : JDK1.1.1.5
Development Platform : windows95

I don't know how can I use API in JAVA which I was using in VB5.
I just want to get logon user login name and IP address?
0
Comment
Question by:raza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 20 total points
ID: 1227284
Java is cross-platform that is why it does not provide any system-specific infromation like user name. As for the IP address it is:

InetAddress.getLocalHost().getHostAddress()

If you need to talk to Windows API you can probably do it using native calls.

Let me know if you need more info.
0
 

Author Comment

by:raza
ID: 1227285
thanks
if it is  posible then please send me info about how to read windows text file from windows dirctory ?
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1227286
I might be wrong on the first account. To get the user's name try

Properties props = System.getProperties();
String username = props.getProperty("user.name");

This assumes that you are running a Java application which is allowed to read the system properties. Applets can read only some properties, the user.name is probably not one of them

Let me know if you still need the info on reading the text files.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:raza
ID: 1227287
thanks
if it is  posible then please send me info about how to read windows text file from windows dirctory ?
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1227288
BufferedReader reader = new BufferedReader(FileReader(filename));

String line;
while((line = reader.readLine()) != null)
{
  // Process the line
}

0
 

Author Comment

by:raza
ID: 1227289
would u please help me to debug it out
I m getting below 3 erorrs

Compiling D:\jdk1.1.5\Program\Logonuser\Logonuser.java
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:16: Variable 'UserName' is already defined in this method.
            String UserName = props.getProperty("user.name");
                   ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:22: Invalid type expression.
            System.out.println(UserName)
                              ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:23: Invalid declaration.
            g.drawString("Hello Logonuser!", j50, 50);
                        ^
3 errors
Finished

/* here is source
=========*/
import java.awt.*;
import java.util.Properties;
public class Logonuser extends java.applet.Applet
{
      public void init()
      {
            String UserName;
            Properties props = System.getProperties();
            String UserName = props.getProperty("user.name");
            resize(300,300);
      }

      public void paint(Graphics g)
      {
            System.out.println(UserName)

      }
}



0
 

Author Comment

by:raza
ID: 1227290
I m sorry above is wrong posting the currect one is below



Compiling D:\jdk1.1.5\Program\Logonuser\Logonuser.java
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:11: Variable 'UserName' is already defined in this method.
            String UserName = props.getProperty("user.name");
                   ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:17: Undefined variable: UserName
            System.out.println(UserName);
                               ^
2 errors
Finished






import java.awt.*;
import java.util.Properties;

public class Logonuser extends java.applet.Applet
{
      public void init()
      {
            String UserName;
            Properties props = System.getProperties();
            String UserName = props.getProperty("user.name");
            resize(300,300);
      }

      public void paint(Graphics g)
      {
            System.out.println(UserName);
      }
}



0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1227291
      import java.awt.*;
       import java.util.Properties;
       public class Logonuser extends java.applet.Applet
       {
       String UserName;
       public void init()
       {
       Properties props = System.getProperties();
       UserName = props.getProperty("user.name");
       resize(300,300);
       }

       public void paint(Graphics g)
       {
       System.out.println(UserName)

       }
       }

I doubt though an applet can read the user name.
0
 

Author Comment

by:raza
ID: 1227292
I m sorry above is wrong posting the currect one is below



Compiling D:\jdk1.1.5\Program\Logonuser\Logonuser.java
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:11: Variable 'UserName' is already defined in this method.
            String UserName = props.getProperty("user.name");
                   ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:17: Undefined variable: UserName
            System.out.println(UserName);
                               ^
2 errors
Finished






import java.awt.*;
import java.util.Properties;

public class Logonuser extends java.applet.Applet
{
      public void init()
      {
            String UserName;
            Properties props = System.getProperties();
            String UserName = props.getProperty("user.name");
            resize(300,300);
      }

      public void paint(Graphics g)
      {
            System.out.println(UserName);
      }
}



0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question