Skip to content

Commit

Permalink
Merge pull request #2041 from appveyor/fix-rdp-pwd
Browse files Browse the repository at this point in the history
Fix RDP password set
  • Loading branch information
FeodorFitsner authored Jan 18, 2018
2 parents f2670e9 + 1d4abc1 commit 77796f5
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions scripts/enable-rdp.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
function ChangePassword($password) {
$objUser = [ADSI]("WinNT://$($env:computername)/appveyor")
$objUser.SetPassword($password)
$objUser.CommitChanges()
}

function ValidatePassword($password) {
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$env:computername)
$DS.ValidateCredentials("appveyor", $password)
}

# get current IP
$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.InterfaceAlias -like 'ethernet*'}).IPAddress
$port = 3389
Expand All @@ -8,10 +20,16 @@ if($env:appveyor_rdp_password) {
# take from environment variable
$password = $env:appveyor_rdp_password

# change password
$objUser = [ADSI]("WinNT://$($env:computername)/appveyor")
$objUser.SetPassword($password)
$objUser.CommitChanges()
# change password. Best effort to ensure password change applied.
$count = 0
$valid = $false
do {
for ($i=0; $i -le 3; $i++) {ChangePassword($password); Start-Sleep -Milliseconds 100}
$valid = ValidatePassword($password)
$count++
if(!$valid) {Start-Sleep -Milliseconds 100}
} while(!$valid -and ($count -lt 3))

[Microsoft.Win32.Registry]::SetValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", $password)
} else {
# get existing password
Expand Down

0 comments on commit 77796f5

Please sign in to comment.