-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_to_mail_win_10.ps1
138 lines (132 loc) · 3.78 KB
/
key_to_mail_win_10.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#Main function
[string]$value="is empty"
Function GetWin10Key
{
$Hklm = 2147483650
$Target = $env:COMPUTERNAME
$regPath = "Software\Microsoft\Windows NT\CurrentVersion"
$DigitalID = "DigitalProductId"
$wmi = [WMIClass]"\\$Target\root\default:stdRegProv"
#Get registry value
$Object = $wmi.GetBinaryValue($hklm,$regPath,$DigitalID)
[Array]$DigitalIDvalue = $Object.uValue
#If get successed
If($DigitalIDvalue)
{
#Get product name and product ID win 10
$ProductName = (Get-itemproperty -Path "HKLM:Software\Microsoft\Windows NT\CurrentVersion" -Name "ProductName").ProductName
#win 11
$OSver=[System.Environment]::OSVersion.Version.Build
If ($OSver -gt 22000){
$ProductName = "Windows 11 Build " + [System.Environment]::OSVersion.Version
}
$ProductID = (Get-itemproperty -Path "HKLM:Software\Microsoft\Windows NT\CurrentVersion" -Name "ProductId").ProductId
#Convert binary value to serial number
$Result = ConvertTokey $DigitalIDvalue
$OSInfo = (Get-WmiObject "Win32_OperatingSystem" | select Caption).Caption
if($Result)
{
$COMPUTERNAME = $env:COMPUTERNAME
$COMPUTERNAME_FQDN=[System.Net.Dns]::GetHostByName($env:computerName).HostName
$OEM_Key = (Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey
$Global:value ="
COMPUTERNAME : $COMPUTERNAME
COMPUTERNAME_FQDN: $COMPUTERNAME_FQDN
ProductName : $ProductName
ProductID : $ProductID
Installed Key : $Result
OEM Key : $OEM_Key
"
$Global:value
}
Else
{
Write-Warning "Çàïóñêàéòå ñêðèïò â Windows 10-11"
}
}
Else
{
Write-Warning "Âîçíèêëà îøèáêà, íå óäàëîñü ïîëó÷èòü êëþ÷"
}
}
#Convert binary to serial number
Function ConvertToKey($Key)
{
$Keyoffset = 52
$isWin10 = [int]($Key[66]/6) -band 1
$HF7 = 0xF7
$Key[66] = ($Key[66] -band $HF7) -bOr (($isWin10 -band 2) * 4)
$i = 24
[String]$Chars = "BCDFGHJKMPQRTVWXY2346789"
do
{
$Cur = 0
$X = 14
Do
{
$Cur = $Cur * 256
$Cur = $Key[$X + $Keyoffset] + $Cur
$Key[$X + $Keyoffset] = [math]::Floor([double]($Cur/24))
$Cur = $Cur % 24
$X = $X - 1
}while($X -ge 0)
$i = $i- 1
$KeyOutput = $Chars.SubString($Cur,1) + $KeyOutput
$last = $Cur
}while($i -ge 0)
$Keypart1 = $KeyOutput.SubString(1,$last)
$Keypart2 = $KeyOutput.Substring(1,$KeyOutput.length-1)
if($last -eq 0 )
{
$KeyOutput = "N" + $Keypart2
}
else
{
$KeyOutput = $Keypart2.Insert($Keypart2.IndexOf($Keypart1)+$Keypart1.length,"N")
}
$a = $KeyOutput.Substring(0,5)
$b = $KeyOutput.substring(5,5)
$c = $KeyOutput.substring(10,5)
$d = $KeyOutput.substring(15,5)
$e = $KeyOutput.substring(20,5)
$keyproduct = $a + "-" + $b + "-"+ $c + "-"+ $d + "-"+ $e
$keyproduct
}
GetWin10Key
$Username = "Xerox";
$Password = "khFy7g3F";
function Send-ToEmail([string]$email)
{
$message = new-object Net.Mail.MailMessage;
$message.From = "[email protected]";
$message.To.Add($email);
$COMPUTERNAME_FQDN=[System.Net.Dns]::GetHostByName($env:computerName).HostName
$message.Subject = "Windows Key from "+ $COMPUTERNAME_FQDN;
$message.Body = "$Global:value";
$smtp = new-object Net.Mail.SmtpClient("mail.ulba.kz", "25");
$smtp.EnableSSL = $false;
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message);
write-host "Mail Sent to "+ $message.To;
sleep 1
$message.Dispose();
}
write-host "----------------------------------------"
write-host ""
write-host ""
$ex=read-host
if ($ex -eq "1" -or $ex -eq "2" ) {
write-host "Âûïîëíÿþ ôóíêöèþ:"
}
elseif ([string]::IsNullOrEmpty($ex)) {
write-host "Âû óêàçàëè íåâåðíûé ïàðàìåòð."
break;
}
switch ($ex){
"1"{Send-ToEmail -email "[email protected]";}
Default
{
Send-ToEmail -email "[email protected]";
write-host "Ðåøåíî çà âàñ"
}
}