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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to rename folders redirection on user's home share (%homeshare%

Status
Not open for further replies.

oxy6en

Programmer
Oct 15, 2010
7
AU
Hi,

I've created a VBScript called: RenameFolder.vbs

When the user logon for the first time, the script will check user's folders redirection (7_Documents, 7_Desktop and 7_Favorites) on %homeshare% then rename those folders to %homeshare%\Desktop, %homeshare%\Favorites, %homeshare%\Documents.
When the script run successfully, it will create a registry entry "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\RenameFolder"
So, the script will not run again for the second time.

Problem:
1. The script was run without any error but doesn't rename those folders

Could anyone please help me to double check what went wrong with the script?

==================================================================================
Option Explicit

'Declare Variables
Dim strRoot, ObjFSO, WshShell
Dim Shell, UserVar_HOMESHARE, strCheck, strModfy

'Set objects
Set WshShell = CreateObject("WScript.Shell")
Set Shell = WshShell.Environment("PROCESS")
Set ObjFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

strRoot = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\RenameFolder"
strCheck = WshShell.RegRead(strRoot)

'Read Environment Variable
UserVar_HOMESHARE = Shell("HOMESHARE")

If strCheck = "1" Then
'This script has already been executed for this user, do nothing
ElseIf UserVar_HOMESHARE = "" Then
' FolderRedirection is Not renamed, do nothing

Else ObjFSO.MoveFolder "%homeshare%\7_desktop" , "%homeshare%\Desktop"
ObjFSO.MoveFolder "%homeshare%\7_documents" , "%homeshare%\Documents"
ObjFSO.MoveFolder "%homeshare%\7_Favorites" , "%homeshare%\Favorites"

StrRoot = "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\RenameFolder"
strModfy = WshShell.RegWrite(strRoot,"1","REG_SZ")
End If

Set ObjFSO = nothing
Set Shell = nothing
Set WshShell = Nothing

wscript.Quit

=====================================================================================================================
 
Comment out (or remove) the line: "On Error Resume Next". This is suppressing any and all errors that you may be getting. On the next run of the script, if you get an error you will also get a message containing more information on what went wrong & why.
 
Also, perhaps an easier method of renaming a folder

Code:
set objFolder = objFSO.GetFolder("%homeshare%\7_desktop")
objFolder.Name = "Desktop"

-Geates
 
Hi Jges,

I removed the "On Error Resume Next" and still doesn't give me any error messages.
It did create a registry entry on RunOnce but did not rename the folders.
 
Hi Geates

Thanks for your suggestion but your code doesn't work either. Is there any full script that you could share?

Cheers
 
Did you reset the registry entry before the 2nd test run?
 
I just realized, at least for me, %homeshare% is not a vbscript var or referrence. It's just a string literally containing "%homeshare%". What you want to use is replace [tt]%homeshare%[/tt] with [tt]UserVar_HOMESHARE[/tt].

Code:
set objFolder = objFSO.GetFolder([red]UserVar_HOMESHARE[/red] & "\7_desktop")
objFolder.Name = "Desktop"

-Geates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top