从PowerShell脚本创建可执行.exe文件? [英] Creating an executable .exe file from a PowerShell Script?

查看:550
本文介绍了从PowerShell脚本创建可执行.exe文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过PowerShell脚本创建可执行文件file.exe?

Is it possible to create an executable file.exe file from a PowerShell Script?

推荐答案

否.至少现在还没有,并且在5个版本的PowerShell之后,似乎不太可能.

No. At least, not yet, and after 5 versions of PowerShell, it seems unlikely ever.

我希望我可以保留它,但是其他人提供了很多我不得不解决的变通"类型的答案:

I wish I could just leave it at that, but other people have provided a bunch of "workaround" type answers I feel compelled to address:

可以将.ps1脚本包装为另一种脚本类型以使其可以双击,甚至可以生成嵌入了脚本的可执行文件(请参见此线程上的其他答案). .但是这些可执行文件"要求系统中已经存在正确版本的PowerShell ,因此您这样做并不会获得任何好处,因此会失去PowerShell的许多功能(例如流对象的输出,帮助文档以及对用户的制表符自动完成的自动参数处理.

You can wrap your .ps1 script in another script type to make it double-clickable, and you can even generate an executable with the script embedded (see the other answers on this thread) ... but those "executables" require the right version of PowerShell to be already present on the system, so you're not gaining anything by doing that, and you loose a lot of the features of PowerShell (like streaming object output, help documentation, and automatic parameter handling with tab completion for users).

这是一个简单的.cmd批处理文件包装器(您可以将其扩展为允许参数):

Here is a simple .cmd batch file wrapper (you could extend this to allow parameters):

REM <#
copy %0 %0.ps1
PowerShell.exe -ExecutionPolicy Unrestricted -NoProfile -Command "&{Set-Alias REM Write-Host; .\%0.ps1}"
del %0.ps1
exit
REM #>

### Your PowerShell script goes below here.
### I've put a couple of lines as an example ...
ls | sort length -desc | select -first 5 | ft
ps | sort ws -desc | select -first 10 | ft

我知道...

使用便携式PowerShell ,可能可以打包一种自解压zip,其中包含正确版本的PowerShell和脚本并且可以正常工作.从任何通常的意义上讲,这不是可执行文件-有点像Valve决定只将拇指上的vmware映像发布为他们的解决方案,以让Linux用户玩《半条命》.但是,该产品似乎被放弃了.

I know ...

With Portable PowerShell, it would probably be possible to package up a sort of self-extracting zip that would contain the right version of PowerShell and a script and would work. That's not an executable in any normal sense of the word -- it's a bit like if Valve had decided to just ship a vmware image on a thumbdrive as their solution to letting Linux users play Half Life. However, the product seems abandoned.

使用 PrimalScript (或 PowerShell Studio )或 PowerGui pShellExec ,可以对脚本进行加密,因此略有保护,可防止撬开眼睛...但这基本上只是混淆,基本上与批处理文件没有什么不同,并且在某些方面更糟.

With PrimalScript (or PowerShell Studio) or PowerGui or pShellExec, your script can be encrypted, so it's slightly secured against prying eyes ... but this is basically just obfuscation, and essentially no different than the batch file, and in some ways worse.

这篇关于从PowerShell脚本创建可执行.exe文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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