views:

453

answers:

2

Windows Vista and 7 has this switch in Network and Sharing Center. It's on by default, and that prevents unauthenticated access to shares even if they're shared with Everyone (like the Public folder). I need to teach my application to turn it on and off automagically. How? I suspect there is a value somewhere in the registry that's responsible for this, but I have no idea how to find it.

+1  A: 

Export the complete register as 1.reg, turn sharing on (or off, if it was on), export to 2.reg and check for the differences?

To be able to use the diff utility, export the files in Win9X/NT4 registration files (*.reg) -format

Kimvais
The files only show changes in MuiCache and MRUListEx (whatever those are) in HKEY_USERS. Note, the switch I'm looking for is system wide and should be in HKEY_LOCAL_MACHINE.
CannibalSmith
Ok, so apparently it is not in the reg :(
Kimvais
@CannibalSmith: MRUListEx is for "most recently used (MRU)" items, so that they'll appear higher in lists that contain things you've recently been using.
John Feminella
A: 

It is in the registry just not necessarily in the place you are expecting (it is in the SAM). From what I can tell all that setting does is enable or disable the guest account, so, well, just enable or disable the account.

You didn't say what you programming language you are using, so here is some simple C code to enable an account, if you need anything else I am sure there is plenty around via google.

#include <LM.h>
#pragma comment(lib, "Netapi32.lib")

BOOL EnableUser(LPCWSTR lpUserName, BOOL bEnable)
{
    BOOL bRet = FALSE;
    DWORD dwLevel = 1008;
    LPUSER_INFO_1 ui1;
    USER_INFO_1008 ui1008;
    NET_API_STATUS nStatus;

    nStatus = NetUserGetInfo(NULL, lpUserName, 1, (LPBYTE*)&ui1);
    if(nStatus == NERR_Success)
    {
        ui1008.usri1008_flags = ui1->usri1_flags;
        if(bEnable)
        {
            ui1008.usri1008_flags &= ~UF_ACCOUNTDISABLE;
        }
        else
        {
            ui1008.usri1008_flags |= UF_ACCOUNTDISABLE;
        }

        nStatus = NetUserSetInfo(NULL, lpUserName,  dwLevel, (LPBYTE)&ui1008, NULL);
        NetApiBufferFree(ui1);
        if(nStatus == NERR_Success)
        {
            bRet = TRUE;
        }   
    }

    return bRet;
}
tyranid
Your code neither disables Password Protected Sharing nor enables the Guest account. I stepped through it to make sure all API calls return 0. Also, enabling the Guest account manually through Control Panel doesn't affect Password Protected Sharing.
CannibalSmith