Execute an RDP file in PS Studio?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Execute an RDP file in PS Studio?

Post by stevens »

Product, version and build:
(*** Please do not write "latest" as a version, specify a version number ***)
32 or 64 bit version of product: 64
Operating system: W2K12R2
32 or 64 bit OS: 64
PowerShell Version:

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Hi,

I'd like to exectue an RDP file when pressing a button (it then opens an RDP session to a remote app).
Opening an exe the same way works by using & "$ToolsFolder\Myexe.exe" but the rdp gives following error:

The term 'C:\Myrdp.rdp' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again..Exception.Message at line 300

Please advise howto do this the proper way.
S.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Execute an RDP file in PS Studio?

Post by davidc »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Execute an RDP file in PS Studio?

Post by jvierra »

Use Start-Process:

start-process 'C:\Users\testuser\Desktop\omega.rdp'

stevens - you keep posting in the wrong forum. Devin moves your posts here for us. Try posting in "PowerShell GUIs' or "Windows PowerShell" under http://scriptinganswers.com
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Execute an RDP file in PS Studio?

Post by stevens »

Sorry for that. I will pay attention to it.
Thanks for the feedback.
One more thing, executing locally (machine on which my PS Studio is installed) works, but exe on other machine, the rdp doesn't work. It says 'This command cannot be run due to the error: The system cannot find the file specified..Exception.'
Another button which also opens an executable on the same location does work fine. So I'm puzzled.

What surprises me is the invocation of the file, please see screenshot below. My path is \supporttool\tools\myrdp.rdp but it writes supportooltools WITHOUT the backslash.
Tried every possible combination but it doesn't show the \.

What am I doing wrong? Please advise.
example.png
example.png (14.48 KiB) Viewed 2975 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Execute an RDP file in PS Studio?

Post by jvierra »

Please don't post screen shots. They are mostly unreadable in most browsers. Post a copy of the code.

I cannot understand what you are saying. The error message is clear. The file path you used doesn't exist.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Execute an RDP file in PS Studio?

Post by stevens »

In the globals.ps1 of my project I set the following:

$ScriptPath = Split-Path $MyInvocation.MyCommand.path
$ToolsFolder = $ScriptPath + "\tools"

I got 3 buttons in the mainform.psf: 1 of the 3 works correctly, the others don't but have the exact same command type
Start-Process "$ToolsFolder\WindirStat.exe"

When I hover over $Toolsfolder it shows me ...\SupportToolstools as value for the variable and I cannot make it \SupportTools\Tools what the path should be.
However, the buttons = launching exes which are below the buttons work fine on the local machine (which has PS Studio installed) but not on a remote one and I cannot figure out why.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Execute an RDP file in PS Studio?

Post by jvierra »

That is why Sapien provides a function to get the script path:

Try using $ScriptDirectory as it is acquired on startup.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Execute an RDP file in PS Studio?

Post by stevens »

Thanks, that worked indeed!
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked