Using Clipboard between Powershell and MS

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
kdtrog
Junior Coder
Posts: 43
Joined: Wed Mar 28, 2007 9:36 am

Using Clipboard between Powershell and MS

Post by kdtrog » Fri Feb 17, 2017 10:54 am

I am trying to transfer text between Powershell 5.0 and MacroScheduler via Clipboard.

I am running a PS Script within a MS script using RunProgram>powershell.exe. The PS script does a set-clipboard command.

Code: Select all

RunProgram>powershell.exe -command "& {Set-Clipboard -value 'true'}"
wait>1
GetClipBoard>check_ps
The result variable does not contain the newest value (in this case "true")

Any ideas?

Klaus

kdtrog
Junior Coder
Posts: 43
Joined: Wed Mar 28, 2007 9:36 am

Re: Using Clipboard between Powershell and MS

Post by kdtrog » Fri Feb 17, 2017 11:33 am

I guess I found the reason. My MS Script is running in an elevated user session but MS is using the clibboard of the original User environment. Powershell is using the elevated environment's clipboard.

A bug or works as designed?

klaus

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Using Clipboard between Powershell and MS

Post by Marcus Tettmar » Fri Feb 17, 2017 11:39 am

That's just how Windows works - the whole point is that data can't be shared across execution levels.

However, why is your script running elevated? Macro Scheduler doesn't run elevated by default. It only runs elevated if you choose to run it elevated. If there is a good reason why your script runs elevated you're going to have to either run powershell elevated as well, or find some other way to transfer the data.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

kdtrog
Junior Coder
Posts: 43
Joined: Wed Mar 28, 2007 9:36 am

Re: Using Clipboard between Powershell and MS

Post by kdtrog » Fri Feb 17, 2017 3:50 pm

Of cause you are right. At the end I found and solved my problem. I worked in the same elevation level but I had an error executing the PS Script because I made a mistake in my LabelToVar statement for the script. :oops:

Thanks anyway

klaus

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts