Jump to content

[Solved] How to run Powershell with AutoIt and use Get-RDUserSession command?


Recommended Posts

If I run this code, it works perfectly

$CmdPid = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit " & 'Get-ChildItem',@DesktopDir, @SW_SHOW)

But this code

$CmdPid = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit " & 'Get-RDUserSession',@DesktopDir, @SW_SHOW)

I get this error:

Get-RDUserSession : The term 'Get-RDUserSession' is not recognized as the name of a cmdlet, function, script file, or o
perable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try aga
in.

If I try run the command Get-RDUserSession  in normal PowerShell (started from windows start menu) the command works perfectly.

But If I run with AutoIt I get the above mentioned error .

Any ideas?

Edited by DannyJ
Link to comment
Share on other sites

I had a similar problem with Active Directory. You need to install those cmdlets.
https://stackoverflow.com/questions/52876847/get-rdusersession-is-not-recognized-as-the-name-of-a-cmdlet

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

3 minutes ago, water said:

I had a similar problem with Active Directory. You need to install those cmdlets.
https://stackoverflow.com/questions/52876847/get-rdusersession-is-not-recognized-as-the-name-of-a-cmdlet

Thank you I have already tried this command

Quote

Import-Module -Name RemoteDesktop -Verbose

The AutoIt PowerShell I don't know why won't allow to import these modules.

 

Can I acces the default PS with Auto It?

Please use this command if you open the PowerShell, and check the commands in it:

 

$CmdPid = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit " & 'Get-RDUserSession',@DesktopDir, @SW_SHOW)

I don't know why this PowerShell (opened by AutoIt) is different from the Windows default PS. 

Link to comment
Share on other sites

15 hours ago, argumentum said:

...I don't marry to a tool. I use what I find functional. Good luck.

Don't you think I have a more complex issue than this?

I just wrote here a little piece of a complex issue, if you can't help me at least, don't make sarcastic remarks, it won't help....

Thanks

Edited by DannyJ
Link to comment
Share on other sites

15 hours ago, Subz said:

Did you compile as 64 bit and use #RequireAdmin?  Example:

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Run("PowerShell.exe -noexit Get-RDUserSession")

 

Thank you very much, I am very grateful for your help, your solution works perfectly.

Solution: 
 

#RequireAdmin

#AutoIt3Wrapper_UseX64=y

Need admin to run this command, and 64bit to run smoothly.

Edited by DannyJ
Link to comment
Share on other sites

4 hours ago, DannyJ said:

don't make sarcastic remarks, it won't help....

well, your attitude is not friendly nor helpful. If you start a thread, do attend to it by responding honestly, and with a touch of humility if I may say.
I understand that when one has a need for a solution, one goes into a form of desperation of sorts. But jumping around without attending the dialog is not nice nor welcoming to the one attempting to aid.

Glad to see that you posted the solution to the problem for the next one needing such solution.

...and as I kindly ask everyone that found a clear solution, do prefix [Solved] to the tittle, as this helps future searches.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • 1 year later...

I'm getting frustrated to tears with this.
So far I've tried this

Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Start-Sleep -Seconds 20 -Milliseconds 300" )

With no luck.
And the command I need to run is "Set-MpPreference -DisableRealtimeMonitoring $True" to disable powershell. So that's going to need administrator permission.

So my two questions are
1. Why didn't my run command work and
2. How do I run the command I really need to run as Administartor?

I went with the pause command because I can allow people to test it and such without disabling their active protection. I want MY defender disabled, not the person who's trying to help me. :D

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

1 hour ago, argumentum said:

Open your own thread. Don't necro-nonsense. Change the ETA-404 to Brain-404. Yeah, that's a start :D 

Yes mod. You're a moderator right? Oh no, you're not? Strange because the Moderator that I messaged around an hour ago about weather or not I should reply here or start a new thread said that it would be fine to reply here since "A year isn't really that old".  :)

(I say this with most of the respect that is due to you. We normally agree about and get along about nearly everything.)

Edited by Draygoes
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Hey, my bad @argumentumThat was a bit harsh of me, I should have commented with more taste. Been thinking about it.
EDIT: I did end up starting a new thread. Again, sorry. This doesn't make it any better, but I was frustrated by then. Thats all that was.

Edited by Draygoes
Added detail. (x2)
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...