How can I turn on File and Printer sharing, and the Firewall from the Windows command line

7

2

I am using PsExec to access cmd on a Windows 7 computer on my network, and I want to turn on File and Printer Sharing, followed by the Windows firewall without having to get up and walk all the way to the computer.

What commands do I need to use to do this?

Thanks

JMK

Posted 2012-04-12T09:54:27.173

Reputation: 2 839

I thought psexec required file and print sharing before it would remotely connect. How can you remotely enable it, if you can't connect to remotely enable it? – Zoredache – 2012-04-12T16:55:57.847

The Firewall is currently off – JMK – 2012-04-13T07:57:45.843

Answers

13

This command should take care of the File and Printer Sharing:

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

For the firewall:

netsh advfirewall set currentprofile state on  

I've tried them just now, and its seems to work for me.

For any additional information see Microsofts KB article: http://support.microsoft.com/kb/947709

Patrick Jørgensen

Posted 2012-04-12T09:54:27.173

Reputation: 528

1Thanks for the KB link for netsh advfirewall. That's handy. – Rilgon Arcsinh – 2012-04-12T10:22:03.070

0

You can use the net start command to start a service. For example:

net start "Windows Firewall"

From my limited investigation, though, File and Printer Sharing is not a service invokable by name at a CLI. Windows Firewall is, however.

Rilgon Arcsinh

Posted 2012-04-12T09:54:27.173

Reputation: 311

-1

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

see here: https://serverfault.com/a/739272/83850

steampowered

Posted 2012-04-12T09:54:27.173

Reputation: 2 109

(1) Thank you for providing a link to a page where a similar question is discussed, but it looks like [SU] had it first.   (2) Can you explain how this answer differs from the accepted answer? – G-Man Says 'Reinstate Monica' – 2018-02-20T20:45:04.347

(1) the link has more information (2) This command specifies direction – steampowered – 2018-02-21T02:14:21.440