-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappclose.psm1
100 lines (71 loc) · 2.64 KB
/
appclose.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
function appclose ([string]$para1){
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
$wshell=New-Object -ComObject wscript.shell
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
$paracheck=$PSBoundParameters.ContainsKey('para1')
if( $paracheck -eq $false -or $para1.length -eq 0 ){
#write-host "no defined, setting 1 min after login"
$para1="no_define"
}
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules"
}
else{
$scriptRoot=$PSScriptRoot
}
$action="appclose"
$tcpath=(Split-Path -Parent $scriptRoot)+"\currentjob\TC.txt"
$tcnumber=((get-content $tcpath).split(","))[0]
$tcstep=((get-content $tcpath).split(","))[1]
$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
$appname=$para1
if($appname -match "^cmd\b"){
$cmdcount=((Get-Process -Name cmd -ErrorAction SilentlyContinue).id).count
if($cmdcount -gt 1){
$appchecks=Get-Process -Name cmd -ErrorAction SilentlyContinue|Sort-Object StartTime|Select-Object -last 1
Stop-Process -id $appchecks.Id
&$actionss -para3 "nolog" -para5 "$($appname)_close"
$results="OK"
$index="close app $appname ok"
}
else{
$results="NG"
$index="No app $appname is found"
}
}
else{
$appchecks=Get-Process -Name $appname* -ErrorAction SilentlyContinue
$bcount=($appchecks.id).Count
if($bcount -ge 1){
(Get-Process -Name $appname*).CloseMainWindow()
(Get-Process -Name $appname* -ea SilentlyContinue)|stop-process -Force
Start-Sleep -s 30
$appchecks=Get-Process -Name $appname* -ErrorAction SilentlyContinue
$bcount=($appcheck.id).Count
if($bcount -ge 1){
foreach($appname1 in $appchecks){
taskkill -pid ($appname1.id) /F
}
start-sleep -s 3
$appcheck=Get-Process -Name $appname* -ErrorAction SilentlyContinue
$bcount=($appcheck.id).Count
}
&$actionss -para3 "nolog" -para5 "$($appname)_close"
if($bcount -eq 0){$results="OK"; $index="close app $appname ok"}
if($bcount -gt 0) {$results="NG" ; $index= "close app $appname fail"}
}
else{ $results="-"; $index="No app $appname is found" }
}
######### write log #######
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 appclose