-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver_uninstall_NVIDIA.psm1
169 lines (115 loc) · 4.22 KB
/
driver_uninstall_NVIDIA.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
function driver_uninstall_NVIDIA ([string]$para1,[string]$para2){
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
$pkgename=$para1
$nonlog_flag=$para2
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules"
}
else{
$scriptRoot=$PSScriptRoot
}
$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
$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}
$timenow=get-date -format "yyMMdd_HHmmss"
$programlistpath=$picpath+"$($timenow)_step$($tcstep)_programslist_before.txt"
$index=@()
if($pkgename.length -ne 0){
$packages = (Get-Package |Where-object{$_.name -like "*$pkgename*"}).name
$controlpn="Control Panel\Programs\Programs and Features"
if($packages.count -ne 0){
## start uninstall ##
$packages = (Get-Package |Where-object{$_.name -like "*$pkgename*"}).name
$packages|Out-File $programlistpath
foreach ($package in $packages){
## screenshot 1st time
Start-Process control -Verb Open -WindowStyle Maximized
start-sleep -s 5
$wshell.SendKeys("% ")
$wshell.SendKeys("x")
start-sleep -s 2
$wshell.SendKeys("^l")
Set-Clipboard $controlpn
Start-Sleep -s 5
$wshell.SendKeys("^v")
Start-Sleep -s 1
$wshell.SendKeys("~")
Start-Sleep -s 10
&$actionss -para3 nonlog -para5 "before_uninstall_$($package)_check"
$shell.Windows() |Where-object{$_.name -eq "File Explorer"}| ForEach-Object { $_.Quit() }
start-sleep -s 5
Start-Process control -Verb Open -WindowStyle Maximized
start-sleep -s 5
$ctlpath="$controlpn\$package"
write-host "uninstall $package"
$wshell.SendKeys("^l")
Set-Clipboard $ctlpath
Start-Sleep -s 5
$wshell.SendKeys("^v")
Start-Sleep -s 1
$wshell.SendKeys("~")
Start-Sleep -s 10
&$actionss -para3 nonlog -para5 "start_uninstall_$($package)"
$wshell.SendKeys("u")
do{
$packages = (Get-Package |Where-object{$_.name -eq $package}).name
}until($packages.count -eq 0)
$index=$index+@("$package uninstall done")
&$actionss -para3 nonlog -para5 "after_uninstall_$($package)"
Start-Sleep -s 5
$wshell.SendKeys("l")
$shell.Windows() |Where-object{$_.name -eq "File Explorer"}| ForEach-Object { $_.Quit() }
start-sleep -s 5
## screenshot after
Start-Process control -Verb Open -WindowStyle Maximized
start-sleep -s 5
$wshell.SendKeys("^l")
Set-Clipboard $controlpn
Start-Sleep -s 5
$wshell.SendKeys("^v")
Start-Sleep -s 1
$wshell.SendKeys("~")
Start-Sleep -s 10
&$actionss -para3 nonlog -para5 "after_uninstall_$($package)_check"
$shell.Windows() |Where-object{$_.name -eq "File Explorer"}| ForEach-Object { $_.Quit() }
}
$timenow=get-date -format "yyMMdd_HHmmss"
$programlistpath2=$picpath+"$($timenow)_step$($tcstep)_programslist_after.txt"
$programlistpath3=$picpath+"$($timenow)_step$($tcstep)_programslist_uninstall.txt"
$packages2 = (Get-Package |Where-object{$_.name -like "*$pkgename*"}).name
$packages2 |Out-File $programlistpath2
$packages|Where-object{$_ -notin $packages2} |Out-File $programlistpath3
}
else{
$index="$pkgename no found"
}
$results="check index"
$index=[string]::join("`n",$index)
}
else{
$results="NG"
$index="No define uninstall target name"
}
######### write log #######
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 driver_uninstall_NVIDIA