且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式连接到网络驱动器并缓存凭据

更新时间:2023-01-02 09:19:42

您可以创建一个使用"

You could create a batch file that uses "NET USE" to connect to your shares. You'd need to use a drive letter for each share, but it'd be super simple to implement.

您的批处理文件如下所示:

Your batch file would look like this:

net use h: \\MACHINE1 <password> /user:<domain>\<user>
net use i: \\MACHINE2 <password> /user:<domain>\<user>
net use j: \\MACHINE3 <password> /user:<domain>\<user>

更新

是否保留连接取决于您为/persistent开关指定的内容.如果您指定是,那么它将在您下次登录时尝试重新连接.如果您指定否,则不会.令人担心的是 documentation 说它默认为您上次使用的值!

Whether the connection remains or not depends upon what you specified for the /persistent switch. If you specified yes, then it will attempt to reconnect upon your next logon. If you specified no then it won't. The worrying this is the documentation says that it defaults to the value that you used last!

如果您指定no,则连接将一直保持到下次重新启动为止.如果您断开VPN连接,则驱动器将不可用(但是,如果您重新连接至VPN,则只要未删除驱动器,该驱动器就应该可用).

If you specified no, the connection will remain until you next reboot. If you drop your VPN connection the drive would be unavailable (but if you reconnect to the VPN the drive should be available as long as you haven't removed it).

我不知道在不映射到驱动器号的情况下使用它的方法,该文档会让您相信这是不可能的.

I don't know of a way to use it without mapping to a drive letter, the documentation would lead you to believe that it isn't possible.

我了解您的问题,您只是在尝试为资源管理器提供正确的凭据,因此它不会再困扰您登录框.使用映射驱动器虽然不完美,但至少可以减轻您的痛苦.

I understand your problem, that you're just trying to give explorer the correct credentials so it stops nagging you with login boxes. Using mapped drives though not perfect will at least alleviate your pain.