Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Permissions Denied Error when moving a folder

Status
Not open for further replies.

Sentinel7even

IS-IT--Management
May 10, 2007
2
US
I am trying use a logon script to redirect a users internet favorites to their home folder. I also want to move their current favorites folder which resides localy on their computer to their home folder. The script I came up with is

Code:
Set WSHShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

strHomeShare = WSHShell.ExpandEnvironmentStrings("%HOMESHARE%")
strUserProfile = WSHShell.ExpandEnvironmentStrings("%USERPROFILE%")

objFSO.MoveFolder strUserProfile & "\Favorites", strHomeshare & "\Favorites"

sFavorites = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Favorites" 
WshShell.RegWrite sFavorites, strHomeshare & "\Favorites", "REG_EXPAND_SZ"

When you run this you get a permission dennied error. The weird thing is I can go in and manually move the folder withh no problems. But when trying to do it from the script I dont have permissions. Anyone got any Ideas?
 
Move folder moves the folder from one place to another. Do you want to move the folder or the contents of the folder?

When you do it manually, are you moving the folder or the contents?
 
I'd move the folder after the registry hack ...
 
I am trying to move the entire folder. I encounter no problems when doing this manually...
 
Despite the illusion of a security error, it is often related to trailing backslash and existence of destined folder before moving.

documentation said:
If source contains wildcards or destination ends with a path separator (\), it is assumed that destination specifies an existing folder in which to move the matching files. Otherwise, destination is assumed to be the name of a destination folder to create. In either case, three things can happen when an individual folder is moved:

If destination does not exist, the folder gets moved. This is the usual case.

If destination is an existing file, an error occurs.

If destination is a directory, an error occurs.

An error also occurs if a wildcard character that is used in source doesn't match any folders. The MoveFolder method stops on the first error it encounters. No attempt is made to roll back any changes made before the error occurs.
Checking more rigorously the existence of the folders in question. Also how about add a backslash to the destined folder?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top