-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_to_mail_win_7_8.ps1
118 lines (103 loc) · 3.57 KB
/
key_to_mail_win_7_8.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
[string]$value="is empty"
function Get-WindowsKey
{
## function to retrieve the Windows Product Key from any PC
## by Jakob Bindslet (*** Email address is removed for privacy ***)
param ($targets = “.”)
$hklm = 2147483650
$regPath = “Software\Microsoft\Windows NT\CurrentVersion”
$regValue = “DigitalProductId”
Foreach ($target in $targets)
{
$productKey = $null
$win32os = $null
$wmi = [WMIClass]”\\$target\root\default:stdRegProv”
$data = $wmi.GetBinaryValue($hklm,$regPath,$regValue)
$binArray = ($data.uValue)[52..66]
$charsArray = “B”,”C”,”D”,”F”,”G”,”H”,”J”,”K”,”M”,”P”,”Q”,”R”,”T”,”V”,”W”,”X”,”Y”,”2”,”3”,”4”,”6”,”7”,”8”,”9”
## decrypt base24 encoded binary data
For ($i = 24; $i -ge 0; $i--)
{
$k = 0
For ($j = 14; $j -ge 0; $j--) {
$k = $k * 256 -bxor $binArray[$j]
$binArray[$j] = [math]::truncate($k / 24)
$k = $k % 24
}
$productKey = $charsArray[$k] + $productKey
If (($i % 5 -eq 0) -and ($i -ne 0))
{
$productKey = “-” + $productKey
}
}
$win32os = Get-WmiObject Win32_OperatingSystem -computer $target
$obj = New-Object Object
$obj | Add-Member Noteproperty Computer -value $target
$obj | Add-Member Noteproperty Caption -value $win32os.Caption
$obj | Add-Member Noteproperty CSDVersion -value $win32os.CSDVersion
$obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture
$obj | Add-Member Noteproperty BuildNumber -value $win32os.BuildNumber
$obj | Add-Member Noteproperty RegisteredTo -value $win32os.RegisteredUser
$obj | Add-Member Noteproperty ProductID -value $win32os.SerialNumber
$obj | Add-Member Noteproperty ProductKey -value $productkey
$obj
write-host ""
write-host "----------------------------------------"
write-host "Global"
$COMPUTERNAME = $env:COMPUTERNAME
$COMPUTERNAME_FQDN=[System.Net.Dns]::GetHostByName($env:computerName).HostName
$Global:value ="
COMPUTERNAME : $COMPUTERNAME
COMPUTERNAME_FQDN: $COMPUTERNAME_FQDN
ProductName : "+$win32os.Caption+"
CSDVersion : "+$win32os.CSDVersion+"
ProductID : "+$win32os.SerialNumber+"
Installed Key : $productkey
"
$Global:value
}}
write-host ""
write-host "----------------------------------------"
write-host ""
Get-WindowsKey
sleep 1
$Username = "SarmurzanovDA";
$Password = "fmkk9RFUJK";
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 "email"
write-host $Global:value.ToString()
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]";}
"2"{Send-ToEmail -email "[email protected]";}
Default
{
Send-ToEmail -email "[email protected]";
write-host "Решено за вас, отправляем по адресу [email protected]"
}
}