API SetComputerName fonctionne a moitié
Bonjour,
Voilà, pour faire bref j'ai une application qui tien un textbox et un bouton.
Lors du clique sur le bouton, le logiciel est sensé changé le nom du PC par la valeur qui se trouve dans textbox.Text ...
Seulement, il le fait mais a moitié, je vous explique :
- Le nom est bien changé pour %COMPUTERNAME% ( variable d'environement )
- Le nom est bien changé dans HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName
- Le nom est bien changé dans HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName
Par contre lorsque je fais Propriété systeme > Nom de l'ordinateur > La il n'est pas changé???
Mais pourquoi???
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Runtime.InteropServices;
namespace CLSInstaller
{
public partial class MainForm : Form
{
[DllImport("kernel32.dll")]
static extern bool SetComputerName(string lpComputerName);
enum COMPUTER_NAME_FORMAT
{
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
}
public MainForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Application des paramètres régionaux...
RegistryKey cle = Registry.CurrentUser.OpenSubKey(@"Control Panel\International", true);
cle.SetValue("sShortDate", "dd/MM/yyyy");
cle.SetValue("sTimeFormat", "HH:mm:ss");
cle.Close();
progressBar1.Value = 50;
// Application du nom de L'ordianteur...
string ComptNm = textBox1.Text;
bool done = SetComputerName(ComptNm);
if (done)
{
Console.WriteLine("Done");
}
progressBar1.Value = 100;
}
}
} |