简体   繁体   English

本地Powershell脚本可触发Citrix实例中的VBS脚本

[英]Local Powershell script to trigger VBS script inside Citrix instance

I am trying to get a local powershell script to trigger a VBS script inside a citrix instance. 我正在尝试获取本地Powershell脚本来触发citrix实例内的VBS脚本。 The events should be this: 事件应该是这样的:

Citrix Instance opening Windows Explorer ----> Network Path of script typed into the windows explorer session Citrix实例打开Windows资源管理器---->在Windows资源管理器会话中键入脚本的网络路径

I'm using the WfIcaLib.dll (ICOSDK) that came with the Citrix receiver install. 我正在使用Citrix Receiver安装随附的WfIcaLib.dll(ICOSDK)。 Documentation PDF for the Citrix ICOSDK is available here Citrix ICOSDK的文档PDF在此处提供

So this is the code I'm using, which works PERFECTLY in Powershell command line, but when I use the 32-bit ISE, it does nothing other than telling me the DLL has been loaded. 所以这是我正在使用的代码,它在Powershell命令行中可以正常运行,但是当我使用32位ISE时,除了告诉我DLL已加载外,它什么也没做。 I get no errors, but the Citrix Client never actually opens like it does when I run the same exact commands through Powershell command line. 我没有收到任何错误,但是Citrix Client实际上从未像通过Powershell命令行运行相同的确切命令时那样打开。

#load Citrix ICA Client SDK
[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")

$ICA = New-Object WFICALib.ICAClientClass 
$ICA.Address = "***.***.***.***:****" 
$ICA.Application = "Windows ExplorerFED6" 
$ICA.Username = "******"
$ICA.Domain = "**" 
$ICA.Launch = $true
$ICA.Outputmode = [WfIcaLib.OutputMode]::OutputModeNormal 
$ICA.SetProp("Password", "*********")
$ICA.TWIMode=$true 
$ICA.Connect()

Any ideas? 有任何想法吗?

EDIT: SOLVED - after reopening under 32-bit ISE and getting code to work, I could not run the .ps1 file since it kept defaulting to 64-bit (even if using Open With on 32-bit powershell version). 编辑:已解决-在32位ISE下重新打开并让代码工作后,由于无法保持默认值为64位(即使在32位powershell版本上使用Open With),我也无法运行.ps1文件。 Running the script via command prompt or 32-bit powershell console both worked. 通过命令提示符或32位Powershell控制台运行脚本都可以。

Using any method suggested by Mike Garuccio worked just fine. 使用Mike Garuccio建议的任何方法都可以。 I will most likely end up using a Task Scheduler to run the script. 我很可能最终会使用任务计划程序来运行脚本。

It looks like the problem is a versioning one, which you can deal with using start-job (was originally going to do this with a runspace but that's a lot more code for no real benefit). 看来问题在于版本控制,您可以使用start-job进行处理(本来打算在运行空间中执行此操作,但有很多代码却没有真正的好处)。 This will start a job to run your code under 32-bit powershell, it should still place any GUI elements or popups on screen but if you need to get any data out from the script later you'll need to receive the job. 这将启动一个作业,以在32位Powershell下运行代码,它仍应在屏幕上放置任何GUI元素或弹出窗口,但是如果您以后需要从脚本中获取任何数据,则需要接收该作业。 code would look something like below. 代码如下所示。

$SB = {
[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")

  $ICA = New-Object WFICALib.ICAClientClass 
  $ICA.Address = "***.***.***.***:****" 
  $ICA.Application = "Windows ExplorerFED6" 
  $ICA.Username = "******"
  $ICA.Domain = "**" 
  $ICA.Launch = $true
  $ICA.Outputmode = [WfIcaLib.OutputMode]::OutputModeNormal 
  $ICA.SetProp("Password", "*********")
  $ICA.TWIMode=$true 
  $ICA.Connect()
}

Start-Job -ScriptBlock $SB -RunAs32
get-job | Receive-Job

Alternatively, you could also use a simple .bat file as a launcher with something like C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe -file yourscript.ps1 或者,您也可以使用简单的.bat文件作为启动器,并使用C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe -file yourscript.ps1

or if you need everything to be wrapped in powershell and the job does not work you can use the solution Here that basically does the same thing but from within powershell (drop the if statement they use tho, just use the stuff contained inside it like below, with any changes you need to make wrt the profile and interactive settings.) 或者如果您需要将所有内容都包装在powershell中并且工作无法正常进行,则可以使用解决方案在这里 ,基本上可以做同样的事情,但是要在powershell中进行操作(删除它们使用的if语句,只需使用其中包含的内容,如下所示) ,您需要进行任何更改才能进行配置文件和交互式设置。)

&"$env:windir\\syswow64\\windowspowershell\\v1.0\\powershell.exe" -noninteractive -noprofile -file "C:\\Path o\\script.ps1" -executionpolicy bypass

hope one of those works for you! 希望其中一项为您服务!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM