- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在编写一个脚本,在这个例子中的计算器上对某个程序进行访问控制
当您启动程序(脚本)时,脚本会生成一个包含用户名和时间戳的文本文件。如果第二个人尝试访问,脚本会检查此文本文件是否存在,并给出用户名和时间戳,并希望稍后尝试。如果该文件不存在,您可以访问该程序并生成该文件。当您关闭程序时,文件将被删除。
我正在使用一些 Windows 窗体来包含忽略函数并退出脚本。
问题是在您点击两个窗体上的忽略按钮后,Windows 窗体不会关闭。
我不知道如何修复它。
代码:
##### further functions #####
Function Warnung {
[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
$Form1.text = "Warning!"
$Form1.Width = 300
$Form1.Height = 200
$Text = New-Object Windows.Forms.Label
$Text.Location = New-Object Drawing.Point 75,30
$Text.Size = New-Object Drawing.Point 200,30
$Text.text = "Am $timestamp hat sich"
$Text2 = New-Object Windows.Forms.Label
$Text2.Location = New-Object Drawing.Point 75,60
$Text2.Size = New-Object Drawing.Point 200,30
$Text2.text = "$user"
$Text3 = New-Object Windows.Forms.Label
$Text3.Location = New-Object Drawing.Point 75,90
$Text3.Size = New-Object Drawing.Point 200,30
$Text3.text = "im calculator angemeldet!"
$Close = New-Object Windows.Forms.Button
$Close.text = "Close"
$Close.Location = New-Object Drawing.Point 20,120
$Close.add_click({$Form1.Close()})
$Taskmgr = New-Object Windows.Forms.Button
$Taskmgr.text = "Taskmgr"
$Taskmgr.Location = New-Object Drawing.Point 105,120
$Taskmgr.add_click({Taskmgr})
$Ignore = New-Object Windows.Forms.Button
$Ignore.text = "Ignore"
$Ignore.Location = New-Object Drawing.Point 190,120
$Ignore.add_click({Warning2})
$Form1.controls.add($Close)
$Form1.controls.add($Taskmgr)
$Form1.controls.add($Ignore)
$Form1.controls.add($Text)
$Form1.controls.add($Text2)
$Form1.controls.add($Text3)
$Form1.ShowDialog()
}
Function Taskmgr{
$Form1.Close()
Start-process taskmgr.exe
}
Function Ign2{
$Form2.Close()
$Form1.Close()
Remove-Item C:\users\heisem\desktop\test.txt
$date = Get-Date
$file = "C:\users\heisem\desktop\test.txt"
$env:username | set-content $file
$date | add-content $file
}
Function Warning2 {
$Form2.text = "Warnung!"
$Form2.Width = 300
$Form2.Height = 200
$Text4 = New-Object Windows.Forms.Label
$Text4.Location = New-Object Drawing.Point 40,30
$Text4.Size = New-Object Drawing.Point 200,70
$Text4.text = "Sind Sie sich sicher, dass Sie $user übergehen möchten?"
"Haben Sie $user angesprochen
ob diese(r) den Passwortsafe verlassen kann/hat?"
$Close2 = New-Object Windows.Forms.Button
$Close2.text = "Close"
$Close2.Location = New-Object Drawing.Point 20,120
$Close2.add_click({$Form2.Close()})
$Ignore2 = New-Object Windows.Forms.Button
$Ignore2.text = "Ignore"
$Ignore2.Location = New-Object Drawing.Point 190,120
$Ignore2.add_click({Ign2})
$Form2.controls.add($Close2)
$Form2.controls.add($Ignore2)
$Form2.controls.add($Text4)
$Form2.ShowDialog()
}
##### Main function #####
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$Form1 = New-Object Windows.Forms.Form
$Form2 = New-Object Windows.Forms.Form
if (Test-Path C:\users\heisem\desktop\test.txt) {
$user = Get-content "C:\users\heisem\desktop\test.txt" -totalcount 1
$timestamp = Get-Content "C:\users\heisem\desktop\test.txt" | Select-Object -Skip 1
Warnung
Start-Process calc.exe -Wait
Remove-Item C:\users\heisem\desktop\test.txt
} else {
$datum = Get-Date
$datei = "C:\users\heisem\desktop\test.txt"
$env:username | set-content $datei
$datum | add-content $datei
Start-Process calc.exe -Wait
Remove-Item C:\users\heisem\desktop\test.txt
}
最佳答案
这与调用 calc.exe
时使用的 -Wait
参数有关。您在调用 taskmgr.exe
的函数中不会遇到问题,因为您没有使用 -Wait
。
我还将 $Form1
和 $Form2
定义从局部函数范围中取出,以便每个人都可以全局访问它们。
相当疯狂地猜测,我想 -Wait
参数不允许前面的代码完成执行,直到函数退出,即框架正在决定某些引用仍然需要存在,而您调用的进程存在。
##### further functions #####
Function Warnung {
[reflection.assembly]::LoadWithPartialName( "System.Windows.Forms")
$Form1.text = "Warning!"
$Form1.Width = 300
$Form1.Height = 200
$Text = New-Object Windows.Forms.Label
$Text.Location = New-Object Drawing.Point 75,30
$Text.Size = New-Object Drawing.Point 200,30
$Text.text = "Am $timestamp hat sich"
$Text2 = New-Object Windows.Forms.Label
$Text2.Location = New-Object Drawing.Point 75,60
$Text2.Size = New-Object Drawing.Point 200,30
$Text2.text = "$user"
$Text3 = New-Object Windows.Forms.Label
$Text3.Location = New-Object Drawing.Point 75,90
$Text3.Size = New-Object Drawing.Point 200,30
$Text3.text = "im calculator angemeldet!"
$Close = New-Object Windows.Forms.Button
$Close.text = "Close"
$Close.Location = New-Object Drawing.Point 20,120
$Close.add_click({$Form1.Close()})
$Taskmgr = New-Object Windows.Forms.Button
$Taskmgr.text = "Taskmgr"
$Taskmgr.Location = New-Object Drawing.Point 105,120
$Taskmgr.add_click({Taskmgr})
$Ignore = New-Object Windows.Forms.Button
$Ignore.text = "Ignore"
$Ignore.Location = New-Object Drawing.Point 190,120
$Ignore.add_click({Warning2})
$Form1.controls.add($Close)
$Form1.controls.add($Taskmgr)
$Form1.controls.add($Ignore)
$Form1.controls.add($Text)
$Form1.controls.add($Text2)
$Form1.controls.add($Text3)
$Form1.ShowDialog()
}
Function Taskmgr{
$Form1.Close() ### IT WORKS HERE
Start-process taskmgr.exe
}
Function Ign2{
$Form2.Close() ### HERE IS THE PROBLEM
$Form1.Close() ### THE FORMS DO NOT CLOSE
Remove-Item C:\users\heisem\desktop\test.txt
$date = Get-Date
$file = "C:\users\heisem\desktop\test.txt"
$env:username | set-content $file
$date | add-content $file
Start-Process calc.exe
Remove-Item C:\users\heisem\desktop\test.txt
}
Function Warning2 {
$Form2.text = "Warnung!"
$Form2.Width = 300
$Form2.Height = 200
$Text4 = New-Object Windows.Forms.Label
$Text4.Location = New-Object Drawing.Point 40,30
$Text4.Size = New-Object Drawing.Point 200,70
$Text4.text = "Sind Sie sich sicher, dass Sie $user übergehen möchten?"
"Haben Sie $user angesprochen
ob diese(r) den Passwortsafe verlassen kann/hat?"
$Close2 = New-Object Windows.Forms.Button
$Close2.text = "Close"
$Close2.Location = New-Object Drawing.Point 20,120
$Close2.add_click({$Form2.Close()})
$Ignore2 = New-Object Windows.Forms.Button
$Ignore2.text = "Ignore"
$Ignore2.Location = New-Object Drawing.Point 190,120
$Ignore2.add_click({Ign2})
$Form2.controls.add($Close2)
$Form2.controls.add($Ignore2)
$Form2.controls.add($Text4)
$Form2.ShowDialog()
}
##### Main function #####
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$Form1 = New-Object Windows.Forms.Form
$Form2 = New-Object Windows.Forms.Form
if (Test-Path C:\users\heisem\desktop\test.txt) {
$user = Get-content "C:\users\heisem\desktop\test.txt" -totalcount 1
$timestamp = Get-Content "C:\users\heisem\desktop\test.txt" | Select-Object -Skip 1
Warnung
} else {
$datum = Get-Date
$datei = "C:\users\heisem\desktop\test.txt"
$env:username | set-content $datei
$datum | add-content $datei
Start-Process calc.exe -Wait
Remove-Item C:\users\heisem\desktop\test.txt
}
关于windows - 如何在 powershell 中关闭 Windows 窗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25993813/
对于一个科学实验,我写了一个turtle.py ,它会打开一个 800x480 的窗口并绘制一个缓慢增长的黑点。 turtle.py以 C:\Users\kaza>python C:\Users\ka
我开发了一个 swing 应用程序,但每次运行应用程序时都会打开一个新窗口。我希望如果一个窗口已经打开,则其他窗口不允许打开。 最佳答案 Here是一个 Java 单一应用实例的例子: A singl
有没有办法检测主进程中 Electron 的结构? process.platform 似乎也在 x64 机器上返回 win32,我没有在文档中找到任何获取架构的选项。 最佳答案 你试过 process
public short[] HanningWindow(short[] signal_in ,int pos ,int size) { for (int i= pos; i < pos+si
我有一个具有这些属性的 Electron 窗口: mainWindow = new BrowserWindow({ width: 800, height: 600, title: "Aqu
我有一个 Ubuntu 工作站,我正在尝试引导一个 Windows 节点。 Windows 节点在端口 2222 上打开了 ssh。我一直在关注 http://docs.opscode.com/plu
我是一名优秀的程序员,十分优秀!