Jump to content

Recommended Posts

Posted

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

  • Developers
Posted
  On 4/4/2019 at 7:55 PM, 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

Expand  

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

Posted
  On 4/4/2019 at 7:59 PM, Jos said:

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

Expand  

Thanks i gonna look for it : )

Posted (edited)

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

  Reveal hidden contents

  • Developers
Posted
  On 4/4/2019 at 8:12 PM, svenjatzu said:

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

Expand  

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

  • Moderators
Posted

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!

  • 2 weeks later...
  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted

My sollution is, drop the project to the archive untill its gonna be urgent to finish it, in between i set the changes by hand.

But ofc ass soon as i restart the project and finish it i gonna add the code : )

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
  • Recently Browsing   0 members

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