Skip to content

Commit

Permalink
Skip notifying user in hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbob committed Jul 12, 2015
1 parent c6ff2cb commit a7708ea
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 30 deletions.
Binary file not shown.
Binary file modified FOGService.v12.suo
Binary file not shown.
Binary file not shown.
41 changes: 11 additions & 30 deletions Modules/HostnameChanger/HostnameChanger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ namespace FOG.Modules.HostnameChanger
/// </summary>
public class HostnameChanger : AbstractModule
{
private bool _notifiedUser;

private readonly Dictionary<int, string> _returnCodes = new Dictionary<int, string>
{
{0, "Success"},
Expand Down Expand Up @@ -75,7 +73,6 @@ private static extern int NetUnjoinDomain(string lpServer, string lpAccount, str
public HostnameChanger()
{
Name = "HostnameChanger";
_notifiedUser = false;
}

protected override void DoWork()
Expand Down Expand Up @@ -118,36 +115,20 @@ private void RenameComputer(Response response)

Log.Entry(Name, string.Format("Renaming host to {0}", response.GetField("#hostname")));

if (!UserHandler.IsUserLoggedIn() || response.GetField("#force").Equals("1"))
{
Log.Entry(Name, "Unregistering computer");
//First unjoin it from active directory
UnRegisterComputer(response);

Log.Entry(Name, "Updating registry");

RegistryHandler.SetRegistryValue(@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters","NV Hostname",
response.GetField("#hostname"));
RegistryHandler.SetRegistryValue(@"SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName",
response.GetField("#hostname"));
RegistryHandler.SetRegistryValue(@"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName",
response.GetField("#hostname"));
Log.Entry(Name, "Unregistering computer");
//First unjoin it from active directory
UnRegisterComputer(response);

Power.Restart(RegistryHandler.GetSystemSetting("Company") + " needs to rename your computer", Power.FormOption.Delay);
}
else if(!_notifiedUser)
{
Log.Entry(Name, "User is currently logged in, will try again later");
Log.Entry(Name, "Updating registry");

var notification = new Notification("Please log off",
string.Format(
"{0} is attemping to service your computer, please log off at the soonest available time",
RegistryHandler.GetSystemSetting("Company")), 120);
RegistryHandler.SetRegistryValue(@"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters","NV Hostname",
response.GetField("#hostname"));
RegistryHandler.SetRegistryValue(@"SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName", "ComputerName",
response.GetField("#hostname"));
RegistryHandler.SetRegistryValue(@"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName",
response.GetField("#hostname"));

Bus.Emit(Bus.Channel.Notification, notification.GetJson(), true);

_notifiedUser = true;
}
Power.Restart(RegistryHandler.GetSystemSetting("Company") + " needs to rename your computer", Power.FormOption.Delay);
}

//Add a host to active directory
Expand Down
Binary file modified Modules/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Service/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
Binary file modified Tray/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit a7708ea

Please sign in to comment.