# Capture Return Code from PsExex?

**URL:** https://www.finalbuilder.com/forums/t/capture-return-code-from-psexex/2589
**Category:** Discussion
**Created:** [January 30, 2018, 2:30am UTC](https://www.finalbuilder.com/forums/t/capture-return-code-from-psexex/2589 "2018-01-30T02:30:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![holger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@holger](https://www.finalbuilder.com/forums/u/holger)
#### Post date: [January 30, 2018, 2:30am UTC](https://www.finalbuilder.com/forums/t/capture-return-code-from-psexex/2589/1 "2018-01-30T02:30:24Z")

</div>

Hi all,  
  
i have a FB Project that remotely installs a software. For this i copy the software to the remote maschine and execute it using PsExec.   
More often than not this process fails on a certain machine. PSExec returns (in the log)   
  
“The handle is invalid” along with RC 6.   
  
I then go (manually) and stop and delete the PSEXESVC on the remote machine, reboot it and then it works again, until it happens again.   
  
This gets tiring, so i though i capture the RC and then just have FB stop and remove the service, reboot the machine and continue afterwards.   
  
But how do i capture the RC? I found no way to write this to a variable. I am quite new to FB so i might have overlooked other possibilites.   
  
Are there other ways of executing “Remote”? Running PowerShell maybe? Any experiences on that?  
  
Thanks a lot  
Holger

---

<div class="post-metadata">

### Author: ![holger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@holger](https://www.finalbuilder.com/forums/u/holger)
#### Post date: [January 30, 2018, 2:31am UTC](https://www.finalbuilder.com/forums/t/capture-return-code-from-psexex/2589/2 "2018-01-30T02:31:34Z")

</div>

Grrr, PsExeC!

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [January 30, 2018, 9:22am UTC](https://www.finalbuilder.com/forums/t/capture-return-code-from-psexex/2589/3 "2018-01-30T09:22:14Z")

</div>

The PSExec action has a Script event, OnCheckErrorCode which has a ReturnCode parameter.

---

<div class="post-metadata">

### Author: ![holger](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/h/ed8c4c/32.png) [@holger](https://www.finalbuilder.com/forums/u/holger)
#### Post date: [January 31, 2018, 6:08am UTC](https://www.finalbuilder.com/forums/t/capture-return-code-from-psexex/2589/4 "2018-01-31T06:08:23Z")

</div>

Very cool, Thanks.  
  
for those who look how to do this with PowerShell, this is what has worked for me  
  
$FBVariables.SetVariable(“ReturnCode”, $ReturnCode)  
  
“ReturnCode” = FinalBuilder Variable  
$ReturnCode = Variable set from Script.
