0

Imagine a company named XYZ, has bought a Windows OS. While installing it in their system, they might have given the name of their company (XYZ) . How to get that (company name) name of the organization from java?

EDIT: As suggested in comments, i searched in regedit. It is seen that there is no direct way to get the Company name directly from OS information.

(Microsoft office is storing the value that they got from the user explicitly while installing them at HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo - Company)

Nandha
  • 752
  • 1
  • 12
  • 37
  • XYZ as the PC name ? – Nisal Edu Nov 01 '17 at 09:47
  • No..It is the name of the company. – Nandha Nov 01 '17 at 09:51
  • Is there a Windows command that returns "XYZ"? – laune Nov 01 '17 at 09:51
  • Don't know. May be is it possible to get from java? Something similar to System.getEnv("....") ? – Nandha Nov 01 '17 at 09:56
  • 1
    You can use WMI queries or peek in the registries for that. But doing that in Java only wasn't easy to do. I have written a C++ extension to overcome that. Although some people claims to be successful like [this SO answer](https://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java) (peek into `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization` to get the company name) – KarelG Nov 01 '17 at 10:18
  • "They might have given..." That's not the way for installing systems. Either they have a standard procedure and adhere to it, or there is no way to get the name of the company. Do you think the computer can read the sign over the main entrance? You are chasing a phantom. – laune Nov 01 '17 at 10:18
  • @KarelG Works if the computer is online and the web address isn't blocked and they did register, and the name is the one of the company - all of which is not an absolute requirement. – laune Nov 01 '17 at 10:21
  • @laune what are you saying? You don't need a network connection for that. He wants to find out a company name if it is provided with his java program. It is possible, but only if the applet is launched as admin (otherwise I couldn't use my C++ extension to check the registries). The WMI registries is the right place for that. However Java is not designed to work with it. – KarelG Nov 01 '17 at 10:26
  • @KarelG How does one provide a company name with a java program? And, typically, users are not permitted to run as admin in any orderly organization. – laune Nov 01 '17 at 10:30
  • 1
    @KarelG 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization' will this key be available in all windows system? Because i too got the company name key inside the path mentioned in EDIT. But that path won't be available if the user does not have Microsoft office. –  Nov 01 '17 at 11:12

2 Answers2

2

You can track it by using IP address by the underlying DNS

import java.net.InetAddress;
import java.net.UnknownHostException;

String hostname = "";

try
{
    InetAddress address;
    address = InetAddress.getLocalHost();
    hostname = address.getHostName();
}
catch (UnknownHostException ex)
{
    System.out.println("Can't Find the PC name");
}
Nisal Edu
  • 7,237
  • 4
  • 28
  • 34
  • Thank you. This gives the name of the system. But i need the name of the organization to which the system belongs to. Possible only if they had provided this information during installation. – Nandha Nov 01 '17 at 10:00
1

Instead of using DNS lookup, you can look for the environment variable COMPUTERNAME (Windows only). This will not work for Mac or Linux.

private static String getComputerName()
{
    Map<String, String> environment = System.getenv();
    return environment.get("COMPUTERNAME");
}
jepml
  • 56
  • 4