有没有办法从编译的 EXE(使用 Quest PowerGUI)正确访问 isnetworkdeployed 属性?
Is there a way to properly access the isnetworkdeployed property from a complied EXE (using Quest PowerGUI)?
我有一个封装在 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。
看到没有使用 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)
我愿意接受任何其他解决方案。
似乎相关脚本确实在本地运行(如建议的那样),这似乎是由 exe
包装引起的,相反,您可能想要浏览(C:
,CD \Path
) 到您的 exe
位置并使用当前位置:
(get-location).Path
一般说明
我会重新考虑整体设计,因为我知道这个包装器可能(误)用于覆盖敏感信息(如硬编码密码),称为 Security through obscurity。如果情况确实如此,(合法的)黑客将很容易对此进行攻击。有几种方法可以处理脚本中的敏感信息,例如改为使用当前用户的凭据限制共享凭据and/or。
我有一个封装在 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。
看到没有使用 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)
我愿意接受任何其他解决方案。
似乎相关脚本确实在本地运行(如建议的那样),这似乎是由 exe
包装引起的,相反,您可能想要浏览(C:
,CD \Path
) 到您的 exe
位置并使用当前位置:
(get-location).Path
一般说明
我会重新考虑整体设计,因为我知道这个包装器可能(误)用于覆盖敏感信息(如硬编码密码),称为 Security through obscurity。如果情况确实如此,(合法的)黑客将很容易对此进行攻击。有几种方法可以处理脚本中的敏感信息,例如改为使用当前用户的凭据限制共享凭据and/or。