5

我有一个封装在 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

将此 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

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

4

2 回答 2

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)

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

于 2020-12-04T16:38:48.813 回答
0

看起来相关脚本确实在本地运行(如建议的那样),这似乎是由exe包装引起的,相反,您可能希望浏览 ( C:, CD \Path) 到您的exe位置并使用当前位置:

(get-location).Path

一般说明
我会重新考虑整体设计,因为知道此包装器可能(错误)用于覆盖敏感信息(如硬编码密码),称为Security through obscurit y。如果情况确实如此,(合法的)黑客会很容易地对此进行攻击。有几种方法可以处理脚本中的敏感信息,例如限制共享凭证和/或改用当前用户的凭证。

于 2020-12-06T15:43:21.147 回答