我想根據時間從我的電腦中阻止社交媒體。 下午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文件到任務計劃程序。 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
並手動運行該批處理文件不執行任何操作。
嗨,什麼不起作用?蝙蝠文件?計劃的任務?請編輯您的問題以包含此內容。 – sodawillow
請詳細描述一下這意味着你失敗的原因 –
在powershell工程文件'(Get-Content test.txt)中運行一個測試腳本。 ForEach-Object {$ _ -replace「from」,「to」} | Set-Content test.txt'這段代碼完美地工作。但是當我更改路徑並從蝙蝠運行它不工作。 – Nithee