Solved

Change IP Address using Run As

Posted on 2011-02-15
5
2,209 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

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 …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

809 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