-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchangescale.psm1
189 lines (134 loc) · 5.56 KB
/
changescale.psm1
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
function changescale ([int]$para1,[string]$para2,[string]$para3){
Add-Type -AssemblyName System.Windows.Forms
#default
# Posted by IanXue-MSFT on
# https://learn.microsoft.com/en-us/answers/questions/197944/batch-file-or-tool-like-powertoy-to-change-the-res.html
# $scaling = 0 : 100% (default)
# $scaling = 1 : 125%
# $scaling = 2 : 150%
# $scaling = 3 : 175%
# etc....
$paracheck1=$PSBoundParameters.ContainsKey('para1')
if($paracheck1 -eq $false -or $para1 -eq 0){
$para1=125
}
$scaleset=$para1
$recoverflag=$para2
$nonlog_flag=$para3
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules"
}else{
$scriptRoot=$PSScriptRoot
}
$action="changescales - $scaleset"
$tcpath=(Split-Path -Parent $scriptRoot)+"\currentjob\TC.txt"
$tcnumber=((get-content $tcpath).split(","))[0]
$tcstep=((get-content $tcpath).split(","))[1]
#region import screenshot functino
$actionss ="screenshot"
Get-Module -name $actionss|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionss\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
#endregion
$dpisets=@(96,120,144,168)
$sclsets=@(100,125,150,175)
$dpirec=(Get-ItemProperty -Path "HKCU:\Control Panel\Desktop\WindowMetrics" -Name AppliedDPI).AppliedDPI
$oriscls= $sclsets[$dpisets.indexof($dpirec)]
$maindisplay=(((Get-WmiObject win32_desktopmonitor)[0].PNPDeviceID).split("\"))[1]
function scaleset ([int]$scaleset){
$indexto=$sclsets.indexof($scaleset)
$checkrecommand=(Get-ChildItem -Path "HKCU:\Control Panel\Desktop\" | Select-Object Name).name -like '*PerMonitorSettings*'
$dpirec=(Get-ItemProperty -Path "HKCU:\Control Panel\Desktop\WindowMetrics" -Name AppliedDPI).AppliedDPI
$indexfrom=$dpisets.indexof($dpirec)
$oriscls= $sclsets[$dpisets.indexof($dpirec)]
if($checkrecommand){
#$dpifrom=(Get-ItemProperty -Path "HKCU:\Control Panel\Desktop\PerMonitorSettings\*" -Name DpiValue).DpiValue
$dpifrom=(Get-ItemProperty -Path "HKCU:\Control Panel\Desktop\PerMonitorSettings\*$maindisplay*" -Name DpiValue).DpiValue
}
else{
$dpifrom=0
}
if($dpifrom -eq 4294967294){$dpifrom = -2 }
if($dpifrom -eq 4294967295){$dpifrom = -1 }
$indexref=$indexto-$indexfrom+$dpifrom
if($indexref -eq -1){$indexref=4294967295}
if($indexref -eq -2){$indexref=4294967294}
write-host "$oriscls (DPI:$dpirec) change to $scaleset with indexref:$indexref"
start-process explorer "ms-settings:display"
Start-Sleep -s 5
[System.Windows.Forms.SendKeys]::SendWait("% ")
Start-Sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("x")
# screenshot before#
&$actionss -para3 nonlog -para5 "scalesetting_before1"
Start-Sleep -s 1
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
start-Sleep -s 1
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
Start-Sleep -s 1
&$actionss -para3 nonlog -para5 "scalesetting_before2"
(get-process ApplicationFrameHost|sort starttime|select -Last 1).closemainwindow()
$source = @'
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(
uint uiAction,
uint uiParam,
uint pvParam,
uint fWinIni);
'@
$apicall = Add-Type -MemberDefinition $source -Name WinAPICall -Namespace SystemParamInfo -PassThru
$apicall::SystemParametersInfo(0x009F, $indexref , $null, 1) | Out-Null
Start-Sleep -s 10
Stop-Process -Name explorer
Start-Sleep -s 30
start-process explorer "ms-settings:display"
Start-Sleep -s 5
[System.Windows.Forms.SendKeys]::SendWait("% ")
Start-Sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("x")
# Start-Sleep -s 2
# [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
# Start-Sleep -s 5
# [System.Windows.Forms.SendKeys]::SendWait("{TAB 15}")
# [System.Windows.Forms.SendKeys]::SendWait("{DOWN 10}")
# screenshot #
&$actionss -para3 nonlog -para5 "scalesetting_after1"
Start-Sleep -s 1
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
start-Sleep -s 1
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
Start-Sleep -s 1
&$actionss -para3 nonlog -para5 "scalesetting_after2"
(get-process ApplicationFrameHost|sort starttime|select -Last 1).closemainwindow()
Start-Sleep -s 5
### check ###
$dpiafter=(Get-ItemProperty -Path "HKCU:\Control Panel\Desktop\PerMonitorSettings\*$maindisplay*" -Name DpiValue).DpiValue
$sacleafter= $sclsets[$dpisets.IndexOf($dpiafter)]
if($sacleafter -eq $scaleset){
$results = "Pass"
}
else{
$results = "NG"
}
$results
}
#region change
$results1=scaleset $scaleset
#endregion change
$results=$results1[-1]
#region recover
if($recoverflag.length -gt 0){
$results2=scaleset $oriscls
$results=[string]::Join(";",$results1[-1], $results2[-1])
}
#endregion recover
$index="check screenshots"
if($nonlog_flag.Length -eq 0){
Get-Module -name "outlog"|remove-module
$mdpath=(Get-ChildItem -path "C:\testing_AI\modules\" -r -file |Where-object{$_.name -match "outlog" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
#write-host "Do $action!"
outlog $action $results $tcnumber $tcstep $index
}
}
Export-ModuleMember -Function changescale