Click here to Skip to main content
       

C#

 
AnswerRe: Binary File Library PinmemberGarth J Lancaster11-Jan-13 11:18 
GeneralRe: Binary File Library Pinmemberdxtrx11-Jan-13 11:41 
GeneralRe: Binary File Library PinmemberGarth J Lancaster11-Jan-13 12:43 
GeneralRe: Binary File Library Pinmemberdxtrx11-Jan-13 12:47 
QuestionLatency In Button Click When Using MVVM PinmemberTee12311-Jan-13 7:25 
AnswerRe: Latency In Button Click When Using MVVM PinmemberSledgeHammer0111-Jan-13 9:38 
GeneralRe: Latency In Button Click When Using MVVM PinmemberTee12311-Jan-13 10:14 
QuestionC# computer name rename PinmemberEvetsMostel11-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 Pinmemberjibesh11-Jan-13 7:47 
GeneralRe: C# computer name rename [modified] PinmemberEvetsMostel11-Jan-13 7:54 
GeneralRe: C# computer name rename PinmemberEvetsMostel11-Jan-13 11:30 
GeneralRe: C# computer name rename PinmemberEvetsMostel14-Jan-13 13:15 
QuestionFTP Decryption Error PinmemberMember 865395910-Jan-13 18:22 
AnswerRe: FTP Decryption Error PinmemberBernhard Hiller10-Jan-13 21:46 
GeneralRe: FTP Decryption Error PinmemberGarth J Lancaster11-Jan-13 11:00 
AnswerRe: FTP Decryption Error PinmvpEddy Vluggen11-Jan-13 2:28 
GeneralRe: FTP Decryption Error PinmemberGarth J Lancaster11-Jan-13 11:00 
Questionhow to export a div to pdf Pinmembershineskollam10-Jan-13 18:17 
AnswerRe: how to export a div to pdf PinmvpRichard MacCutchan10-Jan-13 21:51 
QuestionRegarding implementation of Dependency Injection with C# PinmemberTridip Bhattacharjee10-Jan-13 2:06 
AnswerRe: Regarding implementation of Dependency Injection with C# PinprotectorPete O'Hanlon10-Jan-13 2:22 
AnswerRe: Regarding implementation of Dependency Injection with C# Pinmemberjschell10-Jan-13 14:03 
AnswerRe: Regarding implementation of Dependency Injection with C# PinmemberSledgeHammer0110-Jan-13 14:57 
GeneralRe: Regarding implementation of Dependency Injection with C# PinmemberTridip Bhattacharjee10-Jan-13 20:07 
GeneralRe: Regarding implementation of Dependency Injection with C# PinprotectorPete O'Hanlon10-Jan-13 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web04 | 2.8.140827.1 | Last Updated 31 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid