Solved

Change IP Address using Run As

Posted on 2011-02-15
5
2,180 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
ID: 34898684
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
ID: 34898785
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
ID: 34898843
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
ID: 34899056
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
ID: 34911858
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

896 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

12 Experts available now in Live!

Get 1:1 Help Now