除了 MikeBazs Answer,我想提供以下“解决方法”,它使 Click-Once-Application 的安装“非交互式”和“几乎无声”(用户在安装过程中看到进度窗口,无需点击和/或可能)
有一些“问题”需要考虑,但如果您遵循本指南,结果应该是您所需要的:
1.) 签署您的应用程序:在 Visual Studio 中,您可以使用自己的证书轻松签署您的应用程序,这没什么大不了的。
2.) 分发证书:为了避免该对话框,如果应安装应用程序,您需要将您的证书分发到任何机器上的以下商店(为此使用 GPO ): Trusted Publishers 和 Trusted Root Certification Authorities
现在,用户只需单击即可安装应用程序 - 没有安全问题。但我们希望零点击:
3.) 创建一个位于服务器上的 powershell 脚本,该脚本调用应用程序的 setup.exe(如果尚未安装):
$appInfo = Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall | foreach-object {Get-ItemProperty $_.PsPath}
$displayName = $appInfo | ? { $_.displayname -eq "MyApplicationName" } | select displayName
if ($displayName -eq $null){
# MyApplicationName not installed, install!
Start-Process "\\server\share\MyApplication\Application\setup.exe"
}
现在,用户可以执行该脚本,只需安装一次,无需进一步确认。但应用程序在安装后启动。
4.) 修改应用程序的源代码:我使用了一个虚拟文件来检测应用程序的首次运行。如果它是第一次运行,(即安装后)我只是再次关闭它:
private void Form1_Load(object sender, EventArgs e)
{
//first run? That's a initial deployment, close application.
if (!File.Exists("C:\\some\\static\\path\\notfirstrun.dat"))
{
File.WriteAllText("C:\\some\\static\\path\\notfirstrun.dat", "1");
Application.Exit();
}
现在,用户可以执行该脚本,只需安装一次,无需进一步确认,并且应用程序在安装后不会“自动启动”。
但我们也想避免“点击”:
如果我们在 Startup-Folder 中设置 powershell 脚本 - 它会弹出,这很难看。如果我们将其设置为 Login-Script,它不会在用户上下文中运行,这是 Click-Once 所必需的。
作为“这个”问题的解决方法,您可以将其包装在 vbs 脚本中,调用 powershell 脚本。请注意,这是在用户上下文中执行的,因此用户需要权限才能执行 powershell-scripts:
Dim objShell
Set objShell=CreateObject("WScript.Shell")
strCMD="powershell.exe -sta -noProfile -NonInteractive -nologo -ExecutionPolicy Bypass -f \\server\share\scripts\install_App.ps1"
objShell.Run strCMD,0,True
最后,使用 GPO 将您的 vbs 脚本部署到任何用户的启动文件夹中。
用户将看到的只是“安装”进度。
简而言之:
- 签署您的代码
- 分发您的证书
- 使用 powershell 脚本触发安装
- 将该 powershell 脚本包装在一个不可见的 vbs 脚本中
- 将 vbs 脚本部署到每个用户的启动文件夹。