Solved

Logon user name using API for window95

Posted on 1998-07-21
9
193 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now