I try to change the hostname via kernel32.dll import and the function SetComputerName. SetComputerName function
Mainclass:
namespace Castell
{
class Program
{
private static string hostname { get; set; }
setHostname();
private static void setHostname()
{
hostname = "TEST123456789";
int errorcode = ImportDLL.SetComputerName(hostname);
Console.WriteLine(Marshal.GetLastWin32Error());
}
}
}
Import Class:
namespace Castell
{
class ImportDLL
{
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int SetComputerName(string hostname);
}
}
Result of the Marshal.GetLastWin32Error() is "6". So that means: ERROR_INVALID_HANDLE 6 (0x6) The handle is invalid.
Dont know whats wrong with the handle.