如何從 Windows 命令列開啟檔案和印表機共用以及防火牆

如何從 Windows 命令列開啟檔案和印表機共用以及防火牆

我正在使用 PsExec 在我的網路上的 Windows 7 電腦上存取 cmd,並且我想打開File and Printer Sharing,然後是 Windows 防火牆,而不必起身一路走到電腦前。

我需要使用什麼命令來執行此操作?

謝謝

答案1

此命令應負責文件和印表機共用:

netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes  

對於防火牆:

netsh advfirewall set currentprofile state on  

我剛剛嘗試過它們,它似乎對我有用。

有關任何其他信息,請參閱 Microsoft 的知識庫文章:http://support.microsoft.com/kb/947709

答案2

若要僅為私人設定檔開啟檔案和印表機共用,可以使用下列命令:

netsh firewall set service type=fileandprint mode=enable profile=standard

對於 Windows 8 或 Windows Server 2012 及更高版本的作業系統,可以使用其他命令:

wmic /namespace:\\Root\StandardCimv2 path MSFT_NetFirewallRule where (RuleGroup="@FirewallAPI.dll,-28502" and Profiles=2) call enable

答案3

您可以使用該net start命令來啟動服務。例如:

net start "Windows Firewall"

不過,根據我有限的調查,文件和印表機共用不是可以在 CLI 上透過名稱呼叫的服務。然而,Windows 防火牆是。

答案4

netsh advfirewall firewall set rule name="File and Printer Sharing (SMB-In)" dir=in new enable=Yes

看這裡: https://serverfault.com/a/739272/83850

相關內容