使用 PowerGUI 编译为 EXE 时如何引用依赖项 PowerShell 文件
how to refer to a dependency PowerShell file when compiling to EXE using PowerGUI
我正在尝试使用解决方案 PowerGUI 将两个单独的 Powershell 文件编译成一个 .EXE。
它似乎支持此功能,因为它甚至为此目的有一个名为 Dependencies 的按钮。
但是我找不到任何示例来说明如何从包含在同一 .EXE
中的任何其他 PowerShell 文件中引用依赖文件
我的主 PS 文件只包含以下行:
Start-Process powershell.exe -ArgumentList "-noexit -file C:\PGM\usbControl.ps1"
我想知道如何将 "C:\PGM\usbControl.ps1" 编码为 .EXE 包内的相对路径并指向包含的依赖项。
谢谢。
最后我不必使用任何外部 IDE,标准的 powershell 代码就成功了。嵌入代码! :) ScriptBlock 是关键。
$sb = {
$query = 'SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA ''Win32_LogicalDisk'' AND TargetInstance.DriveType=2'
Register-WmiEvent -Query $query -SourceIdentifier RemovableDiskDetection -Action {
$class = $eventArgs.NewEvent.__CLASS
$device = $eventArgs.NewEvent.TargetInstance.DeviceID
$wshell = New-Object -ComObject Wscript.Shell
switch ($class)
{
__InstanceCreationEvent {
$path = $device + '\flag\'
Write-Host '*** Checking the existence of the file $path'
if (Test-Path -Path $path)
{
$wshell.Popup('Inserted, device id: $device WITH flag', 0, 'Done', 0x1)
}
else
{
$wshell.Popup('Inserted, device id: $device WITHOUT flag', 0, 'Done', 0x1)
}
}
__InstanceDeletionEvent {
$wshell.Popup('Removed, device id: $device ', 0, 'Done', 0x1)
}
}
}
}
start-process powershell.exe -argument "-noexit -nologo -noprofile -windowstyle hidden -command $sb"
在这个很好的解决方法之后,我只是使用 PS2EXE 工具来编译它。
.\ps2exe.ps1 -noConsole -inputFile .\magic.ps1 -outPutFile magic.exe
我正在尝试使用解决方案 PowerGUI 将两个单独的 Powershell 文件编译成一个 .EXE。 它似乎支持此功能,因为它甚至为此目的有一个名为 Dependencies 的按钮。 但是我找不到任何示例来说明如何从包含在同一 .EXE
中的任何其他 PowerShell 文件中引用依赖文件我的主 PS 文件只包含以下行:
Start-Process powershell.exe -ArgumentList "-noexit -file C:\PGM\usbControl.ps1"
我想知道如何将 "C:\PGM\usbControl.ps1" 编码为 .EXE 包内的相对路径并指向包含的依赖项。
谢谢。
最后我不必使用任何外部 IDE,标准的 powershell 代码就成功了。嵌入代码! :) ScriptBlock 是关键。
$sb = {
$query = 'SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA ''Win32_LogicalDisk'' AND TargetInstance.DriveType=2'
Register-WmiEvent -Query $query -SourceIdentifier RemovableDiskDetection -Action {
$class = $eventArgs.NewEvent.__CLASS
$device = $eventArgs.NewEvent.TargetInstance.DeviceID
$wshell = New-Object -ComObject Wscript.Shell
switch ($class)
{
__InstanceCreationEvent {
$path = $device + '\flag\'
Write-Host '*** Checking the existence of the file $path'
if (Test-Path -Path $path)
{
$wshell.Popup('Inserted, device id: $device WITH flag', 0, 'Done', 0x1)
}
else
{
$wshell.Popup('Inserted, device id: $device WITHOUT flag', 0, 'Done', 0x1)
}
}
__InstanceDeletionEvent {
$wshell.Popup('Removed, device id: $device ', 0, 'Done', 0x1)
}
}
}
}
start-process powershell.exe -argument "-noexit -nologo -noprofile -windowstyle hidden -command $sb"
在这个很好的解决方法之后,我只是使用 PS2EXE 工具来编译它。
.\ps2exe.ps1 -noConsole -inputFile .\magic.ps1 -outPutFile magic.exe