I've been trying for a while now to programatically enable file sharing
on Windows XP and Windows 2000 for a local application running under a non-domain controlled network, on a computer which has never been authorized for file sharing before.
It appears to me that there is no documented way to share a file or folder unless and until the user manually enables file sharing by using the file manager to either run the network setup wizard, or click the "just enable file sharing" checkbox in response to right clicking the file or folder to be shared in windows file manager and then selecting 'sharing'.
According to Google anyway, the DDK
sample program snetcfg is supposed to do what I want. I've compiled the
DDK version, and also written my own simplified version using ATL.
Neither seems to really work.
Uninstalling with snetcfg.exe works:
snetcfg.exe -v -u MS_Server
But installing starts the server service, but the user still has to use
file manager's user interface to enable file sharing, both on XP and
2000. Neither form of the snetcfg command line works for me:
snetcfg.exe -v -u MS_Server
or the long form
snetcfg.exe -v -l %system%\inf \netserv.inf -c S -i ms_server
I wrote a simplified version of snetcfg that uninstalls ms_server and
then reinstalls it, since some google hits recommend this technique.
In both the ddk sample snetcfg and my simplified version the api calls
all succeed as expected.
I'd appreciate any insights on how to programatically enable file and
printer sharing that anyone might have. An out line of my C++ attempt
grayraven42 [at] gmail [dot] com
// outline version of a c++ program to uninstall
// and then reinstall ms_server
// Get an INetCfg object
HRESULT hr = Cfg.CoCreateInstance(CLSID_CNetCfg, NULL);
// lock the object
hr = Cfg.QueryInterface(&lock);
hr = lock->AcquireWriteLock(
// initialize the configuration object
hr = Cfg->Initialize(0);
// do the uninstall
const HRESULT HrNcc =
// get the configuration class pointer
hr = Cfg->QueryNetCfgClass(&GUID_DEVCLASS_NETSERVICE, IID_INetCfgClass,
// get the setup pointer
// do the actual uninstall
hr = ncClassSetup->DeInstall (ncc, &m_OboToken, NULL);
// clean up
// here we obtain and lock net configuration object Cfg exactly as shown
// variables setup here
// copy netserve.inf using the setup api
BOOL bSetup = SetupCopyOEMInf(
path, // usually c:\windows\inf\netserv.inf
NULL, // other files are in the
// same dir. as primary INF
SPOST_PATH, // first param. contains path to INF
0, // default copy style
szInfNameAfterCopy, // receives the name of the INF
// after it is copied to %windir%\inf
MAX_PATH, // max buf. size for the above
NULL, // receives required size if non-null
NULL); // optionally retrieves filename
// do the actual install
hr = Cfg->QueryNetCfgClass (&GUID_DEVCLASS_NETSERVICE,
hr = ncClassSetup->Install(
0, // <upgrade-from-build-num>
NULL, // answerfile name
NULL, // answerfile section name
// clean up
NET SHARE will only work AFTER you enable file and print sharing via the registry key or via the wizard. The sharing hand will appear under the folder after a net share, but you won't be able to even see the computer from the network until file and print sharing is enabled.
So is there a final solution to enable File and Printer Sharing remotely?
Is there a compiled executable or source that will allow this?
Does this solution work with Windows XP Home as well?
I have a few floating users that use Windows XP Home to access network services and I wanted to be able to use SysInternals PSTools on their systems. I believe that enabling File and Print Sharing enables the default administrative shares necessary for PSTools to work. But I wanted to be able to enable File and Print Sharing remotely.
Can anyone help?
Could someone please tell me where i could get snetcfg.exe and some of the command line switches?
Also , can i access file sharing privileges. As in allowing netowork users to change shared files?
I'd really be greateful if anyone helps , there is'nt much about this on the web.
Hi everyone. I know it's been a very long time since this thread started, but since I was like all of you trying to find a way to remotely enable/disable "File and Printer sharing" and other binded protocols for a specific network adapter, I thought I could give you the solution I found.
There is now a tool called nvspbind that does just that.
It utilizes the INetCfg API.
It is still a little buggy, and unfortunally the guy who coded it does not seem to work on it anymore, but it is still worth to check it out.