c# - 有没有办法从编译的 EXE(使用 Quest PowerGUI)正确访问 isnetworkdeployed 属性?

标签 c# powershell clickonce powergui mageui

我有一个包含在 exe 中的小型 PowerShell 脚本(使用 Quest Power GUI)。然后使用 mageUI.exe(即通过“ClickOnce”部署)将此 exe 部署到 UNC 路径。
现在,有一个命名空间可供我们使用:
System.Deployment.Application
这个命名空间允许我们确定该工具是否是网络部署的 + exe 的原始下载 URL/UNC。
所以我在我的 PowerShell 脚本中添加了以下几行(然后被 PowerGUI 编译成一个 exe)

# Line 1. Load the assembly
[System.Reflection.Assembly]::LoadWithPartialName("System.Deployment")

# Line 2. Utilise methods in the assembly. Below line will give either false or true, depending if the caller is deployed as a 'ClickOnce' app.
[System.Deployment.Application.ApplicationDeployment]::IsNetworkDeployed
将此 exe 发布为“ClickOnce”应用程序(使用 mageUI.exe),将其放在网络共享上,然后从其他服务器(可以访问先前所说的共享)执行后,我仍然得到以下输出:
# Output of Line 1 (This signifies the assembly was loaded successfully)
GAC    Version        Location
---    -------        --------
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v...

# Output of Line 2
False
不知道我做错了什么。属性(property)IsNetworkDeployed (第 2 行)应该返回 true。

最佳答案

看到没有使用 PowerGUI 的解决方案(因为脚本在执行期间被提取到临时文件夹中),我不得不执行以下操作:

 1. Create a 'caller' / 'wrapper' executable using [PS2EXE](https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-Convert-PowerShell-9e4e07f1)
 2. This executable becomes the 'entry point' while deploying as a clickOnce application.
 3. Since the 'wrapper' is executed 'in-memory', the deployment methods/properties from System.Deployment work (if it's deployed through clickOnce).
 4. There is some logic written in the wrapper exe which calls the second (which contains the actual working) executable. Ex:

IF ISNETWORKDEPLOYED, THEN:
    PARSE THE URL ARGS / PREPARE THE ARGS AND PASS IT TO THE SECOND EXECUTABLE (which was compiled using Quest PowerGUI previously)
我对任何其他解决方案持开放态度。

关于c# - 有没有办法从编译的 EXE(使用 Quest PowerGUI)正确访问 isnetworkdeployed 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65040018/

相关文章:

c# - 使用 ContinueWith 或 Async-Await 时的不同行为

c# - 使用 Dapper 创建匿名对象的实例

powershell - 重命名文件中每个文件名的前 20 个字符

.net - 使用 clickonce 部署时不要覆盖 app.config

wpf - ClickOnce 快捷方式无法启动应用程序

C#匹配两个文本文件,大小写敏感问题

c# - 如何从Windows(如dxdiag)获取软件和硬件信息?

powershell - 以 SYSTEM 身份运行时查找当前登录用户(无环境变量)

c# - 在 C# 中创建 PowerShell Cmdlet - 管道链

c# - 如何使用带有 clickonce 的文本文件并在更新时能够更新它?