How to read "company name" from Windows using C #?

Some programs read the company name that you entered when installing Windows and displayed it in the program. How it's done? Do they just read the name from the registry?

+3
source share
6 answers

If you want the registered name of the company to be entered in the register, you can get it from:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization

Using the registry class, you can do something in this direction:

string org = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion", "RegisteredOrganization", "");
+11
source

You can read it. Using WMI, it looks like you are after the Win32_OperatingSystem class, and the Organization element of this class contains the company name.

. , System.Management.dll . , foreach, , , , :

using System;
using System.Management;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementClass c = new ManagementClass("Win32_OperatingSystem");

            foreach (ManagementObject o in c.GetInstances())
            {
                Console.WriteLine("Registered User: {0}, Organization: {1}", o["RegisteredUser"], o["Organization"]);
            }
            Console.WriteLine("Finis!");
            Console.ReadKey();
        }
    }
}
+4

Windows :

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization

:

using Microsoft.Win32;

, :

RegistryKey hklm = Registry.LocalMachine;
hklm = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
Object obp = hklm.GetValue("RegisteredOrganization");`
Console.WriteLine("RegisteredOrganization :{0}",obp);`

, Xiaofu.

- . , escape- #, , \n tab, \t, # , , , (\) @ (@ "\ somestring" ):

string org = (string)Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\\Software\\Microsoft\\Windows NT\\CurrentVersion", "RegisteredOrganization", "");

. RegisteredOrganization , . try/catch .

+3

API SystemParametersInfo SPI_GETOEMINFO

int details = SystemParametersInfo(SPI_GETOEMINFO, OEMInfo.Capacity, OEMInfo, 0);
        if (details != 0)
        {
            MessageBox.Show(OEMInfo.ToString());
        }

OEM. , , ( )

:
http://pinvoke.net/default.aspx/Enums.SystemMetric

+1

.NET, , , , :

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization

http://support.microsoft.com/kb/310441

0

-, , , .

using Microsoft.Win32;

namespace Extensions
{
    public static class MyExtensions
    {
        public static string CompanyName(this RegistryKey key)
        {
            // this string goes in my resources file usually
            return (string)key.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion").GetValue("RegisteredOrganization");
        }
    }
}

:

RegistryKey key = Registry.LocalMachine;
return key.CompanyName();

Nothing out of the ordinary, just a prettier way to deal with deleted registry values.

-1
source

Source: https://habr.com/ru/post/1699282/


All Articles