Solved

Logon user name using API for window95

Posted on 1998-07-21
9
199 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java: anonymous class 4 38
Java syntax, or is it Selenium 6 41
Print Rhino Java Array in Javascript 1 37
Java array sort 10 33
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

733 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