Jump to content

Recommended Posts

Posted

Hello All,

I am trying hard to get a simple script working.

I need a simple script which will set the IP, NM & Gateway for a non-admin user using predefined admin credentials.

OS: Windows 7 32 Bit

Now sure why, but the script would just not work.

#include <WindowsConstants.au3>
#include <INet.au3>


Global $sUserName = "admin"
Global $sPassword = "mypass"

if isadmin() then
            msgbox(16,"Announce", "I am ADMIN")
            RunWait ('netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1')
Else
            msgbox(16,"Announce", "I am NOT ADMIN")
            $cmnd = 'c:\windows\system32\cmd.exe /c netsh interface ipv4 set address "Local Area Connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1'
            RunAsWait ($sUserName, @ComputerName, $sPassword, 0, $cmnd)
EndIf

Any help from forum members is highly appreciated.

Thx

Sanjay

Posted

RunWait (@COMSPEC & 'netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1')

Posted

Have you try this way ? Posted Image

#include <Process.au3>
_RunDos ( 'netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )
; or
RunWait ( @ComSpec & ' /c netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Posted

Have you try this way ? Posted Image

#include <Process.au3>
_RunDos ( 'netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )
; or
RunWait ( @ComSpec & ' /c netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )

nice example.
Posted

Hi,

Tried both option, none worked!

Pls see attached screenshot.

Windows 7, logged in as ADMIN.

But if I compile the script and right-click on the executable and Run-As-Admin, then it works fine.

What should be my next step so resolve this....

Pls help.

Thx

Sanjay

post-58737-0-18532800-1290074605_thumb.j

Posted (edited)

On Windows 7 you need a command line similar to this:

netsh interface ipv4 set address name="Local Area Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1

You need the name= before the connection name for the netsh command at least that's what the help file for it says.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Hi,

The command works fine, but only after I compile the script and right-click on the executable and Run-As-Admin.

I am creating this script for it to be used by non-admin users.

My question is what changes in the script are required such that the script/command is executed as an ADMINISTRATOR.

I tried the 'RunAs' option, but it did not help.

Seems like RunAs is only good to execute an external program and not for system commands.

Pls help how do I go about solving this.

Thx in advance.

Posted

Hi,

The command works fine, but only after I compile the script and right-click on the executable and Run-As-Admin.

I am creating this script for it to be used by non-admin users.

My question is what changes in the script are required such that the script/command is executed as an ADMINISTRATOR.

I tried the 'RunAs' option, but it did not help.

Seems like RunAs is only good to execute an external program and not for system commands.

Pls help how do I go about solving this.

Thx in advance.

Not possible. Use @RequireAdmin

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Posted

@Skrip,

If I use RequireAdmin, the compiled-script, when executed, asks for a admin password.

@ Richard,

I have tried RunAs also, but it does not change the LAN parameters.

#include <Process.au3>

$sUserName = "admin"
$sPassword = "aaaaaa"
$cmnd = @ComSpec & ' /c netsh interface ipv4 set address name="Local Area Connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1'
;_RunDos ( 'netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )

; or
;RunWait ( @ComSpec & ' /c netsh interface ipv4 set address name="Local Area Connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )
RunAsWait($sUserName, @ComputerName, $sPassword, 0, $cmnd, @SystemDir)

There are no errors, the compiled-script executes, but the LAN properties does not change.

If I Right-Click on the compiled-script and use Run-As-Administraor, enter the Admin password, the compiled-script works as expected.

Pls help..

Thx again.

Posted

@ Richard, Thx for your suggestion.

#include <Process.au3>

$sUserName = "admin"
$sPassword = "marian50"
$cmnd = @ComSpec & ' /c netsh interface ipv4 set address name="Local Area Connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1'
;_RunDos ( 'netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )

; or
;RunWait ( @ComSpec & ' /c netsh interface ipv4 set address name="Local Area Connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1' )
RunAsWait($sUserName, @ComputerName, $sPassword, 2, $cmnd, @SystemDir)

Still same problem.

If I Right-Click on the compiled-script and use Run-As-Administraor, enter the Admin password, the compiled-script works as expected.

A simple double click on compiled-script does not change network properties, nor any errors

Pls help.

Thx

Posted

I couldn't agree more and I am pulling my hair...

Could there be any Windows 7 issue, like permissions, user settings or anything like that ??

I am totally lost for options now...

SOS!!!!

Posted

I have to assume it's part of the security model. It's probably to keep programs that would trigger UAC from running without triggering UAC.

I guess you'll have to either manually right click and run as admin or change the manifest to make the script trigger the UAC prompt itself.

Posted

Unfortunately, providing admin password to users is not a good idea.

The same script runs well on XP, its Win7 which is giving me difficult time.

I will have to continue searching a solution for this problem.

I am hopeful someone will have a solution.

Thx

Sans

Posted

Well, you have to understand that UAC is to prevent programs from accessing administrative powers without the consent of the user. When you log in, you are using a standard user token every time. When you "run as admin", it uses a second, more powerful user token.

It's a good security model but does create some headaches when trying to do large scale changes.

Posted

Point taken, but there has to be programmatic ways to run applications with admin privileges; with the admin password embedded in the application.

My quest is to find such a way.

Pls let me know if this is possible, if not, can this be achieved using a .NET or C or any other language.

Thx again.

Sans

  • 2 years later...
Posted

Long time ago, but since I faced a similar problem (with the same kind of script) I did find some sort of a solution that worked for me. 
When adding

#RequireAdmin

at the beginning of my script, it now at least gives the user a a warning that it tries to make a changes. 

That way a user sees why the program does not work. 

If the user is (local) admin, it can make these changes (the program works). 

I am using: 

RunWait (  @ComSpec & ' /c netsh interface ipv4 set address name="' & $sCon & '" static ' & $sIP & ' ' &  $sSub & ' ' &  $sSGat & ' 1', "", @SW_HIDE)
RunWait (  @ComSpec & ' /c netsh interface ipv4 set dns name="' & $sCon & '" static ' & $sVDns , "", @SW_HIDE)
RunWait (  @ComSpec & ' /c netsh interface ipv4 set wins name="' & $sCon & '" static ' & $sADns, "", @SW_HIDE)

to change the IP settings. 

Hope this is of any help!

Peter

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