简体   繁体   中英

'Permission denied' when checking if a file exists in VBScript

I have a VBS script that is to copy a file from an old user profile to a new one, if it exists, but I'm being shown a 'Permission denied' error when using the objFSO.FileExists() method.

To check the file, I map a drive (working fine, and objFSO.FolderExists() checks are working ok) and pass my username/password (I am an admin, so have access to all profiles, but this is even failing on my own profile).

Full scrip is in this pastebin (Line 106 for the code in question), I'd be greatful for some tips. Thanks.

The mapping method with user/password often gives trouble because the script runs in another security context than the user you use to do the mapping. You do need the mapping though to get permission to read the file so the safest to do is use the mapping but afterward use the UNC to access the file, not the path with the driveletter.

So instead of

old_nicknames_file_path = "J:\" & user_name & "\Application Data\Microsoft\Outlook"

use

old_nicknames_file_path = "\\server\d$\__OLD-PROFILES\" & user_name & "\Application Data\Microsoft\Outlook"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM