有没有办法从编译的EXE(使用Quest PowerGUI)正确访问isnetworkdeployed属性? [英] Is there a way to properly access the isnetworkdeployed property from a complied EXE (using Quest PowerGUI)?

查看:63
本文介绍了有没有办法从编译的EXE(使用Quest PowerGUI)正确访问isnetworkdeployed属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包装在exe中的小PowerShell脚本(使用Quest Power GUI).然后使用mageUI.exe(即通过"ClickOnce"部署)将该exe部署到UNC路径.

I have a small PowerShell script wrapped in an exe (using Quest Power GUI). This exe is then deployed to a UNC path using mageUI.exe (i.e. through a 'ClickOnce' deployment).

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

Now, there is a namespace available to us:

System.Deployment.Application

此命名空间使我们可以确定该工具是否是网络部署的+ exe的原始下载URL/UNC.

This namespace allows us to figure out if the tool is network deployed + the originating download URL/UNC of the exe.

因此,我在PowerShell脚本中添加了以下几行(然后由PowerGUI编译为exe文件)

So I added the following lines in my PowerShell script (which was then compiled into an exe by PowerGUI)

# 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),将其放在网络共享上,然后从其他服务器(可以访问上述共享)执行后,我仍然得到以下输出:

After publishing this exe as a 'ClickOnce' application (using mageUI.exe), putting it on a network share, and then executing from some other server (which has access to previously said share), I still get the following output:

# 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.

Not sure what I'm doing wrong. The property IsNetworkDeployed (Line 2) should have returned true.

推荐答案

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

Seeing that there is no solution using PowerGUI (since the script is extracted into a temp folder during execution), I had to do the following:

 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)

我愿意接受其他任何解决方案.

I am open to any other solutions.

这篇关于有没有办法从编译的EXE(使用Quest PowerGUI)正确访问isnetworkdeployed属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆