kernel32

rename computer programmatically c# .net

走远了吗. 提交于 2019-11-29 13:46:12
I need to rename my computer via .net application. I have tried this code: public static bool SetMachineName(string newName) { MessageBox.Show(String.Format("Setting Machine Name to '{0}'...", newName)); // Invoke WMI to populate the machine name using (ManagementObject wmiObject = new ManagementObject(new ManagementPath(String.Format("Win32_ComputerSystem.Name='{0}'",System.Environment.MachineName)))) { ManagementBaseObject inputArgs = wmiObject.GetMethodParameters("Rename"); inputArgs["Name"] = newName; // Set the name ManagementBaseObject outParams = wmiObject.InvokeMethod("Rename"

Do I need to pin an anonymous delegate?

风流意气都作罢 提交于 2019-11-29 13:41:19
I am calling CopyFileEx from a C# application with an anonymous delegate being passed into the LPPROGRESS_ROUTINE parameter in order to get notifications on the file copy progress. My question is, does the anonymous delegate need to be pinned and why (or why not). In addition, does the answer change if: CopyFileEx was not blocking. If I passed in a delegate that was not anonymous. Thanks! The delegate does not need to be pinned . A managed object is pinned if it cannot be moved by the garbage collector. If the marshalling information is correct then the marshalling layer will ensure that a

rename computer programmatically c# .net

假装没事ソ 提交于 2019-11-28 07:19:35
问题 I need to rename my computer via .net application. I have tried this code: public static bool SetMachineName(string newName) { MessageBox.Show(String.Format("Setting Machine Name to '{0}'...", newName)); // Invoke WMI to populate the machine name using (ManagementObject wmiObject = new ManagementObject(new ManagementPath(String.Format("Win32_ComputerSystem.Name='{0}'",System.Environment.MachineName)))) { ManagementBaseObject inputArgs = wmiObject.GetMethodParameters("Rename"); inputArgs["Name