標籤

bat (52) 作品 (38) python (21) shell (17) windows (11) 虛擬機 (11) php (10) CPP (6) KMS (6) 程式設計 (6) docker (5) 使用教學 (5) xoops (4) 公文 (4) Apache2 (3) Excel (3) juniper (3) 資料庫 (3) mysql (2) 免動手 (2) 資料結構 (2) 軟體廣播 (2) 電腦維修 (2) Android Studio (1) Apple IPAD管理 (1) Arduino (1) CSS (1) LAMP (1) NAS (1) Ubuntu (1) VHD (1) Windows Server (1) 原因 (1) 程式應用 (1) 程式積木 (1) 編輯器 (1) 雲端硬碟 (1)

2021年3月30日 星期二

只要會用滑鼠點兩下,就能將hosts 取代學生機的hosts

   資訊組長管理電腦教室。遇到學生上FB、遊戲網站時,需要對hosts 做修改。於是編輯好hosts,要下載自己編輯好的hosts到學生機上的hosts。總是要經過好幾道手續,點好幾次滑鼠,才能到。那有沒有比較好的方法,能夠解決?

   有沒有一個更快的方式,讓我只要點兩下,就可以將C:\Windows\System32\drivers\etc\hosts 更名hosts_今天日期後,再複製手上的hosts到C:\Windows\System32\drivers\etc\。一氣呵成。

教學影片:


目的:
1.將C:\Windows\System32\drivers\etc\hosts 更名hosts_今天日期(當作備份)
2.複製手上的hosts到C:\Windows\System32\drivers\etc\。

檔案名稱:CopyHosts2EtcBK.bat
檔案內容:
@echo off
REM ---------------以下是程式碼,不需更改---------------
REM :: BatchGotAdmin (Run as Admin code starts)
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"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
REM :: BatchGotAdmin (Run as Admin code ends)
REM :: Your codes should start from the following line
REM 取得今天的年、月、日 (自動補零)
SET TodayYear=%date:~0,4%
SET TodayMonthP0=%date:~5,2%
SET TodayDayP0=%date:~8,2%
REM  設定現在所處的目錄與系統目錄C:\Windows\System32\drivers\etc\
set NowDir=%~dp0
set TargetDir=C:\Windows\System32\drivers\etc\
REM 到系統目錄C:\Windows\System32\drivers\etc\
cd %TargetDir%
REM  更改檔名hosts hosts_今天日期(年月日)
rename hosts hosts_%TodayYear%_%TodayMonthP0%_%TodayDayP0%
REM  複製現在所處的目錄的hosts 到系統目錄C:\Windows\System32\drivers\etc\hosts
copy %NowDir%hosts hosts
exit

目的:
1.將手上的hosts取代C:\Windows\System32\drivers\etc\hosts。

檔案名稱:CopyHosts2Etc.bat
檔案內容:
REM ---------------以下是程式碼,不需更改---------------
@echo off
REM  設定現在所處的目錄與系統目錄C:\Windows\System32\drivers\etc\
set NowDir=%~dp0
set TargetDir=C:\Windows\System32\drivers\etc\
REM  複製現在所處的目錄的hosts 到系統目錄C:\Windows\System32\drivers\etc\hosts
copy %NowDir%hosts %TargetDir%hosts
exit


沒有留言:

張貼留言

只要點兩下,傳統右鍵選單改回Win11右鍵選單

系列文章: 1. 只要點兩下,就能將Win11 右鍵選單 回復 傳統右鍵選單 2. 只要點兩下,傳統右鍵選單改回Win11右鍵選單 上一篇提到只要點兩下,就能將Win11選單回到傳統選單。但是有沒有方法能夠回到Win11選單呢?                    ...