Revert "Rename Windows guest without reboot"
This commit is contained in:
parent
6378deacd6
commit
7784ee2d09
|
@ -12,32 +12,14 @@ module VagrantPlugins
|
||||||
# We cannot use %ComputerName% because it truncates at 15 chars
|
# We cannot use %ComputerName% because it truncates at 15 chars
|
||||||
return if machine.communicate.test("if ([System.Net.Dns]::GetHostName() -eq '#{name}') { exit 0 } exit 1")
|
return if machine.communicate.test("if ([System.Net.Dns]::GetHostName() -eq '#{name}') { exit 0 } exit 1")
|
||||||
|
|
||||||
|
# Rename and reboot host if rename succeeded
|
||||||
script = <<-EOH
|
script = <<-EOH
|
||||||
try
|
$computer = Get-WmiObject -Class Win32_ComputerSystem
|
||||||
{
|
$retval = $computer.rename("#{name}").returnvalue
|
||||||
$computer = Get-WmiObject -Class Win32_ComputerSystem
|
if ($retval -eq 0) {
|
||||||
$computer.rename("#{name}")
|
shutdown /r /t 5 /f /d p:4:1 /c "Vagrant Rename Computer"
|
||||||
|
|
||||||
Remove-ItemProperty -path "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" -name "Hostname"
|
|
||||||
Remove-ItemProperty -path "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" -name "NV Hostname"
|
|
||||||
|
|
||||||
New-PSDrive -name HKU -PSProvider "Registry" -Root "HKEY_USERS"
|
|
||||||
|
|
||||||
Set-ItemProperty -path "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Computername\\Computername" -name "Computername" -value "#{name}"
|
|
||||||
Set-ItemProperty -path "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Computername\\ActiveComputername" -name "Computername" -value "#{name}"
|
|
||||||
Set-ItemProperty -path "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" -name "Hostname" -value "#{name}"
|
|
||||||
Set-ItemProperty -path "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" -name "NV Hostname" -value "#{name}"
|
|
||||||
Set-ItemProperty -path "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" -name "AltDefaultDomainName" -value "#{name}"
|
|
||||||
Set-ItemProperty -path "HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon" -name "DefaultDomainName" -value "#{name}"
|
|
||||||
Set-ItemProperty -path "HKCU:\\Volatile Environment" -name "LOGONSERVER" -value "#{name}"
|
|
||||||
[Environment]::SetEnvironmentVariable("COMPUTERNAME", "#{name}", "User")
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
exit -1
|
|
||||||
}
|
}
|
||||||
|
exit $retval
|
||||||
EOH
|
EOH
|
||||||
|
|
||||||
machine.communicate.execute(
|
machine.communicate.execute(
|
||||||
|
|
Loading…
Reference in New Issue