• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2581
  • Last Modified:

Change IP Address using Run As

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
LeviDaily
Asked:
LeviDaily
1 Solution
 
Krzysztof PytkoActive Directory EngineerCommented:
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
 
LeviDailyAuthor Commented:
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
 
Krzysztof PytkoActive Directory EngineerCommented:
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
 
omgangCommented:
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
 
matrixnzCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now