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

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

4 Answers 4

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

1
  • 1
    Thanks for the KB link for netsh advfirewall. That's handy. Apr 12, 2012 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

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.

-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

2
  • (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? Feb 20, 2018 at 20:45
  • (1) the link has more information (2) This command specifies direction Feb 21, 2018 at 2:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .