8

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

  • 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 Apr 12 '12 at 16:55
  • The Firewall is currently off – JMK Apr 13 '12 at 7:57
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

| improve this answer | |
  • 1
    Thanks for the KB link for netsh advfirewall. That's handy. – Rilgon Arcsinh Apr 12 '12 at 10:22
1

To turn on file and printer sharing only for private profile one can use this command:

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

For Windows 8 or Windows Server 2012 and later OS one can use other command:

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

| improve this answer | |
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.

| improve this answer | |
-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

| improve this answer | |
  • (1) Thank you for providing a link to a page where a similar question is discussed, but it looks like Super User had it first.   (2) Can you explain how this answer differs from the accepted answer? – G-Man Says 'Reinstate Monica' Feb 20 '18 at 20:45
  • (1) the link has more information (2) This command specifies direction – steampowered Feb 21 '18 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.