我想根据时间从我的电脑中阻止社交媒体。 晚上9点后阻塞,上午11点后解锁(如父母控制) 我试过跟随但失败了。
创建了block.bat
文件
@echo off
(Get-Content C:\Windows\System32\drivers\etc\hosts) | ForEach-Object { $_ -replace "#127.0.0.1 facebook.com", "127.0.0.1 facebook.com" } | Set-Content C:\Windows\System32\drivers\etc\hosts
创建了Unblock.bat
文件
@echo off
(Get-Content C:\Windows\System32\drivers\etc\hosts) | ForEach-Object { $_ -replace "127.0.0.1 facebook.com", "#127.0.0.1 facebook.com" } | Set-Content C:\Windows\System32\drivers\etc\hosts
并将这2个bat文件添加到Task Scheduler。 Block将在上午11点运行,并在晚上9点解锁。
我从PowerShell收到此错误:
Set-Content : The input object cannot be bound because it did not contain the information required to bind all mandatory parameters: Path At line:1 char:140 + ... e "#127.0.0.1 facebook.com", "127.0.0.1 facebook.com" } | Set-Content + ~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (# Copyright (c)...Microsoft Corp.:String) [Set-Content], ParameterBindingException + FullyQualifiedErrorId : InputObjectMissingMandatory,Microsoft.PowerShell.Commands.SetContentCommand
手动运行bat文件什么都不做。
答案 0 :(得分:1)
试试这段代码:
@Echo off
cls & color 0A & echo.
Mode con cols=55 lines=5
Set Copyright=Hackoo 2016
Title Block-UnBlock Facebook by %Copyright%
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
CLS
Echo.
Echo.
ECHO **************************************
ECHO Running Admin shell
ECHO **************************************
::pause
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
Echo.
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************
setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
(
ECHO Set UAC = CreateObject^("Shell.Application"^)
ECHO args = "ELEV "
ECHO For Each strArg in WScript.Arguments
ECHO args = args ^& strArg ^& " "
ECHO Next
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1
)> "%temp%\OEgetPrivileges.vbs"
"%SystemRoot%\System32\WScript.exe" "%temp%\OEgetPrivileges.vbs" %*
exit /B
:gotPrivileges
if '%1'=='ELEV' shift /1
setlocal & pushd .
cd /d "%~dp0"
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
Set Copyright=Hackoo 2016
Title Block-UnBlock Facebook by %Copyright%
Rem If you didn't want to create a shortcut and see the intro on your desktop just comment this line below
If Not Exist %USERPROFILE%\Desktop\Block-UnBlock_Facebook.lnk Goto:Intro
::***********************************************************************************************
:CheckPassword
Mode con cols=55 lines=3
cls & color 0A & echo.
set MyPassword=Hackoo
set "psCommand=powershell -Command "$pword = read-host 'Enter your password' -AsSecureString ; ^
$BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)""
for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p
if %MyPassword%==%password% (Goto:Good) else (Goto:Bad)
exit/b
::***********************************************************************************************
:Good
Cls & Color 0A
echo(
echo Good Password
TimeOut /T 1 /NoBreak>nul
Goto:menuLOOP
::***********************************************************************************************
:Bad
Cls & Color 0C
echo(
echo Bad password
TimeOut /T 1 /NoBreak>nul
Goto:CheckPassword
::***********************************************************************************************
:menuLOOP
Mode con cols=85 lines=8
Cls & color 0B
Title Block and UnBlock Facebook by %Copyright%
echo(
echo( ================================Menu================================
echo(
for /f "tokens=2* delims=_ " %%A in ('"findstr /b /c:":menu_" "%~f0""') do echo %%A %%B
echo(
echo( ====================================================================
set choice=
echo( & set /p choice=Make a choice or hit ENTER to quit: || GOTO :EOF
echo( & call :menu_[%choice%]
GOTO:menuLOOP
::********************************************************************************************
:menu_[1] Blocking Facebook
Mode con cols=85 lines=8
cls & color 0C
Call:SkipLine 3
Call:Tab 6
echo %x% "Deactivate write protection" ...
TimeOut /T 2 /NoBreak>nul
set hostspath=%windir%\System32\drivers\etc\hosts
Set BackupHosts=%AppData%\hosts.hackoo
If Not Exist %BackupHosts% Attrib -R %hostspath% && Type %hostspath% > %BackupHosts%
cls
Attrib -R %hostspath%
(
echo ###########################
echo # Block Facebook %Copyright%#
echo ###########################
echo 127.0.0.1 www.facebook.com
echo 127.0.0.1 facebook.com
echo 127.0.0.1 ok.facebook.com
echo 127.0.0.1 www.ok.facebook.com
echo 127.0.0.1 a.ok.facebook.com
echo 127.0.0.1 www.a.ok.facebook.com
echo 127.0.0.1 facebook.com.au
echo 127.0.0.1 www.facebook.com.au
echo 127.0.0.1 nl-nl.facebook.com
echo 127.0.0.1 www.nl-nl.facebook.com
echo 127.0.0.1 facebook.nl
echo 127.0.0.1 www.facebook.nl
echo 127.0.0.1 login.facebook.com.au
echo 127.0.0.1 www.login.facebook.com.au
echo 127.0.0.1 www-10-01-snc2.facebook.com
echo 127.0.0.1 www-11-01-snc2.facebook.com
echo 127.0.0.1 www-10-03-ash1.facebook.com
echo 127.0.0.1 www-12-08-ash1.facebook.com
echo 127.0.0.1 www-13-08-ash1.facebook.com
echo 127.0.0.1 static.ak.fbcdn.net
echo 127.0.0.1 www.static.ak.fbcdn.net
echo 127.0.0.1 login.facebook.com
echo 127.0.0.1 www.login.facebook.com
echo 127.0.0.1 login.facebook.com.nl
echo 127.0.0.1 www.login.facebook.com.nl
echo 127.0.0.1 fbcdn.net
echo 127.0.0.1 www.fbcdn.net
echo 127.0.0.1 fbcdn.com
echo 127.0.0.1 www.fbcdn.com
echo 127.0.0.1 ads.ak.facebook.com
echo 127.0.0.1 www.ads.ak.facebook.com
echo 127.0.0.1 static.ak.connect.facebook.com
echo 127.0.0.1 www.static.ak.connect.facebook.com
echo 127.0.0.1 login.facebook.com
echo 127.0.0.1 www.login.facebook.com
) > %hostspath%
cls
Call:SkipLine 3
Call:Tab 5
echo %x% "Facebook is Blocked by %Copyright%"
ATTRIB +R %hostspath%
TimeOut /T 2 /NoBreak>nul
Start www.facebook.com
::GOTO :menuLOOP
Exit
::********************************************************************************************
:menu_[2] UnBlocking Facebook
cls & color 0A
Title UnBlocking Facebook ....
Call:SkipLine 3
Call:Tab 5
set hostspath=%windir%\System32\drivers\etc\hosts
Set BackupHosts=%AppData%\hosts.hackoo
If Exist %BackupHosts% Attrib -R %hostspath% && Type %BackupHosts% > %hostspath%
ATTRIB +R %hostspath%
echo %x% "Facebook is UnBlocked by %Copyright%"
TimeOut /T 2 /NoBreak>nul
Start www.facebook.com
Exit
::GOTO :menuLOOP
::******************************************************************************************
:Play
(
echo Play "%~1"
echo Sub Play(URL^)
echo Dim Sound
echo Set Sound = CreateObject("WMPlayer.OCX"^)
echo Sound.URL = URL
echo Sound.settings.volume = 100
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000
echo End Sub
)>%~2
::********************************************************************************************
:SkipLine
For /L %%I In (1,1,%1) Do Echo(
Goto:Eof
::********************************************************************************************
:Tab
set "x="
For /L %%I In (1,1,%1) Do Set "x=!x! "
REM ^-- this is a TAB
goto :eof
::********************************************************************************************
:Intro
Color 0A & Mode con cols=101 lines=57
echo(
echo ` `` ` ` ` `` ``
echo ``` ` ````````` ` `
echo ` .-/+osyhhhhhhhhhhhhyyso+:-` ` `
echo ````/hddddddddddddddddddddddddddhy- `` `
echo `` :mdmdmdmmddddddddddddddddddddddy`
echo ` oNmmmmddddddddddddddddddddddmmmd. `
echo ` yNmNNNmmmmmmmmmmmmmmmmmmmmmmmmmm:
echo ` .dNmNmNNmmNmmmmmmmmmmmmmmmmmmmmmN+ ``
echo ` :NmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmNy ` ``
echo ` oNmmmmNmmmmmmmmmmmmmmmmmmmmmmmmmmm. `
echo ` hNmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmN: ` `
echo `` ` .mNmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmN+ `` `` `
echo ` ` `..-/++osyNmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmNmNy``` ``
echo ` ` `.:+syhddddddmmmNmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmNmyoo/:-.``
echo ` ``-/shhddddddddddddmNNmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmNmdddddddhyo+:-``` ```
echo ` `.+ydddddddddddddddddNNNNmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmdddmddddmmddhyo:.``
echo ``+dddddddddddddddddmmmNNNNmmmmmmmmdddddmddddddddmmdmmmmmmNmdmdddddddddddddddy/`
echo ` `ydddddddddddddddddddmNNNNNmmmmmdddddddddddddddddddddmmmNNNmdddddddddddddddddddd/``
echo omdmdddddddddddddddddmNNNmmmmmmmmddddddddddddddddddddmmNNNmmdmddddddddddddddddddd. `
echo ` omddddddddddddmddddmmdmmmmmmNmmmmmddddddddddddddddmmmmmNmmmdddddddddddddddddddddy` ` `
echo `ymdddddddddddddddddmddddmmmmmmmmmdddddddddddddddddmmmdmddddddddddddddddddddddds. ``
echo ` `+dmdddddmmdmmmmddmmmdddddmmmddddddddddddddddddddddddddddddddddmmddmddddddmh+.` ` `
echo `` ``/shmdmddmmmmmmmddddmmmmmmmmmmdddddddddddddddddddddddddddddmmddmdddddhy+-` ` ` `
echo ` ` ```-/oyhdddmmmmmmmmmmmmmmmmmmdddddddddddddmddddmmmdmmddddddddddhyo/-` ` ` ` `
echo ` ` ` ` ` ``-/+sydddddddddmddmmdmdddmdddddmmmdmmmdddddddhhhhhho/-.` `
echo ``` ` :mNMNNNNNmdhhhhhhhddddddddhdhhhhhhhyyhmmNNNmmd. `
echo ` :mNNNNNMNNNhsooo+++++oyyo+oo++/://++++sNNNNNNmh/ ``
echo ``` :dNNNNNNMNNNdyssoo++/+oyy++o++////+oooohNNNNNNmd/ ` ` `
echo `:dNNNNNNMNNNNmyyssooo+osyy++ooo++++oosssdNNNNNNmdo ` `
echo ``./hNNNNNNNNNNNmNdsyhhoooyoys+/+o+++++yhssymNNNNNNmdy.
echo ` `` .oymNNNNmNNNMNNNNMhosdmdysohho+hs+++sddossmNNNNNNNmdmo````
echo ` ` -/smNNNNNNNNNNNNNMNdosyydmmmdoodNmmddssosmMNmNNNNNmmdds:.`
echo ` ` ` .+dmNNNmNNNNNNNNNNMNdosyssssoo+osoooososmMMNmNNNNmNmmddds:.``
echo ` ``` `` ` ``.-/odNNNNNNmNMNNNNNNMMMMMmssyooooyys++++oohNMMMNmNNNNmNmmmmNNNmdho-` `
echo ` `` `.-/+syhdmNNNNMMNNNNNNNNNNNNmNMNNMNNhso++smms//+oodNNMMNmNmmNNmNNmNmNNNNNNNmhs/.` ` `
echo ` ` .+ydmNNNNNNNNNMNMMNNNNNNNNNNNNNNMMMNMMNmy+/hmdh:++yNNNMMMNNNmmmmmNNmNNNNNNNNNNNNmmhs:.` `
echo ```/dmNNNNNNNMNNNMMMMMMNMNNNNNNNNmNNMMMMMNMNNh+omNo/sdMNMNNMMNNNmmmmmmNNNNNNNNNNNNNNNNmNmds:`` `
echo ``.smmmNNNNNNNNNNNNNNNNMNMNNNMNNmNmNNMNMMMNNNNNNdNmdmNNNNNNMMNNNNNNmmmmNNNNNNNNNNNNNNNNNNNmmmh/` `
echo ``/dmmNmNNNNNNNNNNNNNNNNNNMMNNNNmmNNNMMMMMMMMMMMNMNNMNMNNNNNNNNNNNNNmmmmNNNNNNNNNNNNNNNNNmmNmmmms. `
echo NmmmmNNNmmmmNNNNNNNNNNNMMMNNNNNmNNNNNNNNNNNNNMNNMNNNNNNNNNNNNNNNNNmmmmNNNNNNNNNNNNNNNmmmmNmmmmmh-`
echo mmmmNmNmmmmmmmNNNNNNNNMMMMMMMMNNNmNNNNNNNNNNNNNNNMNNNNNNNNNNNNNNMNNNmmmNNNNNNNNNNNNNNNNNmmmmmmmmmmd:
echo mNNmmmmmmmmmmNNNNNMMMMMMNMNMMMMNNmNNNNNNNNNNNNNNNMNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNmmmmmmmmmmmmmmm
echo NmmmmmmmmmmmNNNNNNNNMMNNNMNNNMMNNNNNNNNNNNNNNNNNNMNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNmmmmmmmmmmmmm
echo(
echo "/ | / | / | ";
echo "$$ | $$ | ______ _______ $$ | __ ______ ______ ";
echo "$$ |__$$ | / \ / |$$ | / | / \ / \ ";
echo "$$ $$ | $$$$$$ |/$$$$$$$/ $$ |_/$$/ /$$$$$$ |/$$$$$$ |";
echo "$$$$$$$$ | / $$ |$$ | $$ $$< $$ | $$ |$$ | $$ |";
echo "$$ | $$ |/$$$$$$$ |$$ \_____ $$$$$$ \ $$ \__$$ |$$ \__$$ |";
echo "$$ | $$ |$$ $$ |$$ |$$ | $$ |$$ $$/ $$ $$/ ";
echo "$$/ $$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$/ $$$$$$/ ";
echo " ";
echo " ";
Set vbsfile=%temp%\Intro.vbs
Set URL=http://hackoo.alwaysdata.net/Intro.mp3
Call:Play %URL% %vbsfile%
Start %vbsfile%
Timeout /T 18 /Nobreak>nul
::********************************************************************
Set MyFile=%~f0
Set ShorcutName=Block-UnBlock_Facebook
(
echo Call Shortcut("%MyFile%","%ShorcutName%"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(CheminApplication,Nom^)
echo Dim objShell,DesktopPath,objShortCut,MyTab
echo Set objShell = CreateObject("WScript.Shell"^)
echo MyTab = Split(CheminApplication,"\"^)
echo If Nom = "" Then
echo Nom = MyTab(UBound(MyTab^)^)
echo End if
echo DesktopPath = objShell.SpecialFolders("Desktop"^)
echo Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
echo objShortCut.TargetPath = Dblquote(CheminApplication^)
echo ObjShortCut.IconLocation = "Winver.exe,0"
echo objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo DblQuote = Chr(34^) ^& Str ^& Chr(34^)
echo End Function
echo ^'**********************************************************************************************
) > %temp%\Shortcutme.vbs
Start /Wait %temp%\Shortcutme.vbs
Del %temp%\Shortcutme.vbs
Goto:CheckPassword
::****************************************************************************************************
:EOF
EXIT
答案 1 :(得分:0)
您无法通过主机阻止Facebook将其转发到localhost。
在路由器或防火墙上执行此操作。
但是,如果适合你,请使用批处理文件。 块
最好使用此vbs
答案 2 :(得分:0)
这是我们的解决方案。
阻止
example:
path: '/{_locale}{_S}example'
defaults: { _controller: 'AppBundle:Example:index' , _locale="de" , _S: "/" }
requirements:
_S: "/?"
_locale: '|de|en|fr'
块
$HostFile = "$($env:windir)\system32\Drivers\etc\hosts"
$Hosts = Get-Content -Path $HostFile
(Get-Content $HostFile) -replace '127.0.0.1 Facebook.com', '#127.0.0.1 Facebook.com' | Set-Content $HostFile