Jump to content

Run Powershell as Admin - doesnt work no way - (Moved)


Recommended Posts

Hi

 

im trying to build a script that recognises the active network, and then change the ipv4 dns from maually to automatic.

i tryed already with powershell and it works.

now i wanna add the powershell script to my au3 script but on running the script it doesnt run powershell as admin.

 

how can i solve this?

 

this is my powershell script:

Get-Netadapter | ?{$_.Status -in 'Up','Disconnected'} | %{Set-NetIPInterface -InterfaceIndex $_.ifIndex -Dhcp Enabled; Set-DnsClientServerAddress -InterfaceIndex $_.ifIndex}

 

this is my vba script to run the ps1 as admin:

Set oShell = CreateObject("Shell.Application")  
oShell.ShellExecute "powershell", "-executionpolicy bypass -file dns.ps1", "", "runas", 1

 

someone please can help me to make it work with autoit?

 

thanks

Link to comment
Share on other sites

  • Developers
3 minutes ago, svenjatzu said:

this is my vba script to run the ps1 as admin:

Set oShell = CreateObject("Shell.Application")  
oShell.ShellExecute "powershell", "-executionpolicy bypass -file dns.ps1", "", "runas", 1

Should be easy to convert to Autoit3. Just check out the Objxxx() functions in the helpfile and let us know when you have something that doesn't work. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

if you requireadmin for your script, then any other commands you run from the script will also be ran as admin, including powershell commands that invoke .ps1 files

 

(look at post #5 in this thread)

 

 

 

Edited by iamtheky

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

Link to comment
Share on other sites

  • Developers
9 minutes ago, svenjatzu said:

Well this objxxx() doesnt seem to be what im looking for or im to stupid for it

Post your script when you want some help. ;) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

For one-liners, this works just fine:

RunAs("<admin account>", "<Domain>", "<Password>", 0, "powershell.exe -command Start-Sleep 10 | Get-NetAdapter | Out-File <filePath", @WindowsDir)

Even when AutoIt does not run as admin.

For full scripts, something like this is what I normally use:

RunAs("admin account", "<Domain>", "<Password>", 0, "powershell.exe -file <path to file>.ps1", @WindowsDir)

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

svenjatzu,

Then please post the answer to help those who have the same problem in the future.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...