JeffQOOQAAA

Autoit Powershell command can't excute

22 posts in this topic

Hi ALL.

I met a problem.

 

Local $DHCP = "Install-WindowsFeature DHCP -IncludeManagementTools"

ShellExecute("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe")
sleep(2000)
Send($DHCP)
Send("{Enter}")

I have no idea can't normally excute this command in PowerShell

Have anyone seen before ?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I get an error too, but it's not related to autoit, the error is within the poweshell window, so it begs the question, why are you posting it here?

Quote

Install-WindowsFeature : The term 'Install-WindowsFeature' 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.
At line:1 char:1
+ Install-WindowsFeature DHCP -IncludeManagementTools
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-WindowsFeature:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

BTW: this does the same in here:

ShellExecute("powershell.exe", $DHCP)

 

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

yes!  this is error. due to I type this command into powershell directly can normally excute

But can't excute via Autoit, So.... i don't know why......

 

 

Share this post


Link to post
Share on other sites

How about this? what happens?

#RequireAdmin
Local $DHCP = "Install-WindowsFeature DHCP -IncludeManagementTools"
ShellExecute("powershell.exe", $DHCP)

 


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

Still got same error.....

Share this post


Link to post
Share on other sites

What about

Run('powershell '& $DHCP)

 


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Share this post


Link to post
Share on other sites

You need PowerShell running as Administrator try something like:

;~ Change "Get-AppxPackage" to Install-WindowsFeature DHCP -IncludeManagementTools (I believe this is a Windows Server Feature and not included with standard Windows)
PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass Get-AppxPackage' -Verb RunAs}"

Or use a PowerShell Script

Opt('ExpandVarStrings', 1)
PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""@ScriptDir@\FileName.ps1""' -Verb RunAs}"

 

Share this post


Link to post
Share on other sites

 Hi Subz

Do you mean use "Get-AppxPackage"  replace Install-WindowsFeature DHCP -IncludeManagementTools command ? 

But I try this, it will show  many function & cmdlet list, is right?

Share this post


Link to post
Share on other sites

No, "Get-AppxPackage" was just an example, What I meant was replace "Get-AppxPackage" in my example with "Install-WindowsFeature DHCP -IncludeManagementTools" for example:
nb: -ExcutionPolicy and Bypass should only be required for PowerShell script like in my second example above.

PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList 'Install-WindowsFeature DHCP -IncludeManagementTools' -Verb RunAs}"

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hi Subz

I try this command, right?

RunWait(@ComSpec & " /c " & "powershell -noexit -Command " &"{Start-Process PowerShell.exe -ArgumentList 'Install-WindowsFeature DHCP -IncludeManagementTools' -Verb RunAs}")

Share this post


Link to post
Share on other sites

#11 ·  Posted

Yes except except for the quotes, you would probably require something like this 

RunWait(@ComSpec & ' /c powershell -noexit -Command "& {Start-Process PowerShell.exe -ArgumentList ' & "'Install-WindowsFeature DHCP -IncludeManagementTools'" & ' -Verb RunAs}"')

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

Hi Subz.

I''ve tried this commandm but looks like can't normally install DHCP services.

Have any idea for other way?

Share this post


Link to post
Share on other sites

#13 ·  Posted

Can you type the exact command you write in PowerShell to install this?

Share this post


Link to post
Share on other sites

#14 ·  Posted

RunWait(@ComSpec & " /c " & 'powershell -noexit -Command  "& {Start-Process PowerShell.exe -ArgumentList ' & "'Install-WindowsFeature DHCP -IncludeManagementTools'"  & '-Verb RunAs}"')

This it!

Share this post


Link to post
Share on other sites

#15 ·  Posted

Sorry I meant in PowerShell, either the IDE or Shell.

Share this post


Link to post
Share on other sites

#16 ·  Posted

But I type your command , still can't install DHCP

RunWait(@ComSpec & ' /c powershell -noexit -Command "& {Start-Process PowerShell.exe -ArgumentList ' & "'Install-WindowsFeature DHCP -IncludeManagementTools'" & ' -Verb RunAs}"')

Share this post


Link to post
Share on other sites

#17 ·  Posted

What about:

#RequireAdmin
RunWait(@ComSpec & ' /c powershell -noexit -Command "& {Install-WindowsFeature DHCP -IncludeManagementTools}"')

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

Is there an error? What's it say in the windows powershell event log?


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

Share this post


Link to post
Share on other sites

#19 ·  Posted

I got this error

Install-WindowsFeature : The term 'Install-WindowsFeature' 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.
At line:1 char:4
+ & {Install-WindowsFeature DHCP -IncludeManagementTools}
+    ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-WindowsFeature:String)
   [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

 

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