Solved

Change IP Address using Run As

Posted on 2011-02-15
5
2,143 Views
Last Modified: 2012-05-11
We have Netbooks that our technicians use. Their user account is a standard user. We cant give them administrative rights on the Netbooks but need to allow them to be able to change their IP Addresses on the Local Area Connection. Is there a way to do this? When I am logged in as them there is no way of right clicking and using Runas or any options? Any ideas? Any 3rd party software?
0
Comment
Question by:LeviDaily
5 Comments
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
Open elevated command-line and type

runas /user:<AdminUser@yourdomain.com> cmd

and in that new window use

netsh interface ip set address name="Local Area Connection" static IPAddress NetworkMask Default Gateway

netsh interface ip set dns "Local Area Connection" static <DNSIPAddress> primary
netsh interface ip set dns "Local Area Connection" static <DNSIPAddress> secondary

where Local Area Connection is a name of NIC card on that PC.

i.e.

netsh interface ip set address name="Local Area Connection" static 192.168.1.10 255.255.255.0 192.168.1.254
netsh interface ip set dns "Local Area Connection" static 192.168.1.1 primary
netsh interface ip set dns "Local Area Connection" static 192.168.1.2 secondary

Regards,
Krzysztof
0
 
LVL 2

Author Comment

by:LeviDaily
Comment Utility
I found this batch file which is AWESOME! The problem is the user has to right click and run as different user. I know we cant save the password for the runas in the batch file. Can I create a .vbs script to use the runas command and have the password saved and call on the batch file below?

 ChangeIPAddress.txt
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
Comment Utility
I'm not an expert in programming but you can try digging in the Internet and convert this batch file to exe file using AutoIt.

AutoIt download
http://www.autoitscript.com/site/autoit/

Then everything will be compiled and they will run only the EXE file :)

Krzsztof
0
 
LVL 28

Expert Comment

by:omgang
Comment Utility
Try this.  Save it as a vbs script.  It issues a runas command calling your batch file.
OM Gang


                intSleep = 250   'milliseconds to wait until we send the password
                strPass = "password"     'admin acount password
                Set objNet = CreateObject("WScript.Network")
      Set wshShell = CreateObject("WScript.Shell")
      strThisComputer = objNet.ComputerName
            
            'build RunAs command so we can execute msg command as priveleged user
      strRunAsCmd = "runas /noprofile /user:" & strThisComputer & "\administrator "

            'build command to send network message
      strNetCmd = "ChangeIPAddress.bat"

      strFullCmd = strRunAsCmd & Chr(34) & strNetCmd & Chr(34)
      wshShell.Run strFullCmd
      WScript.Sleep intSleep
      wshShell.SendKeys strPass & "~"
0
 
LVL 29

Accepted Solution

by:
matrixnz earned 500 total points
Comment Utility
Here is an AutoIT Script I wrote to do the same thing, you just need to change the variables as you see fit (see $VAR...)

Cheers
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>

Example()

Func Example()
 Local $VAR_USERNAME = 'Administrator'
 Local $VAR_PASSWORD = 'Password'
 Local $VAR_LOGONDOM = @ComputerName ;~ @ComputerName will run using local machine account, change to domain name to run with domain credentials
 Local $VAR_SUBNETIP = '255.255.255.0'
 Local $VAR_GATEWYIP = '10.1.1.1'

 $GUI_IPADDRESS = GUICreate('IP Address Configuration', 280, 60)

 $SELECT_DHCP = GUICtrlCreateRadio("Dynamic Address (DHCP)", 10, 10, 260, 20)
 GUICtrlSetResizing($SELECT_DHCP, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 $SELECT_STATIC = GUICtrlCreateRadio("Static IP Address", 10, 30, 210, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 $BUTTON_GO = GUICtrlCreateButton('Go', 230, 30, 40, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 GUICtrlSetState($SELECT_DHCP, $GUI_CHECKED)

 GUICtrlCreateLabel('Static IP:', 10, 63, 100, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 $STATIC_ADDRESS = _GUICtrlIpAddress_Create($GUI_IPADDRESS, 80, 60, 190, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

 GUICtrlCreateLabel('Subnet:', 10, 88, 100, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 $STATIC_SUBNETIP = _GUICtrlIpAddress_Create($GUI_IPADDRESS, 80, 85, 190, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 _GUICtrlIpAddress_Set($STATIC_SUBNETIP, $VAR_SUBNETIP)

 GUICtrlCreateLabel('Gateway:', 10, 113, 100, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 $STATIC_GATEWYIP = _GUICtrlIpAddress_Create($GUI_IPADDRESS, 80, 110, 190, 20)
 GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
 _GUICtrlIpAddress_Set($STATIC_GATEWYIP, $VAR_GATEWYIP)

 GUISetState()

 While 1
  $msg = GUIGetMsg()
  Select
   Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
   Case $msg = $SELECT_DHCP And BitAND(GUICtrlRead($SELECT_DHCP), $GUI_CHECKED) = $GUI_CHECKED
    $WIN_POSITION = WinGetPos('[Active]')
    WinMove('[Active]', '', $WIN_POSITION[0], $WIN_POSITION[1], $WIN_POSITION[2], 88)
   Case $msg = $SELECT_STATIC And BitAND(GUICtrlRead($SELECT_STATIC), $GUI_CHECKED) = $GUI_CHECKED
    $WIN_POSITION = WinGetPos('[Active]')
    WinMove('[Active]', '', $WIN_POSITION[0], $WIN_POSITION[1], $WIN_POSITION[2], $WIN_POSITION[3] + 80)
   Case $msg = $BUTTON_GO And BitAND(GUICtrlRead($SELECT_DHCP), $GUI_CHECKED) = $GUI_CHECKED
    RunAsWait($VAR_USERNAME, $VAR_LOGONDOM, $VAR_PASSWORD, 0, @SystemDir & '\netsh.exe int ip set address name = "Local Area Connection" source = dhcp', '', @SW_HIDE)
    RunAsWait($VAR_USERNAME, $VAR_LOGONDOM, $VAR_PASSWORD, 0, @SystemDir & '\ipconfig.exe /renew', '', @SW_HIDE)
	Exit
   Case $msg = $BUTTON_GO And BitAND(GUICtrlRead($SELECT_STATIC), $GUI_CHECKED) = $GUI_CHECKED
    RunAsWait($VAR_USERNAME, $VAR_LOGONDOM, $VAR_PASSWORD, 0, @SystemDir & '\netsh.exe interface ip set address "Local Area Connection" static ' & _GUICtrlIpAddress_Get($STATIC_ADDRESS) & ' '  & _GUICtrlIpAddress_Get($STATIC_SUBNETIP) & ' ' & _GUICtrlIpAddress_Get($STATIC_GATEWYIP) & ' 1', '', @SW_HIDE)
	Exit
  EndSelect
 WEnd
EndFunc

Open in new window

IPConfiguration.jpg
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now