Click here to Skip to main content
12,394,573 members (79,708 online)
   

C#

 
AnswerRe: Binary File Library Pin
Garth J Lancaster11-Jan-13 11:18
memberGarth J Lancaster11-Jan-13 11:18 
GeneralRe: Binary File Library Pin
dxtrx11-Jan-13 11:41
memberdxtrx11-Jan-13 11:41 
GeneralRe: Binary File Library Pin
Garth J Lancaster11-Jan-13 12:43
memberGarth J Lancaster11-Jan-13 12:43 
GeneralRe: Binary File Library Pin
dxtrx11-Jan-13 12:47
memberdxtrx11-Jan-13 12:47 
QuestionLatency In Button Click When Using MVVM Pin
Tee12311-Jan-13 7:25
memberTee12311-Jan-13 7:25 
AnswerRe: Latency In Button Click When Using MVVM Pin
SledgeHammer0111-Jan-13 9:38
memberSledgeHammer0111-Jan-13 9:38 
GeneralRe: Latency In Button Click When Using MVVM Pin
Tee12311-Jan-13 10:14
memberTee12311-Jan-13 10:14 
QuestionC# computer name rename Pin
EvetsMostel11-Jan-13 7:00
memberEvetsMostel11-Jan-13 7:00 
I've been trying to get this method to work. According to others and everything I've read, this should be the answer. As you can see, I've tried different methods and under machines that I don't have permission, I get error code 5 (no permission) but on other machines I get error code 87 (invalid parameter. Please help!

Here's the code:

Boolean SetComputerName(String name)
{
   String RegLocComputerName = @"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName";
   try
   {
       string compPath= "Win32_ComputerSystem.Name='" + System.Environment.MachineName + "'";
       //using (ManagementObject mo = new ManagementObject(new ManagementPath(compPath)))
           //using (ManagementObject mo = new ManagementObject("root\\cimv2",compPath,null))
           //ManagementClass mo = new ManagementClass("Win32_ComputerSystem");
           ManagementObject mo = new ManagementObject(compPath);
           {
           ManagementBaseObject inputArgs = mo.GetMethodParameters("Rename");
           inputArgs["Name"] = name;
           //inputArgs["Password"]=null;
           //inputArgs["UserName"]=null;  // use the current user
           ManagementBaseObject output = mo.InvokeMethod("Rename", inputArgs, null);
           uint retValue = (uint)Convert.ChangeType(output.Properties["ReturnValue"].Value, typeof(uint));
           if (retValue != 0)
           {
               MessageBox.Show(String.Format("Computer could not be changed due to unknown reason. return = {0}",retValue));
               throw new Exception("Computer could not be changed due to unknown reason.");
           }
       }
 
       RegistryKey ComputerName = Registry.LocalMachine.OpenSubKey(RegLocComputerName);
       if (ComputerName == null)
       {
           throw new Exception("Registry location '" + RegLocComputerName + "' is not readable.");
       }
       if (((String)ComputerName.GetValue("ComputerName")) != Name)
       {
           throw new Exception("The computer name was set by WMI but was not updated in the registry location: '" + RegLocComputerName + "'");
       }
       ComputerName.Close();
       ComputerName.Dispose();
   }
   catch (Exception ex)
   {
       return false;
   }
   return true;
}

AnswerRe: C# computer name rename Pin
jibesh11-Jan-13 7:47
memberjibesh11-Jan-13 7:47 
GeneralRe: C# computer name rename Pin
EvetsMostel11-Jan-13 7:54
memberEvetsMostel11-Jan-13 7:54 
GeneralRe: C# computer name rename Pin
EvetsMostel11-Jan-13 11:30
memberEvetsMostel11-Jan-13 11:30 
GeneralRe: C# computer name rename Pin
EvetsMostel14-Jan-13 13:15
memberEvetsMostel14-Jan-13 13:15 
QuestionFTP Decryption Error Pin
Member 865395910-Jan-13 18:22
memberMember 865395910-Jan-13 18:22 
AnswerRe: FTP Decryption Error Pin
Bernhard Hiller10-Jan-13 21:46
memberBernhard Hiller10-Jan-13 21:46 
GeneralRe: FTP Decryption Error Pin
Garth J Lancaster11-Jan-13 11:00
memberGarth J Lancaster11-Jan-13 11:00 
AnswerRe: FTP Decryption Error Pin
Eddy Vluggen11-Jan-13 2:28
mvpEddy Vluggen11-Jan-13 2:28 
GeneralRe: FTP Decryption Error Pin
Garth J Lancaster11-Jan-13 11:00
memberGarth J Lancaster11-Jan-13 11:00 
Questionhow to export a div to pdf Pin
shineskollam10-Jan-13 18:17
membershineskollam10-Jan-13 18:17 
AnswerRe: how to export a div to pdf Pin
Richard MacCutchan10-Jan-13 21:51
mvpRichard MacCutchan10-Jan-13 21:51 
QuestionRegarding implementation of Dependency Injection with C# Pin
Tridip Bhattacharjee10-Jan-13 2:06
memberTridip Bhattacharjee10-Jan-13 2:06 
AnswerRe: Regarding implementation of Dependency Injection with C# Pin
Pete O'Hanlon10-Jan-13 2:22
protectorPete O'Hanlon10-Jan-13 2:22 
AnswerRe: Regarding implementation of Dependency Injection with C# Pin
jschell10-Jan-13 14:03
memberjschell10-Jan-13 14:03 
AnswerRe: Regarding implementation of Dependency Injection with C# Pin
SledgeHammer0110-Jan-13 14:57
memberSledgeHammer0110-Jan-13 14:57 
GeneralRe: Regarding implementation of Dependency Injection with C# Pin
Tridip Bhattacharjee10-Jan-13 20:07
memberTridip Bhattacharjee10-Jan-13 20:07 
GeneralRe: Regarding implementation of Dependency Injection with C# Pin
Pete O'Hanlon10-Jan-13 21:11
protectorPete O'Hanlon10-Jan-13 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 23 Jul 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid