Script works on 7 but not XP

Discussion in 'Software' started by trunolimit, Mar 13, 2015.

  1. trunolimit

    trunolimit Private E-2

    Hello World,

    Can anyone help me understand why this script works on windows 7 but doesn't work on xp? This is a combination of 2 scripts I found on the Google. The first half gets me admin rights and the second half is supposed to change the DNS IP


    REM
    @echo off

    :: BatchGotAdmin
    :-------------------------------------
    REM --> Check for permissions
    >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

    REM --> If error flag set, we do not have admin.
    if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
    ) else ( goto gotAdmin )

    :UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params = %*:"=""
    echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

    :gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"

    @echo off


    set DNS1=10.50.0.117
    set DNS2=10.50.0.118
    set DNS3=10.55.32.23
    set DNS4=10.55.31.27

    for /f "tokens=1,2,3*" %%i in ('netsh int show interface') do (
    if %%i equ Enabled (
    echo Changing "%%l" : %DNS1% + %DNS2% + %DNS3% + %DNS4%
    netsh int ipv4 set dns name="%%l" static %DNS1% primary validate=no
    netsh int ipv4 add dns name="%%l" %DNS2% index=2 validate=no
    netsh int ipv4 add dns name="%%l" %DNS3% index=3 validate=no
    netsh int ipv4 add dns name="%%l" %DNS4% index=4 validate=no
    )
    )

    ipconfig /flushdns

    :EOF
    ipconfig /all
    cmd.exe
     
  2. GermanOne

    GermanOne Guest

    There is no UAC on XP. For that reason it makes no sense to have a "runas" verb for the ShellExecute method in VBScript. Thus, it doesn't even exist on XP.
    So the thing under XP is that either your account already has elevated permissions or you are not able to execute commands that require administrative rights.

    There is the RUNAS Batch command that enables you to run commands or Batch files in a different user account (e.g. "Administrator"). You would need the Administrators password though.
     
  3. trunolimit

    trunolimit Private E-2

    OK. I do have the admin password. So if I take out the first half it should work?

    I'm just trying to avoid having to log out and log back in as admin.

    The error I'm getting is as follows: (I've noticed that names= is not becoming what it should be)

    C:\WINDOWS\system32>REM
    Changing "Area Connection" : 10.50.0.117 + 10.50.0.118 + 10.55.32.23 + 10.55.31.
    27
    The following command was not found: int ipv4 set dns "name=Area Connection" sta
    tic 10.50.0.117 primary validate=no.
    The following command was not found: int ipv4 add dns "name=Area Connection" 10.
    50.0.118 index=2 validate=no.
    The following command was not found: int ipv4 add dns "name=Area Connection" 10.
    55.32.23 index=3 validate=no.
    The following command was not found: int ipv4 add dns "name=Area Connection" 10.
    55.31.27 index=4 validate=no.
    Changing "Area Connection 2" : 10.50.0.117 + 10.50.0.118 + 10.55.32.23 + 10.55.3
    1.27
    The following command was not found: int ipv4 set dns "name=Area Connection 2" s
    tatic 10.50.0.117 primary validate=no.
    The following command was not found: int ipv4 add dns "name=Area Connection 2" 1
    0.50.0.118 index=2 validate=no.
    The following command was not found: int ipv4 add dns "name=Area Connection 2" 1
    0.55.32.23 index=3 validate=no.
    The following command was not found: int ipv4 add dns "name=Area Connection 2" 1
    0.55.31.27 index=4 validate=no.
    Changing "" : 10.50.0.117 + 10.50.0.118 + 10.55.32.23 + 10.55.31.27
    The following command was not found: int ipv4 set dns name= static 10.50.0.117 p
    rimary validate=no.
    The following command was not found: int ipv4 add dns name= 10.50.0.118 index=2
    validate=no.
    The following command was not found: int ipv4 add dns name= 10.55.32.23 index=3
    validate=no.
    The following command was not found: int ipv4 add dns name= 10.55.31.27 index=4
    validate=no.
    Changing "" : 10.50.0.117 + 10.50.0.118 + 10.55.32.23 + 10.55.31.27
    The following command was not found: int ipv4 set dns name= static 10.50.0.117 p
    rimary validate=no.
    The following command was not found: int ipv4 add dns name= 10.50.0.118 index=2
    validate=no.
    The following command was not found: int ipv4 add dns name= 10.55.32.23 index=3
    validate=no.
    The following command was not found: int ipv4 add dns name= 10.55.31.27 index=4
    validate=no.

    Windows IP Configuration

    Successfully flushed the DNS Resolver Cache.
     
  4. trunolimit

    trunolimit Private E-2

    So I guess the question is why is "name=Area Connection" not becoming "Local Area Connection"
     
  5. GermanOne

    GermanOne Guest

    Well, INT should be actually INTERFACE. Maybe this abbreviation was unknown in the XP version of NETSH. Try to replace int with interface in your code.
     
  6. GermanOne

    GermanOne Guest

    How does the Output look like if you execute
    Code:
    netsh int show interface
    or
    Code:
    netsh interface show interface
    in a CMD window or a separate Batch file?
     
  7. trunolimit

    trunolimit Private E-2

  8. trunolimit

    trunolimit Private E-2

    So that's where things get interesting. On XP it returns nothing, on 7 it returns all networked interfaces

    http://i24.photobucket.com/albums/c42/trunolimit/winxp_zpspudjnfyu.png
     
  9. trunolimit

    trunolimit Private E-2


    I'm a newb so it looks like I can't post pictures yet but on windows XP it returns nothing.

    very interesting. So now I either have to find a substitute command that returns all the installed network interfaces or find out why it returns nothing.
     
  10. trunolimit

    trunolimit Private E-2

    OK so it's definitely a privilege problem. If I right click CMD and run it as admin "netsh int show interface" returns the values it suppose to return. However, when I just launch CMD without running it as admin "netsh int show interface" returns nothing.

    So I have to find out how to run scripts as admin automatically on XP.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds