Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

programantically enable file sharing - why doesn't snetcfg.exe work?

39 views
Skip to first unread message

GrayR...@gmail.com

unread,
Jun 28, 2006, 2:04:56 PM6/28/06
to
Howdy,

I've been trying for a while now to programatically enable file sharing
on Windows XP and Windows 2000. 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
follows.

Thanks

Jim Howard
grayraven42 [at] gmail [dot] com

// outline version of a c++ program to uninstall
// and then reinstall ms_server

//uninstall

// Get an INetCfg object
CComPtr<INetCfg> Cfg
HRESULT hr = Cfg.CoCreateInstance(CLSID_CNetCfg, NULL);
//...
// lock the object
hr = Cfg.QueryInterface(&lock);
if (SUCCEEDED(hr))
{ ....
hr = lock->AcquireWriteLock(
c_cmsTimeout,
c_szSampleNetcfgApp,
&szLockedBy);
...
}
// initialize the configuration object

hr = Cfg->Initialize(0);

// do the uninstall
CComPtr<INetCfgComponent> ncc;
const HRESULT HrNcc =
Cfg->FindComponent(A2W(NETCFG_SERVICE_CID_MS_SERVER), &ncc);

// get the configuration class pointer
CComPtr<INetCfgClass> ncClass;

hr = Cfg->QueryNetCfgClass(&GUID_DEVCLASS_NETSERVICE, IID_INetCfgClass,
(void**)&ncClass);

// get the setup pointer
CComPtr<INetCfgClassSetup> ncClassSetup;
ncClass->QueryInterface(IID_INetCfgClassSetup,(void**)&ncClassSetup);

// do the actual uninstall
hr = ncClassSetup->DeInstall (ncc, &m_OboToken, NULL);

// clean up
Cfg->Apply();
Cfg->Uninitialize();
lock->ReleaseWriteLock();

/////////////////////////
//Install MS_Server
//////////////////////
CComPtr<INetCfg> Cfg
CComPtr<INetCfgLock> lock;
// here we obtain and lock net configuration object Cfg exactly as
shown
//above
// 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
CComPtr<INetCfgClassSetup> ncClassSetup;
CComPtr<INetCfgComponent> ncc;

HRESULT hr(E_FAIL);
hr = Cfg->QueryNetCfgClass (&GUID_DEVCLASS_NETSERVICE,
IID_INetCfgClassSetup,(void**)&ncClassSetup);
if(SUCCEEDED(hr))
{
hr = ncClassSetup->Install(
A2W(NETCFG_SERVICE_CID_MS_SERVER),
&m_OboToken,NSF_POSTSYSINSTALL,
0, // <upgrade-from-build-num>
NULL, // answerfile name
NULL, // answerfile section name
&ncc);
// clean up
Cfg->Apply();
Cfg->Uninitialize();
lock->ReleaseWriteLock();
}
return SUCCEEDED(hr);

diptij...@gmail.com

unread,
Jul 10, 2006, 7:13:10 AM7/10/06
to
Hello,
I'm trying to find the network adapters on the system and to activate
the selected one
programatically.

I installed the 2000 DDK in the system
and trying to run the sample example in the network......
but its giving me the error that
Its not finding the defination of the
CLSID_CNetCfg
as well

INetCfg
INetCfgLock
INetCfgClass
INetCfgClassSetup
INetCfgBindingPath
INetCfgBindingInterface
INetCfgComponent
INetCfgComponentBindings
IEnumNetCfgComponent
IEnumNetCfgBindingPath
IEnumNetCfgBindingInterface
INetCfgPnpReconfigCallback


Pls. suggest.

Thanx

Dipti Jaiswal

0 new messages