Jump to content

Powershell code in AutoIt


blumi
 Share

Recommended Posts

I copied the code from MattHiggs, thought when he posts here some example in the forum, that the code is correct.

The code should look more like this I think.

RunWait ( @ComSpec & ' /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Export-StartLayout -As bin -Path c:\temp\test.bin -verbose', @SystemDir )

 

Link to comment
Share on other sites

If you want to keep the DOS window open to inspect some error messages you could use:

RunWait ( @ComSpec & ' /k ...

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Thanks, thats cool. Of course I didn't know this.

Powershell starts, but the command is not known.

+ Export-StartLayout -As bin -Path c:\temp\test.bin -verbose
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Export-StartLayout:String) [], CommandNotFoundExcep
   tion
    + FullyQualifiedErrorId : CommandNotFoundException

I thought Export-Startlayout is a command from powershell, isn't it?

Link to comment
Share on other sites

My code works, and is the only way it has worked for me.  Is your cmd path also at syswow64, in addition to showing that error?

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

You did not tell us which version of Windows you run ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

I'm not running Windows 10 so unfortunately I can't help you with that.
But I'm sure on Google you will find a lot of hits ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

On 3/3/2016 at 4:14 AM, blumi said:

Tried this

RunWait ( @ComSpec & ' /c @powershell Export-StartLayout -As bin -Path c:\temp\test.bin -verbose', @SystemDir )

and

RunWait ( @ComSpec & ' /c @powershell -c Export-StartLayout -As bin -Path c:\temp\test.bin -verbose', @SystemDir )

Nothing works

YOu forgot the double quote surrounding your powershell command.  It should read Run ( @Comspec & ' /c @powershell -c "powershell command"' )

Edited by MattHiggs
Link to comment
Share on other sites

On 3/3/2016 at 6:05 AM, blumi said:

I copied the code from MattHiggs, thought when he posts here some example in the forum, that the code is correct.

The code should look more like this I think.

RunWait ( @ComSpec & ' /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Export-StartLayout -As bin -Path c:\temp\test.bin -verbose', @SystemDir )

 

The code is correct.  If you had copied and pasted like you said you had, then it should have compiled and run no problem.  I would never post something I hadn't verified first.  Maybe you need glasses since you failed to put the powershell command in double quotes like the example I provided.  I will not deny that there is more than one solution to a problem, but before you discount mine, try getting it right first.

Edited by MattHiggs
Link to comment
Share on other sites

On 3/3/2016 at 6:05 AM, blumi said:

I copied the code from MattHiggs, thought when he posts here some example in the forum, that the code is correct.

The code should look more like this I think.

RunWait ( @ComSpec & ' /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Export-StartLayout -As bin -Path c:\temp\test.bin -verbose', @SystemDir )

 

You did remember to change Powershells execution policy from "restricted" when you started coding right?  Powershell Command: Set-ExecutionPolicy unrestricted.  I would think that would be obvious, but your double quote learning disability requires the consideration of all possibilities,

 

Link to comment
Share on other sites

Hi.

 

the "@" is turning off the "echo".

 

You propably know it already from the CMD and BAT script's usual #1 line:

 

@echo off

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...