Jump to content

How to move "My Document" to another location?


jackrabbit
 Share

Recommended Posts

I plan to move all the "My Document" for all account from one machine to another location. I know how to do it manually. But it is tedious to do this for all accounts. I want to write a script to do it. I am new to AutoIt. Would someone tell me which function should I use? If you can provide some sample code, that would be great.

Thanks.

Link to comment
Share on other sites

I plan to move all the "My Document" for all account from one machine to another location. I know how to do it manually. But it is tedious to do this for all accounts. I want to write a script to do it. I am new to AutoIt. Would someone tell me which function should I use? If you can provide some sample code, that would be great.

Thanks.

Look in the help for

DirCreate

DirCopy

FileMove

FileCopy

Use the examples in the help to learn from, and use the forum search facilities to find examples.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

do you want to move the whole folder or just want to change it's default location?

Website: www.cerescode.comForum: www.forum.cerescode.comIRC: irc.freenode.net , Channel: #Ceres--------------------Autoit Wrappers, Great additions to your script (Must See) (By: Valuater)Read It Befor Asking Question Click Here...--------------------Join Monoceres's Forums http://www.monoceres.se--------------------There are three kinds of people: Those who make things happen, those who watch things happen, and those who ask, ‘What happened?’” –Casey Stengel
Link to comment
Share on other sites

  • 2 months later...

Sorry Guys. I was busy with other things and has no time to get on this one. Let me explain my question in more details.

I want to change the default locations of "My Documents". I know we can change some registry to map the "My Documents" to another location, for example D:\MyDocs. My problem is those registry are under HKEY_CURRENT_USER.

I have several accounts, for example, I have Administrator and User account. I log into Administrator account. I want to use a AU3 script to change the "My Documents" location for BOTH Administrator AND User. I think when I log on as Administrator, I can not access User's HKEY_CURRENT_USER registry, am I right? Or there are other solutions?

Many thanks.

Link to comment
Share on other sites

Sorry Guys. I was busy with other things and has no time to get on this one. Let me explain my question in more details.

I want to change the default locations of "My Documents". I know we can change some registry to map the "My Documents" to another location, for example D:\MyDocs. My problem is those registry are under HKEY_CURRENT_USER.

I have several accounts, for example, I have Administrator and User account. I log into Administrator account. I want to use a AU3 script to change the "My Documents" location for BOTH Administrator AND User. I think when I log on as Administrator, I can not access User's HKEY_CURRENT_USER registry, am I right? Or there are other solutions?

Many thanks.

The users HKEY_Current_User hive is in the ntuser.dat in his profile. U can load the users registry hive,e.g. with reg.exe, and change the registry hive as you want. Then unload the user registry, ready.

;-))

Stefan

Link to comment
Share on other sites

Sorry Guys. I was busy with other things and has no time to get on this one. Let me explain my question in more details.

I want to change the default locations of "My Documents". I know we can change some registry to map the "My Documents" to another location, for example D:\MyDocs. My problem is those registry are under HKEY_CURRENT_USER.

I have several accounts, for example, I have Administrator and User account. I log into Administrator account. I want to use a AU3 script to change the "My Documents" location for BOTH Administrator AND User. I think when I log on as Administrator, I can not access User's HKEY_CURRENT_USER registry, am I right? Or there are other solutions?

Many thanks.

Along with what 99ojo just posted,

this by seanhart: http://www.autoitscript.com/forum/index.ph...mp;#entry382209

and/or engine's Registry UDF: http://www.autoitscript.com/forum/index.ph...mp;#entry545798

should get you going

Link to comment
Share on other sites

I try the engine's Registry UDF, and it works. Thanks.

However, I still have problem with other part of my code.

In my code, I need to do two things.

One is to change the computer name. I used the following code.

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$Name);

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$Name);

But when I go to System properties, I found the computer name is not changed. Did I miss something?

The second thing I want to do is to redirect My Document to another directory, say "D:\MyDocs". I used the following code.

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","My Music", "REG_EXPAND_SZ", $path & "\My Music")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","My Pictures", "REG_EXPAND_SZ", $path & "\My Pictures")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Personal", "REG_EXPAND_SZ", $path)

It does not work.

Would you help me with this.

Thank you.

Link to comment
Share on other sites

You would be better off using the MMC. Just do start>run>mmc, and make your change there. No matter who logs in, it will do what you need. No script needed.

edit:you will need to add the correct snap-in.

Thanks for the suggestion. I need to write a script to automate these jobs. I am creating a XP image which will be deployed to quite a lot machines. So I wrote this code and let it run automatically through GUI_run_once. If I only have a few computers, I can do as you suggested.

In fact I have figured out how to change computer name, as below.

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ",$Name);

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ",$Name);

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$Name);

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$Name);

But I still have problem to redirect My Documents to another folder with AU3.

Edited by jackrabbit
Link to comment
Share on other sites

Unless somebody comes up with something else. Renaming the computer is more complicated then changing a reg val.

Download the support tools here:

http://www.microsoft.com/downloads/details...;displaylang=en

You only need one file "NETDOM.EXE"

Unless your joined to a domain this should be enough:

netdom renamecomputer <CurrentName> /newname:<NewName>

The syntax is:

netdom renamecomputer <CurrentName> /newname:<NewName> /userD:<Domain Admin User> Passwordd:domainpass /usero:<localAdmin> /passwordo:localpass /reboot

There is probably a dll you can call to do this but I don't know what it is sorry :)

___________________

For changing the docs you might want to try compiling an exe and using it as a logon script to write the reg settings as the user logs in.

You could use Shutdown(4) to force them to log off and log in again to make it take effect.

The idea of mounting ntuser.dat with Reg.exe is fine but I've had problems with windows keeping these files locked even when the user is not logged in.

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I found this script to rename the pc in the registry and take care of the system properties issue.

I think I have it converted properly. I've never used that objcreate before.

Give it a try :)

Kenny

sNewName = "put new name here" 

Set oShell = CreateObject ("WSCript.shell") 

sCCS = "HKLM\SYSTEM\CurrentControlSet\" 
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\" 
sCompNameRegPath = sCCS & "Control\ComputerName\" 

With oShell 
.RegDelete sTcpipParamsRegPath & "Hostname" 
.RegDelete sTcpipParamsRegPath & "NV Hostname" 

.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName 
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName 
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName 
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName 
End With ' oShell 

MsgBox "Computer name changed, please reboot your computer"

Converted:

$sNewName = "put new name here" 

$oShell = ObjCreate("WSCript.shell")

$sCCS = "HKLM\SYSTEM\CurrentControlSet\" 
$sTcpipParamsRegPath = $sCCS & "Services\Tcpip\Parameters\" 
$sCompNameRegPath = $sCCS & "Control\ComputerName\" 

With $oShell 
    RegDelete($sTcpipParamsRegPath, "Hostname")
    RegDelete($sTcpipParamsRegPath, "NV Hostname") 

    RegWrite($sCompNameRegPath & "ComputerName", "ComputerName", $sNewName)
    RegWrite($sCompNameRegPath & "ActiveComputerName", "ComputerName", $sNewName)
    RegWrite($sTcpipParamsRegPath, "Hostname", $sNewName)
    RegWrite($sTcpipParamsRegPath, "NV Hostname", $sNewName)
End With ' $oShell 

MsgBox(0,"","Computer name changed, please reboot your computer")
Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Thanks Kenny. In fact I have figured this out. I posted in the previous post.

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "Hostname", "REG_SZ",$Name);

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters", "NV Hostname", "REG_SZ",$Name);

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName","ComputerName","REG_SZ",$Name);

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName","ComputerName","REG_SZ",$Name);

My solution is very similar to your.

My Current problem is how to redirect the My Documents to another location, say D:\MyDocs.

Here is part of my code, but it doe NOT work.

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","My Music", "REG_EXPAND_SZ", $path & "\My Music")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","My Pictures", "REG_EXPAND_SZ", $path & "\My Pictures")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Personal", "REG_EXPAND_SZ", $path)

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths", "Administrator", "Reg_SZ", $path)

I found this script to rename the pc in the registry and take care of the system properties issue.

I think I have it converted properly. I've never used that objcreate before.

Give it a try :)

Kenny

sNewName = "put new name here" 

Set oShell = CreateObject ("WSCript.shell") 

sCCS = "HKLM\SYSTEM\CurrentControlSet\" 
sTcpipParamsRegPath = sCCS & "Services\Tcpip\Parameters\" 
sCompNameRegPath = sCCS & "Control\ComputerName\" 

With oShell 
.RegDelete sTcpipParamsRegPath & "Hostname" 
.RegDelete sTcpipParamsRegPath & "NV Hostname" 

.RegWrite sCompNameRegPath & "ComputerName\ComputerName", sNewName 
.RegWrite sCompNameRegPath & "ActiveComputerName\ComputerName", sNewName 
.RegWrite sTcpipParamsRegPath & "Hostname", sNewName 
.RegWrite sTcpipParamsRegPath & "NV Hostname", sNewName 
End With ' oShell 

MsgBox "Computer name changed, please reboot your computer"

Converted:

$sNewName = "put new name here" 

$oShell = ObjCreate("WSCript.shell")

$sCCS = "HKLM\SYSTEM\CurrentControlSet\" 
$sTcpipParamsRegPath = $sCCS & "Services\Tcpip\Parameters\" 
$sCompNameRegPath = $sCCS & "Control\ComputerName\" 

With $oShell 
    RegDelete($sTcpipParamsRegPath, "Hostname")
    RegDelete($sTcpipParamsRegPath, "NV Hostname") 

    RegWrite($sCompNameRegPath & "ComputerName", "ComputerName", $sNewName)
    RegWrite($sCompNameRegPath & "ActiveComputerName", "ComputerName", $sNewName)
    RegWrite($sTcpipParamsRegPath, "Hostname", $sNewName)
    RegWrite($sTcpipParamsRegPath, "NV Hostname", $sNewName)
End With ' $oShell 

MsgBox(0,"","Computer name changed, please reboot your computer")
Link to comment
Share on other sites

Have you tried changing the values manually with regedit just to see if you can?

Meaning test security and so forth.

I also found this but I believe it only locks down the UI for redirecting my documents.

Check: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

See if you have a value named DisablePersonalDirChange

If you do backup the key and delete that value

Click Start>Run type in gpupdate and hit ok

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

There's actually two locations in the registry for setting the "My Documents" location:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\

So, you may want to chage your code to this:

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Music", "REG_EXPAND_SZ", $path & "\My Music")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","My Pictures", "REG_EXPAND_SZ", $path & "\My Pictures")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders","Personal", "REG_EXPAND_SZ", $path)

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","My Music", "REG_EXPAND_SZ", $path & "\My Music")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","My Pictures", "REG_EXPAND_SZ", $path & "\My Pictures")

RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders","Personal", "REG_EXPAND_SZ", $path)

Also, you shouldn't have to reboot to make the new settings work. If you open Windows Explorer and select the My Documents folder, when you press F5 to refresh the view, then you should see the new location. I'm sure there's probably a more elegant way of automating this "refresh" process, but you could easily do it with automated mouse clicks or ControlClicks. For that matter, you could automate the manual process of right-clicking My Documents, selecting Properties, entering in a new target location, clicking OK, and then answering Yes or No to the "Move Documents" dialog that pops up. That would handle all of the registry changes, any file moves, and refresh the view to the new location for you. With no need for a reboot.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...