2

在 WinXP (SP2) 中,您可以存储映射的网络密码...

开始->控制面板->用户帐户->选择一个然后从相关任务中选择“管理我的网络密码”。

我通常有大约 25-30 台服务器以这种方式映射到几个不同的帐户/域。问题是在我们的政策更新过程中的某个时候,它们会被清除掉,而将它们全部重新添加回来是一个真正的 PITA。

有谁知道如何使用某种脚本以编程方式添加它们?

澄清一下,最终目标不是映射驱动器,而是实际创建该部分中的条目。这允许我们使用 Windows 身份验证连接到我们的服务器(通过 Dameware、SSMS 等)。

附录:

Mark 的 CredWrite 提示将我带到了这里……

pinvoke.net -- CredWrite (advapi32)

这反过来又把我带到了这里……

Peer Channel Blog -- 应用程序密码安全

两者都被证明非常有帮助。

4

2 回答 2

3
  • cmdkey.exe是该工具的 CLI 版本 - 但我相信它只包含在 Win2003+ 中。我怀疑 XP 的副本会起作用 - 但可能会违反您的 EULA。
  • net use也有一个 savecred 选项,如果你正在映射驱动器
  • 根据这个相当详细的信息,CredMgr 将其数据库存储在 2 个位置。只需备份这些文件就足够了:
    • %APPDATA%\Microsoft\Credentials\%UserSID%\Credentials
    • %USERPROFILE%\Local Settings\Application Data\Microsoft\Credentials\%UserSID%\Credentials
  • 有一个 API 可以读取凭据,CredEnumerate - 但没有直接明显的方法来添加您自己的。几个候选人:
    • CredWrite采用正常的CREDENTIAL,但没有任何内容表明存储超过当前会话。
    • CredUIStoreSSOCredW采用 bPersist 参数 - 但指定“领域”而不是服务器或网络位置。

Edit: D'oh. I missed the PERSIST member of CREDENTIAL. It can be one of the following values:

  • CRED_PERSIST_SESSION: The credential persists for the life of the logon session. It will not be visible to other logon sessions of this same user. It will not exist after this user logs off and back on.
  • CRED_PERSIST_LOCAL_MACHINE: The credential persists for all subsequent logon sessions on this same computer. It is visible to other logon sessions of this same user on this same computer and not visible to logon sessions for this user on other computers. (This is what's stored into the Local Settings file)
  • CRED_PERSIST_ENTERPRISE: The credential persists for all subsequent logon sessions on this same computer. It is visible to other logon sessions of this same user on this same computer and to logon sessions for this user on other computers. This option can be implemented as locally persisted credential if the administrator or user configures the user account to not have roam-able state. For instance, if the user has no roaming profile, the credential will only persist locally. (This is what's stored into AppData)

It looks like CredWrite is the API you want.

于 2008-10-14T01:57:39.820 回答
1

NET USE(命令)和WshNetwork.MapNetworkDrive(windows 脚本主机)是两种常用的网络驱动器映射脚本方法,都允许您指定用户和密码。
正如您所说,我不知道这将如何与存储的密码一起工作/不工作,除了知道如果您将用户选项留空,它将尝试使用当前用户的凭据。

于 2008-10-14T00:17:55.573 回答