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

Vis*_*ish 5 c# powershell clickonce powergui mageui

我有一个包含在 exe 中的小型 PowerShell 脚本(使用 Quest Power GUI)。然后使用 mageUI.exe(即通过“ClickOnce”部署)将此 exe 部署到 UNC 路径。

现在,有一个命名空间可供我们使用:

系统.部署.应用

这个命名空间允许我们确定该工具是否是网络部署的 + 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
Run Code Online (Sandbox Code Playgroud)

将此 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
Run Code Online (Sandbox Code Playgroud)

不知道我做错了什么。属性IsNetworkDeployed(第 2 行)应该返回 true。

Vis*_*ish 0

看到使用 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)
Run Code Online (Sandbox Code Playgroud)

我对任何其他解决方案持开放态度。