How to turn Password Protected Sharing on or off programmatically

windows 7windows-vista

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.

Best Answer

Probably too late :) , but hopefully useful for others.

The following steps worked just fine for me (it worked on W8 consumer preview too).

to turn it off:

1 - Enable guest account by running

net user guest /active:yes

2 - Obtain guest user SID by running, for example,

wmic useraccount where name='guest' get sid

3 - Obtain write access to registry folder HKLM\SECURITY

4 - Modify the following key, where $SID is the sid obtained in point 2, to:

[HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\$SID\ActSysAc]
@=hex(0):41,00,00,00

5 - restart the machine (until now, I didn't find a better way to make the change effective)

to turn it on again:

[HKEY_LOCAL_MACHINE\SECURITY\Policy\Accounts\$SID\ActSysAc]
@=hex(0):c1,00,00,00

then restart