How do I turn Password Protected Sharing on or off programmatically?

后端 未结 6 705
梦毁少年i
梦毁少年i 2020-12-29 16:24

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 Every

6条回答
  •  旧巷少年郎
    2020-12-29 16:52

    Here is a powershell script that implements paolos answer. It is unpolished as it permits everybody write access to the specific registry key (The [7] part specifies this with regini syntax) and uses a file in C:\ root but works flawless:

    # Get guest user id
    $SID = & "wmic" "useraccount" "where" "name='guest'" "get" "sid" "/Value" | Out-String
    $SID = $SID.Trim().Substring(4)
    
    # Generate regini script
    $PATH = "\Registry\Machine\Security\Policy\Accounts\" + $SID + "\ActSysAc"
    $PATH + " [7]`r`n" + $PATH + "`r`n@ = REG_NONE 4 0x41 0x00 0x00 0x00" >> "C:\firstrun.regini"
    
    # Execute regini script
    & "regini" "C:\firstrun.regini"
    

提交回复
热议问题