我知道这并不理想,但我的限制是我有一个用 Clipper 编写的遗留应用程序。
我想从应用程序内部启动一个新的 WinForms/WPF 应用程序(以简化过渡)。这个用 Clipper 编写的遗留应用程序使用以下命令启动:
SwpRunCmd("C:\MyApp\MyBat.bat",0)
批处理文件包含类似以下命令的内容:
C:\PROGRA~1\INTERN~1\iexplore "http://QASVR/MyApp/AppWin/MyCompany.MyApp.AppWin.application#MyCompany.MyApp.AppWin.application"
它正在启动我们通过 ClickOnce 部署的 WinForms/WPF 应用程序。在我们将 WPF 引入应用程序之前,一切都很顺利。我们能够轻松地从旧版应用程序启动。
然而,由于我们引入了 WPF,我们有以下行为。如果我们首先通过 Clipper 应用程序启动,启动应用程序时会出现异常。错误文本是:
The type initializer for 'System.Windows.FrameworkElement' threw an exception.
at System.Windows.FrameworkElement..ctor()
at System.Windows.Controls.Panel..ctor()
at System.Windows.Controls.DockPanel..ctor()
at System.Windows.Forms.Integration.AvalonAdapter..ctor(ElementHost hostControl)
at System.Windows.Forms.Integration.ElementHost..ctor()
at MyCompany.MyApp.AppWin.Main.InitializeComponent()
at MyCompany.MyApp.AppWin.Main..ctor(String[] args)
at MyCompany.MyApp.AppWin.Program.Main(String[] args)
The type initializer for 'System.Windows.Documents.TextElement' threw an exception.
at System.Windows.FrameworkElement..cctor()
The type initializer for 'System.Windows.Media.FontFamily' threw an exception.
at System.Windows.Media.FontFamily..ctor(String familyName)
at System.Windows.SystemFonts.get_MessageFontFamily()
at System.Windows.Documents.TextElement..cctor()
The type initializer for 'MS.Internal.FontCache.Util' threw an exception.
at MS.Internal.FontCache.Util.get_WindowsFontsUriObject()
at System.Windows.Media.FontFamily.PreCreateDefaultFamilyCollection()
at System.Windows.Media.FontFamily..cctor()
Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at MS.Internal.FontCache.Util..cctor()
如果我们首先通过 URL(在 IE 中)或通过桌面上的图标启动应用程序,我们不会得到异常并且应用程序会按预期启动。
巧妙的是,我们首先启动的内容决定了应用程序是否会启动。因此,如果我们首先使用旧版启动,它会立即中断,即使我们使用其他成功的 URL 或图标启动,我们也无法让应用程序运行。为了让它工作,我们必须注销并重新登录并从 URL 或图标启动它。
如果我们首先使用 URL 或图标,那么从那时起我们从遗留应用程序启动没有问题(直到我们注销并重新登录)。
另一条信息是我们能够以以下方式模拟问题。如果我们使用“cmd.exe”输入命令提示符并执行从 URL 启动的语句,我们就成功了。但是,如果我们使用“command.com”输入命令提示符并执行相同的语句,我们就会遇到中断行为。
我们假设这是因为 Clipper 中的旧版应用程序使用 command.com 的等价物来创建 shell 以生成其他应用程序。我们尝试了很多技巧,比如让 command.com 运行 cmd.exe 或 psexec 然后执行,但似乎没有任何效果。
我们有一些解决方法的想法(比如让应用程序在启动时启动,因此我们强制从 URL 成功启动,使所有后续启动都成功),但即使我们对工作站有很大的控制权,它们都不是最佳的.
为了减少这与权限相关的可能性,我们赋予了启动帐户管理权限(以及非管理权限,以防产生影响)。
任何想法都会非常感激。就像我说的,我们有一些变通办法,但我很想避免它们。
谢谢!