下面是原帖
当您使用 PowerShell 2.0 时,Windows 将回退到旧式 Windows GUI,因为默认情况下,PowerShell 2.0 会加载 .Net 2.0。
$PSVersionTable 在 PowerShell 2.0 中
Name Value
---- -----
CLRVersion 2.0.50727.5485
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
$PSVersionTable 在 PowerShell 4 中
Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.42000
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2
如果您安装了 .net CLR 3.5 或更高版本,您可以强制 PowerShell 2.0 加载比 2.0 更新的 CLR 版本,这将为您提供更新的样式文件对话框。
将以下代码保存到批处理文件(例如 WindowsPowerShell3.5.cmd)中,其中 3.5 是您希望使用 PowerShell 加载的 CLR 版本。然后运行批处理文件以启动 PowerShell。将 powershell.exe 更改为 powershell_ise.exe 以将其应用于 PowerShell ISE 会话。
@echo off
:: http://stackoverflow.com/questions/7308586/using-batch-echo-with-special-characters
if exist %~dp0powershell.exe.activation_config goto :run
echo.^<?xml version="1.0" encoding="utf-8" ?^> > %~dp0powershell.exe.activation_config
echo.^<configuration^> >> %~dp0powershell.exe.activation_config
echo. ^<startup useLegacyV2RuntimeActivationPolicy="true"^> >> %~dp0powershell.exe.activation_config
echo. ^<supportedRuntime version="v3.5"/^> >> %~dp0powershell.exe.activation_config
echo. ^</startup^> >> %~dp0powershell.exe.activation_config
echo.^</configuration^> >> %~dp0powershell.exe.activation_config
:run
:: point COMPLUS_ApplicationMigrationRuntimeActivationConfigPath to the directory that this cmd file lives in
:: and the directory contains a powershell.exe.activation_config file which matches the executable name powershell.exe
set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=%~dp0
%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe %*
set COMPLUS_ApplicationMigrationRuntimeActivationConfigPath=
原帖
试试下面的代码,它基于来自Microsoft的示例代码:
WPF
Add-Type -AssemblyName PresentationFramework
$dlg = New-Object 'Microsoft.Win32.SaveFileDialog'
$dlg.FileName = "Document" # Default file name
$dlg.DefaultExt = ".txt" # Default file extension
$dlg.Filter = "Text documents (.txt)|*.txt" # Filter files by extension
# Show save file dialog box
$result = $dlg.ShowDialog()
# Process save file dialog box results
if ($result) {
# Save document
$filename = $dlg.FileName;
}
我猜你有使用 System.Windows.Forms 的代码,类似于下面的代码:
Windows 窗体
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.forms")
$dlg = New-Object System.Windows.Forms.SaveFileDialog
$dlg.FileName = "Document" # Default file name
$dlg.DefaultExt = ".txt" # Default file extension
$dlg.Filter = "Text documents (.txt)|*.txt" # Filter files by extension
# Show save file dialog box
$result = $dlg.ShowDialog()
# Process save file dialog box results
if ($result) {
# Save document
$filename = $dlg.FileName
}