windows - 脚本适用于 windows 10 但不适用于 windows 7
问题描述
我有以下脚本:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$CenterScreen = [System.Windows.Forms.FormStartPosition]::CenterScreen;
$BucketPath = '\\**\bucket'#Path to the available programs for user
$BucketDBPath = '\\**B$'
#$BucketDBPath = "\\**\$env:COMPUTERNAME.txt"#Path to write the Txt file
$PdfPath = '\\srv\s$\installer\pdf'
$img = [Drawing.Image]::FromFile('\\s**\bg.png')
Function Install(){#Write txt file with %hostname% and list of programs
if (Test-Path $BucketDBPath\$env:COMPUTERNAME.txt ) { Remove-Item $BucketDBPath\$env:COMPUTERNAME.txt }
ForEach ($item in $listBox1.SelectedItems) {
if (Test-Path $PdfPath\$item.pdf){Start-Process ((Resolve-Path "$pdfPath\$item.pdf").path)}
# "$item.exe" | Out-File $BucketDBPath\$env:COMPUTERNAME.txt
echo "$item.exe" >> $BucketDBPath\$env:COMPUTERNAME.txt
}
$form.close()}
Function MakeForm(){
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '650,420'
$Form.text = "Installer"
$Form.TopMost = $true
$form.BackgroundImage = $img
$form.BackgroundImageLayout = 'Tile'
$Form.FormBorderStyle = 'FixedDialog'
$Form.TopMost = $true
$form.StartPosition = $CenterScreen
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "Welcome!`r`nChoose program\s you wish to install"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$label1.BackColor = "White"
$Label1.location = New-Object System.Drawing.Point(200,10)
$Label1.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',15,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
$ListBox1 = New-Object system.Windows.Forms.ListBox
$ListBox1.width = 431
$ListBox1.height = 280
@($programlist) | ForEach-Object {[void] $ListBox1.Items.Add($_)}
$listbox1.Font = 'Microsoft Sans Serif,12'
$ListBox1.location = New-Object System.Drawing.Point(201,60)
$listbox1.SelectionMode = 'MultiExtended'
$listbox1.BackColor = "#cdedfc"
$Button3 = New-Object system.Windows.Forms.Button
$Button3.BackColor = "#caebfc"
$Button3.width = 100
$Button3.text = "Install"
$Button3.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12)
$Button3.height = 30
$Button3.location = New-Object System.Drawing.Point(530,370)
$Form.controls.AddRange(@($ListBox1,$Button3,$Label1))
$Button3.Add_Click({ Install })
[void]$form.ShowDialog()}
$data = gci $BucketPath | %{$_.BaseName}
$programlist = $data
MakeForm
这是一个非常简单的脚本,它向用户展示了共享网络路径中文件的良好 gui,他可以标记它们,并且将使用他的主机名在其他网络路径上创建一个 txt 文件和他的选择。
我把它编译成EXE。非常适合 Windows 10 用户。但是当我为 Windows 7 用户运行这个 exe 时,它什么也没做。谁能发现问题?
*edit 使用来自官方 technet.microsoft 网站的 Markus Scholtes 的 ps2exe gui 编译它
解决方案
推荐阅读
- image - 将 Gitlab CI 与 runner 一起使用时找不到 apt-get
- r - 根据预定义的列值将二进制值添加到列
- react-native - 如何在 react-native-sqlite-storage 中连接预填充的 sqlite 数据库?
- java - Hibernate - 通过父 ID 获取子帐户
- pytest - 具有并行执行的 Pytest 实时日志记录 - 可能吗?
- cmake - cmake/ctest 与 valgrind 输出为 xml
- python-3.x - 我在 python 中的 for 循环之外的变量列表正在改变。请建议
- python - Pandas DataFrame 基于另外两列创建新的 csv 列
- reporting-services - 如何在 SSRS 报告中圈出选项/值
- swift - UITableView 没有出现在视图中?