Click here to Skip to main content
   

C#

 
GeneralRe: single log file for two classes. PinmemberGarth J Lancaster11-Jan-13 13:56 
GeneralRe: single log file for two classes. Pinmembervanikanc14-Jan-13 4:00 
AnswerRe: single log file for two classes. PinmemberPIEBALDconsult11-Jan-13 14:26 
GeneralRe: single log file for two classes. Pinmembervanikanc15-Jan-13 3:24 
GeneralRe: single log file for two classes. PinmemberPIEBALDconsult15-Jan-13 4:08 
QuestionBinary File Library Pinmemberdxtrx11-Jan-13 11:24 
AnswerRe: Binary File Library PinmemberGarth J Lancaster11-Jan-13 12:18 
GeneralRe: Binary File Library Pinmemberdxtrx11-Jan-13 12:41 
GeneralRe: Binary File Library PinmemberGarth J Lancaster11-Jan-13 13:43 
GeneralRe: Binary File Library Pinmemberdxtrx11-Jan-13 13:47 
QuestionLatency In Button Click When Using MVVM PinmemberTee12311-Jan-13 8:25 
AnswerRe: Latency In Button Click When Using MVVM PinmemberSledgeHammer0111-Jan-13 10:38 
GeneralRe: Latency In Button Click When Using MVVM PinmemberTee12311-Jan-13 11:14 
QuestionC# computer name rename PinmemberEvetsMostel11-Jan-13 8: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 8:47 
GeneralRe: C# computer name rename [modified] PinmemberEvetsMostel11-Jan-13 8:54 
GeneralRe: C# computer name rename PinmemberEvetsMostel11-Jan-13 12:30 
GeneralRe: C# computer name rename PinmemberEvetsMostel14-Jan-13 14:15 
QuestionFTP Decryption Error PinmemberMember 865395910-Jan-13 19:22 
AnswerRe: FTP Decryption Error PinmemberBernhard Hiller10-Jan-13 22:46 
GeneralRe: FTP Decryption Error PinmemberGarth J Lancaster11-Jan-13 12:00 
AnswerRe: FTP Decryption Error PinmvpEddy Vluggen11-Jan-13 3:28 
GeneralRe: FTP Decryption Error PinmemberGarth J Lancaster11-Jan-13 12:00 
Questionhow to export a div to pdf Pinmembershineskollam10-Jan-13 19:17 
AnswerRe: how to export a div to pdf PinmvpRichard MacCutchan10-Jan-13 22:51 
QuestionRegarding implementation of Dependency Injection with C# PinmemberTridip Bhattacharjee10-Jan-13 3:06 
AnswerRe: Regarding implementation of Dependency Injection with C# PinprotectorPete O'Hanlon10-Jan-13 3:22 
AnswerRe: Regarding implementation of Dependency Injection with C# Pinmemberjschell10-Jan-13 15:03 
AnswerRe: Regarding implementation of Dependency Injection with C# PinmemberSledgeHammer0110-Jan-13 15:57 
GeneralRe: Regarding implementation of Dependency Injection with C# PinmemberTridip Bhattacharjee10-Jan-13 21:07 
GeneralRe: Regarding implementation of Dependency Injection with C# PinprotectorPete O'Hanlon10-Jan-13 22:11 
QuestionHow to draw an arc in winRT with animation? Pinmemberabinashokk9-Jan-13 22:55 
AnswerRe: How to draw an arc in winRT with animation? PinprotectorPete O'Hanlon9-Jan-13 23:34 
QuestionC#.NET 3.5 Code review checklist PinmemberMember 31370789-Jan-13 21:28 
AnswerRe: C#.NET 3.5 Code review checklist PinmvpEddy Vluggen9-Jan-13 23:54 
AnswerRe: C#.NET 3.5 Code review checklist Pinmemberdeflinek10-Jan-13 1:53 
AnswerRe: C#.NET 3.5 Code review checklist Pinmemberjschell10-Jan-13 15:06 
GeneralRe: C#.NET 3.5 Code review checklist PinmemberPIEBALDconsult10-Jan-13 16:16 
GeneralRe: C#.NET 3.5 Code review checklist PinmemberPIEBALDconsult10-Jan-13 15:46 
QuestionSocket programming Pinmembermohammadkaab9-Jan-13 4:32 
AnswerRe: Socket programming PinmvpDave Kreskowiak9-Jan-13 4:38 
GeneralRe: Socket programming Pinmembermohammadkaab9-Jan-13 8:13 
GeneralRe: Socket programming PinmvpDave Kreskowiak9-Jan-13 10:02 
GeneralRe: Socket programming Pinmembermohammadkaab9-Jan-13 10:25 
GeneralRe: Socket programming PinmvpDave Kreskowiak10-Jan-13 3:11 
AnswerRe: Socket programming PinmentorKeith Barrow9-Jan-13 5:15 
GeneralRe: Socket programming Pinmembermohammadkaab9-Jan-13 11:29 
AnswerRe: Socket programming PinmvpRichard MacCutchan9-Jan-13 5:42 
AnswerRe: Socket programming PinprotectorPete O'Hanlon9-Jan-13 6:27 
AnswerRe: Socket programming Pinmemberharold aptroot9-Jan-13 7:14 

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.150129.1 | Last Updated 31 Jan 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid