Jump to content
Eggsplorer

Powershell Command in Autoit

Recommended Posts

Eggsplorer

Hi,

I would like to install chocolatey packages (OneGet) via Autoit.

Manually without Autoit I would just open Powershell and use this command:

Install-Package -Name Firefox -Force

It also works with cmd (see attachment 1)

powershell.exe -Command Install-Package -Name Firefox -Force

With Autoit I tried the following code:

RunWait(@ComSpec & ' /k ' & 'powershell.exe -Command Install-Package -Name Firefox -Force', @SW_SHOW)

It doesnt work at all. I don't even see a cmd window.

When I add @SystemDir the Windows appears with the error in attechment 2.

Is there another way to run PowerShell Commands with Autoit?

I would like to avoid starting Powershell, waiting for the window, sending the command and sending Enter.

Thanks

Eggsplorer
 

cmd.jpg

autoit.jpg

Edited by Eggsplorer

Share this post


Link to post
Share on other sites
AutoBert

You forgot the 2. parameter if you didn't know what to use just use '' or @scriptdir.

 

Btw.: soon is easter, a good time to eggsplore gardens, parks etc.

Edited by AutoBert

Share this post


Link to post
Share on other sites
Eggsplorer

Ah right. That's why it worked with @SystemDir.

Now I am using @UserProfileDir since I am logged in as "Administrator".

I am still receiving the same error (red font in original post).

How can this be?
AutoIt uses the same command as I pasted to cmd!

Is there an other way to execute PowerShell commands with AutoIt?

Btw.: I am eggsploring AutoIt for now ;)

Share this post


Link to post
Share on other sites
rudi

Hi.

1st of all: I have no experience at all with Powershell 5.0, Packet Handling is nothing I've ever used so far.

 

The message is telling ... keine Übereinstimmung für die angegebenen Suchkriterien und den Paketnamen "Firefox"

So it looks, that within the context something is not available, when started within a @comspec

Maybe one of the other commands from here might help to work out, what exactly is missing?

Get-Package -Source <string> [-ListAvailable] [-Updates] [-ProjectName] [-Filter <string>] [-First <int>] [-Skip <int>] [-AllVersions] [-IncludePrerelease] [-PageSize]

 

Regards, Rudi.


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

Share this post


Link to post
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

  • Similar Content

    • santoshM
      By santoshM
      How can i exit from a procedure in auto
      Func test() if x=o then     return endif endFunc  
    • Valnurat
      By Valnurat
      Hi
      Small question.
      I trying to find all index in an array with value higher than 7.
      How can that be possible?
    • TrashBoat
      By TrashBoat
      Could someone help me create or give an idea of how to do a incrementing for loop that would do this: https://i.imgur.com/YFUt47H.gifv
      I'm having a hard time figuring it out :S
    • msd1994
      By msd1994
      I have a script that just adds some keyboard shortcuts for things like displaying the current song and artist, moving the window to the side so it won't pop up in my way, and play/pause, next song, previous song (these are the only 3 to still work since they don't need the window handle.)
      In some update recently, Spotify's window class swapped from "[CLASS:SpotifyMainWindow]" to "[CLASS:Chrome_WidgetWin_0]". Using the new class in my controls doesn't seem to work, I've tried getting the window handle from the process handle (_GetHwndFromPID($PID)) but that seems to fail as well.
      Does anybody have some idea of a way I could get this script working again?
       
      edit: seems like discord has the same window class name, so could be some issue with this? Still not sure of a way to solve the issue though, I added a function to get the handle of the active window and can just use that now, but it was able to find it on its own before on spotify startup or script startup which would be preferred.
       
      Thanks!
    • sumandevadiga
      By sumandevadiga
      Hello 
      I would like to Run Outlook macros from Autoit every 1 hour, below script unable to run macros.
      While 1 $Minute = Random(1,59,1) Do Sleep(1000) Until @Min = $Minute ; do whatever ; Since we want it to run randomly once an hour, we need to calculate how much time is left before the hour is up, and sleep that length of time. $s = ((60 - $Minute) * 60) * 1000 Sleep($s) $oOApp = ObjCreate("Outlook.Application") $oOApp.Run("SaveAttachments") ; Run Outlook Macros WEnd  
       
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.