tiene el nombre PC como un valor que se desea, por lo que puede obtener esta información de Environment.MachineName
si desea que el equipo local, o puede hacerlo IPHostEntry hostEntry = Dns.GetHostEntry(ip);
continuación string host = hostEntry.HostName;
utilizar DNS para resolver el nombre de una computadora remota si solo tiene su IP.
Usted puede obtener cierta información del registro, después de comprobar que el registro remoto está en funcionamiento, asumiendo que usted quiere un equipo remoto:
ServiceController sc = new ServiceController("RemoteRegistry", computer);
if (sc.Status.Equals(ServiceControllerStatus.Running))
{
// do your stuff
}
Y se puede iniciar si la encuentra detenido:
if (sc.Status.Equals(ServiceControllerStatus.Stopped) ||
sc.Status.Equals(ServiceControllerStatus.StopPending))
{
sc.Start();
}
Añadir esta declaración using
a la parte superior de la página:
using Microsoft.Win32;
Para el nombre de la computadora, puede ir a HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ ComputerName \ ActiveComputerName:
string path = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName";
RegistryKey rk = Registry.OpenRemoteBaseKey(RegistryHive.LocalMachine, computer).OpenSubKey(path);
string pcName = rk.GetValue("computerName").ToString();
Para todos los comandos locales de registro, basta con retirar Registry.OpenRemoteBaseKey(
y , computer)
.
Para el nombre de la CPU:
string path = @"HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0";
RegistryKey rk = Registry.OpenRemoteBaseKey(RegistryHive.LocalMachine, computer).OpenSubKey(path);
string cpuName = rk.GetValue("processorNameString").ToString();
Para el nombre del sistema operativo y la clave:
string path = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
RegistryKey rk = Registry.OpenRemoteBaseKey(RegistryHive.LocalMachine, computer).OpenSubKey(path);
string osName = rk.GetValue("productName").ToString();
string servicePack = rk.GetValue("CSDVersion").ToString();
byte[] digitalProductId = registry.GetValue("DigitalProductId") as byte[];
string osProductKey = DecodeProductKey(digitalProductId);
De Geeks With Blogs para obtener las claves de producto:
public static string DecodeProductKey(byte[] digitalProductId)
{
// Offset of first byte of encoded product key in
// 'DigitalProductIdxxx" REG_BINARY value. Offset = 34H.
const int keyStartIndex = 52;
// Offset of last byte of encoded product key in
// 'DigitalProductIdxxx" REG_BINARY value. Offset = 43H.
const int keyEndIndex = keyStartIndex + 15;
// Possible alpha-numeric characters in product key.
char[] digits = new char[]
{
'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R',
'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9',
};
// Length of decoded product key
const int decodeLength = 29;
// Length of decoded product key in byte-form.
// Each byte represents 2 chars.
const int decodeStringLength = 15;
// Array of containing the decoded product key.
char[] decodedChars = new char[decodeLength];
// Extract byte 52 to 67 inclusive.
ArrayList hexPid = new ArrayList();
for (int i = keyStartIndex; i <= keyEndIndex; i++)
{
hexPid.Add(digitalProductId[i]);
}
for (int i = decodeLength - 1; i >= 0; i--)
{
// Every sixth char is a separator.
if ((i + 1) % 6 == 0)
{
decodedChars[i] = '-';
}
else
{
// Do the actual decoding.
int digitMapIndex = 0;
for (int j = decodeStringLength - 1; j >= 0; j--)
{
int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
hexPid[j] = (byte)(byteValue/24);
digitMapIndex = byteValue % 24;
decodedChars[i] = digits[digitMapIndex];
}
}
}
return new string(decodedChars);
}
que obtiene los duros a cabo del camino. El punto es que el registro es tu amigo.
BTW, C# normalmente no se denomina 'script' –
Evan - No he intentado nada todavía – dps123
@MitchWheat C# Script es algo separado de C#. Extensión de archivo '.csx', ejecutable por' csi.exe' incluido con versiones recientes de Visual Studio. –