2014-12-02 71 views
-1

先生,我想改變我的系統名稱作爲系統名稱+使用批處理文件的IP地址的最後六位數字(例如:如果我的IP是192.168.1.22 PC名稱應PC-001- 022),請幫助我,我需要改變400+系統,我的大學系統名稱更改批處理文件

+0

做這些電腦上運行任何特定的操作系統? – 2014-12-02 13:53:52

回答

1

沒有測試,但是,至少在理論上,這應該工作

@echo off 
    setlocal enableextensions enabledelayedexpansion 

    rem Retrieve ip address. 
    set "ip[4]=" 
    for /f "tokens=2 delims=[]" %%z in ('ping -n 1 -4 ""') do if not defined ip[4] for /f "tokens=1-4 delims=." %%a in ("%%z") do (
     set /a "ip[1]=%%a", "ip[2]=%%b", "ip[3]=%%c", "ip[4]=%%d" 
    ) 

    rem If no ip address available, end process 
    if not defined ip[4] (
     echo Failed to get ip address 
     goto :eof 
    ) 

    rem Prepare the new PC name. Padding is needed 
    set /a "n[1]=ip[3]+1000", "n[2]=ip[4]+1000" 
    set "newName=PC-%n[1]:~-3%-%n[2]:~-3%" 

    rem Chech if renaming is needed 
    if "%computername%"=="%newName%" (
     echo Computer already renamed 
     goto :eof 
    ) 

    rem Are you sure ? 
    echo(
    echo(WARNING : Computer will be renamed from [%computername%] to [%newName%] 
    echo(
    echo(Press Ctrl-C to keep the old name or any other key to rename computer 
    pause > nul 

    rem OK - Do the rename and restart the computer 
    wmic ComputerSystem where Name="%computername%" call Rename Name="%newName%" 
    shutdown /r /c "Restarting to rename computer" 
相關問題