通过VBScript访问文件夹时传递用户名/密码 [英] Pass a username/password when accessing a folder via VBScript

查看:108
本文介绍了通过VBScript访问文件夹时传递用户名/密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,该脚本旨在从服务器上用户的旧配置文件中检索一些文件并将其复制到新文件中,但是当用户通过服务器连接时,用户无权访问相关文件夹/文件

I have a script that is meant to retrieve some files from a users old profile on a server and copy it to there new one, but the users do not have access rights for the folders/files in question when connecting through the server.

是否可以通过以下功能传递用户名/密码?

Is there a way passing a username/password with the following functions? Thanks.

objFSO.FolderExists(folder_path)
objFSO.CopyFolder(folder_path)
objFSO.CopyFile(folder_path)


推荐答案

您必须将共享映射到驱动器上首先,然后

You have to map the share to a driveletter first, then

persistent = false
set objNetwork = WScript.CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "driveletter:", "\\server\sharename", persistent, "username", "password"

然后使用普通文件系统对象(是否使用驱动器字母)进行复制。
通过这种方式进行身份验证后,就可以使用这些凭据进行其他操作。

Then use the normal filesystemobject to do the copying, using the driveletter or not. Once authenticated this way it's possible to do other operations with these credentials.

这篇关于通过VBScript访问文件夹时传递用户名/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆