David Gard
David Gard

Reputation: 12047

'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.

Upvotes: 0

Views: 1377

Answers (1)

peter
peter

Reputation: 42192

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"

Upvotes: 1

Related Questions