Wednesday, October 3, 2007

Enabling Windows 2000/XP "File and Printer Sharing" at the Command Line

I've searched high and low and there does not seem to be any way to enable Windows File and Printer Sharing without having someone actually perform the function of clicking the stupid check box. Yes, I've gone through the registry and even did the ol' regmon trick to see what windows was modifying, nothing was obvious. Recently this problem has cropped up again causing me to renew my search for an answer, and an answer I found!

The key here is a little program called "snetcfg" which allows you to add or remove services to the windows networking system. I'm assuming snetcfg stands for "service net configurator" or something like that. Now, this program in itself can't actually check that little box that we've been discussing rather we are going to leverage some of windows' default behaviors against it.

When windows installs a service it enables it by default, what we will be accomplishing with snetcfg is that we will be uninstalling the File and Printer Sharing service and then re-installing it. Once Windows has re-installed the service it enables it by default.

Here's how we do it:
  1. Grab snetcfg.zip
  2. The command line to uninstall Win2K File and Printer Sharing Service is:
    1. snetcfg.exe -v -u MS_Server
  3. The command line to re-install Win2K File and Printer Sharing Service is:
    1. snetcfg.exe -l %windir%\Inf\NETSERV.INF -c s -i MS_Server
I've found Windows XP to be similar, you can just put these lines into a batch file and push it out via a domain login script.

No comments: