-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriverinstall.psm1
240 lines (191 loc) · 7.09 KB
/
driverinstall.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
function driverinstall ([string]$para1,[string]$para2,[string]$para3,[string]$para4,[string]$para5){
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
$wshell=New-Object -ComObject wscript.shell
$shell=New-Object -ComObject shell.application
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
$drivertype=$para1
$drvfile=$para2
$cmdline=$para3
$cmdtype=$para4
$nonlogflag=$para5
$cSource = @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Clicker
{
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646270(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
public int type; // 0 = INPUT_MOUSE,
// 1 = INPUT_KEYBOARD
// 2 = INPUT_HARDWARE
public MOUSEINPUT mi;
}
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646273(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
public int dx ;
public int dy ;
public int mouseData ;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
//This covers most use cases although complex mice may have additional buttons
//There are additional constants you can use for those cases, see the msdn page
const int MOUSEEVENTF_MOVED = 0x0001 ;
const int MOUSEEVENTF_LEFTDOWN = 0x0002 ;
const int MOUSEEVENTF_LEFTUP = 0x0004 ;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008 ;
const int MOUSEEVENTF_RIGHTUP = 0x0010 ;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
const int MOUSEEVENTF_MIDDLEUP = 0x0040 ;
const int MOUSEEVENTF_WHEEL = 0x0080 ;
const int MOUSEEVENTF_XDOWN = 0x0100 ;
const int MOUSEEVENTF_XUP = 0x0200 ;
const int MOUSEEVENTF_ABSOLUTE = 0x8000 ;
const int screen_length = 0x10000 ;
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
public static void LeftClickAtPoint(int x, int y)
{
//Move the mouse
INPUT[] input = new INPUT[3];
input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
//Left mouse button down
input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
//Left mouse button up
input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, input, Marshal.SizeOf(input[0]));
}
}
'@
Add-Type -TypeDefinition $cSource -ReferencedAssemblies System.Windows.Forms,System.Drawing
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules"
}
else{
$scriptRoot=$PSScriptRoot
}
$tcpath=(Split-Path -Parent $scriptRoot)+"\currentjob\TC.txt"
$tcnumber=((get-content $tcpath).split(","))[0]
$tcstep=((get-content $tcpath).split(","))[1]
$action=((get-content $tcpath).split(","))[2]
$picpath=(Split-Path -Parent $scriptRoot)+"\logs\$($tcnumber)\"
if(-not(test-path $picpath)){new-item -ItemType directory -path $picpath |out-null}
$logpath=(Split-Path -Parent $scriptRoot)+"\logs\$($tcnumber)\step$($tcstep)_cmdresult.txt"
$actionmd="screenshot"
Get-Module -name $actionmd|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionmd\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
$checkcudap=$false
if($drvfile -match "cuda"){
$checkcudap=test-path "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v*\extras\demo_suite"
}
if($checkcudap -eq 0){
if($cmdline.length -ne 0){
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
$wshell=New-Object -ComObject wscript.shell
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
### if zip need uninstall ###
if($drvfile -match "\.zip"){
$drivername= (Get-ChildItem $scriptRoot\driver\$drivertype\ -Recurse -File|where{$_.name -eq $drvfile}).FullName
$zipf=(Get-ChildItem $scriptRoot\driver\$drivertype\ -Recurse -File|where{$_.name -eq $drvfile}).BaseName
$driverfolder= "$scriptRoot\driver\$drivertype\$zipf\"
if(-not(Test-Path $driverfolder)){new-item -ItemType directory $driverfolder -Force|out-null}
$shell.NameSpace("$scriptRoot\driver\$drivertype\$zipf\").copyhere($shell.NameSpace($drivername).Items(),16)
}
else{
$driverfullname= (Get-ChildItem $scriptRoot\driver\$drivertype\ -Recurse -File|where{$_.name -eq $drvfile}).FullName
$driverfolder= split-path -Parent $driverfullname
}
#### cmd / powershell ##
write-host $driverfolder
set-location $driverfolder
if($cmdtype.Length -ne 0){
if($cmdtype -match "cmd"){
start-process cmd -WindowStyle Maximized
}
if($cmdtype -match "powershell"){
start-process "$PSHOME\powershell.exe" -WindowStyle Maximized
}
Start-Sleep -Seconds 5
$id2= (Get-Process -name $cmdtype|sort StartTime -ea SilentlyContinue |select -last 1).id
$cmdwindowhd=(Get-Process -name $cmdtype |sort StartTime -ea SilentlyContinue |select -last 1).MainWindowHandle
### click cmd window ###
Set-Clipboard -value $cmdline
Start-Sleep -Seconds 5
[Microsoft.VisualBasic.interaction]::AppActivate($id2)|out-null
start-sleep -s 2
[Clicker]::LeftClickAtPoint(50, 1)
Start-Sleep -Seconds 2
$wshell.SendKeys("~")
Start-Sleep -Seconds 2
$wshell.SendKeys("^v")
Start-Sleep -Seconds 2
$wshell.SendKeys("~")
Start-Sleep -Seconds 3
### copy text in window ###
do{
start-sleep -s 2
[Microsoft.VisualBasic.interaction]::AppActivate($id2)|out-null
start-sleep -s 1
[Clicker]::LeftClickAtPoint(1,1)
$wshell.SendKeys("E")
start-sleep -s 1
$wshell.SendKeys("S")
start-sleep -s 1
$wshell.SendKeys("~")
start-sleep -s 1
$index=Get-Clipboard
start-sleep -s 2
$checkend=$index[-1]
if($checkend.length -gt 0){$endcheck=$checkend.Substring($checkend.length-1,1)}
else{$endcheck=""}
}until($endcheck -eq ">" -and $checkend.length -gt 0 )
## screenshot ##
&$actionmd -para3 nonlog
start-sleep -s 1
taskkill /PID $id2 /F
### check exe finished ##
$exefile=($cmdline -split".exe")[0]
do{
Start-Sleep -s 10
$exerun=((get-process -Name $exefile -ea SilentlyContinue).Id).count
}until($exerun -eq 0)
###>
}
set-content $logpath -Value $index
$results="-"
$index="check $logpath"
}
if($cmdline.Length -eq 0){
$results="NG"
$index="No command line is found"
}
}
else{
$results="na"
$index="Cuda is installed"
}
######### write log #######
if( $nonlogflag.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 driverinstall