rscl Posted November 17, 2010 Share Posted November 17, 2010 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 Link to comment Share on other sites More sharing options...
CodyBarrett Posted November 17, 2010 Share Posted November 17, 2010 RunWait (@COMSPEC & 'netsh interface ipv4 set address "local area connection" static 192.168.1.52 255.255.255.0 192.168.1.85 1') [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
wakillon Posted November 17, 2010 Share Posted November 17, 2010 Have you try this way ? #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.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
CodyBarrett Posted November 17, 2010 Share Posted November 17, 2010 Have you try this way ? #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. [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
rscl Posted November 18, 2010 Author Share Posted November 18, 2010 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 Link to comment Share on other sites More sharing options...
BrewManNH Posted November 18, 2010 Share Posted November 18, 2010 (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 November 18, 2010 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 GudeHow 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 Link to comment Share on other sites More sharing options...
rscl Posted November 19, 2010 Author Share Posted November 19, 2010 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. Link to comment Share on other sites More sharing options...
Skrip Posted November 19, 2010 Share Posted November 19, 2010 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] Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 19, 2010 Share Posted November 19, 2010 RunAs shouldn't be the problem at all. Are you getting an error or is the program just not starting? Link to comment Share on other sites More sharing options...
rscl Posted November 19, 2010 Author Share Posted November 19, 2010 @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. Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 19, 2010 Share Posted November 19, 2010 Try setting the logon flag to 2 rather than 0. 2 is network credentials only. Link to comment Share on other sites More sharing options...
rscl Posted November 19, 2010 Author Share Posted November 19, 2010 @ 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 Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 20, 2010 Share Posted November 20, 2010 Well that doesn't make any sense then. You're using the same account for both RunAsWait and for the right click run. So what could be different? Link to comment Share on other sites More sharing options...
rscl Posted November 20, 2010 Author Share Posted November 20, 2010 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!!!! Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 20, 2010 Share Posted November 20, 2010 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. Link to comment Share on other sites More sharing options...
rscl Posted November 21, 2010 Author Share Posted November 21, 2010 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 Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 21, 2010 Share Posted November 21, 2010 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. Link to comment Share on other sites More sharing options...
rscl Posted November 22, 2010 Author Share Posted November 22, 2010 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 Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 22, 2010 Share Posted November 22, 2010 (edited) If it can be done in C, it can be done in AutoIt. However, it requires a bit of research on my part. I am going to stick with my original assumption of no until I find anything though. Edited November 22, 2010 by Richard Robertson Link to comment Share on other sites More sharing options...
Montfrooij Posted October 28, 2013 Share Posted October 28, 2013 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now