Ejemplo n.º 1
0
 void DumpOsData()
 {
     osname.value      = (string)WmiBase.Singleton.Win32_OperatingSystem["Name"];
     hostname.value    = (string)WmiBase.Singleton.Win32_ComputerSystem["Name"];
     hostnamedns.value = Win32Impl.GetComputerDnsHostname();
     domain.value      = (string)WmiBase.Singleton.Win32_ComputerSystem["Domain"];
 }
Ejemplo n.º 2
0
        void SetComputerName()
        {
            wmisession.Log("Set Computer Name Requested");
            state.value = "InProgress";
            String defaultname;
            bool   res;

            try {
                defaultname = name.value;
                name.Remove();
            }
            catch {
                try {
                    wmisession.Log("Setting computer name to default");
                    XenStoreItem name = wmisession.GetXenStoreItem("name");
                    defaultname = name.value;
                }
                catch (Exception e) {
                    wmisession.Log("Unable to read default name for domain from xenstore: " + e.ToString());
                    error.value = "Can't read default computer name";
                    state.value = "Failed";
                    return;
                }
            }

            if (defaultname.Equals(""))
            {
                wmisession.Log("Can't set to empty computer name");
                error.value = "Computer name empty";
                state.value = "Failed";
                return;
            }

            if (defaultname.Length > Win32Impl.MAX_COMPUTERNAME_LENGTH)
            {
                warn.value = "Computer name exceeds MAX_COMPUTERNAME_LENGTH.  The NetBIOS name will be truncated";
            }

            try
            {
                wmisession.Log("Setting computer name to " + defaultname);
                Win32Impl.SetLastError(0);
                res = Win32Impl.SetComputerNameEx(Win32Impl.COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, defaultname);
                if (!res)
                {
                    wmisession.Log("Setting computer name failed " + Marshal.GetLastWin32Error().ToString());
                    error.value = "Setting name failed (error code " + Marshal.GetLastWin32Error().ToString() + ")";
                    state.value = "Failed";
                    return;
                }
                wmisession.Log("Setting computer name succceded");
            }
            catch (Exception e)
            {
                wmisession.Log("Exception setting computer name : " + e.ToString());
                error.value = "Exception calling set computer name";
                state.value = "Failed";
                return;
            }
            try
            {
                wmisession.Log("Target hostname " + defaultname);
                wmisession.Log("Current hostname" + Win32Impl.GetComputerDnsHostname());
                if (defaultname.Equals(Win32Impl.GetComputerDnsHostname()))
                {
                    wmisession.Log("No need to reboot to change computer name, already " + defaultname);
                    state.value = "NoChange";
                    return;
                }
            }
            catch {
            }
            state.value = "SucceededNeedsReboot";
        }