Solved

Logon user name using API for window95

Posted on 1998-07-21
9
192 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

19 Experts available now in Live!

Get 1:1 Help Now