Sign in to follow this  
Followers 0
tarns

Change My Documents target directory

10 posts in this topic

Hi there,

I have mapped a network drive to "y:\Documents" using AutoIt. Now i wish to change the default My Documents directory working path (target location directory) from"C:\Documents and Settings\user\My Documents" to "y:\My Documents"

I can grab the users default my docs directory using @MyDocumentsDir but im stuck on the next line of code.I think changing the target directory on the desktop My documents link is different from creating a shortcut to it.

...

DriveMapAdd("Y:\", "\\blah\documents", 0, $User, $Pass)

....

FileCreateShortcut(@MyDocumentsDir,"My Documents.lnk")????

How can i do this with AutoIT v3?

cheers

Share this post


Link to post
Share on other sites



i think those are stored in the registry

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths

each use has its own subkey in that location


Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Share this post


Link to post
Share on other sites

.....
SplashImageOn("ECESplash", "c:\ECE.jpg", 450,100,(@DesktopWidth / 2) ,(@DesktopHeight / 2),1)
;Call function for mapping drive 
If $windowsuser="Tano" Then
    MapDrive ("Z:",$FILESERVER,"yyyW4H1S\gsiano","xxx")
    MapDrive ("Y:",$ECE3,        "xxx-KPW65TU02\Mario", "xxx")
    MapDrive ("S:",$DOCUMENTS,"yyyyW4H1S\gsiano","$xxx")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths", "Tano", "REG_SZ", "S:\")
EndIf
Sleep(3000)
SplashOff()
..........

I changed the Target folder in My Documents to see what gets written into the registry, When i do this it creates a new string key "tano" (my username) and places the drive letter next to it. So i created the reg write script to change that key automatically but it dosnt work.

Is there multiple places the doc path is stored? or another way around this?

Share this post


Link to post
Share on other sites

The weird thing is if u change the value of the target location in the registry it does not work and the target location remains unchanged. But if u change the key in the registry then the my document folder target location gets updated and i can see all the files, somehow its not a 1:1 association.

.....
SplashImageOn("ECESplash", "c:\ECE.jpg", 450,100,(@DesktopWidth / 2) ,(@DesktopHeight / 2),1)
;Call function for mapping drive 
If $windowsuser="Tano" Then
    MapDrive ("Z:",$FILESERVER,"yyyW4H1S\gsiano","xxx")
    MapDrive ("Y:",$ECE3,        "xxx-KPW65TU02\Mario", "xxx")
    MapDrive ("S:",$DOCUMENTS,"yyyyW4H1S\gsiano","$xxx")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths", "Tano", "REG_SZ", "S:\")
EndIf
Sleep(3000)
SplashOff()
..........

I changed the Target folder in My Documents to see what gets written into the registry, When i do this it creates a new string key "tano" (my username) and places the drive letter next to it. So i created the reg write script to change that key automatically but it dosnt work.

Is there multiple places the doc path is stored? or another way around this?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i found this....it look like that may be the wrong key

http://www.microsoft.com/windowsxp/using/n.../honeycutt.mspx

-edit-

i used active registry monitor...and it shows that the origional key i gave was correct...reboot may be neccessary like said above

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hey guys, still cant get it working, and i rebooted twice using both methods

Here is my code...

;Place script in startup folder
FileCreateShortcut(@ScriptDir & "\map.exe", @StartupDir & "\map.lnk")

;Define shares
$FILESERVER="\\xxxw4h1s\ACAD"
$DOCUMENTS="\\xxxw4h1s\ACAD\My Documents"
$ECE2="\\Tano-4msme0hiey\ece2"
$ECE3="\\Mario-kpw65tu02\ECE3"

DriveMapDel("Z:")
DriveMapDel("Y:")
DriveMapDel("X:")
DriveMapDel("S:")

$windowsuser = @UserName

Func _Middle($win, $txt)
    $size = WinGetClientSize($win, $txt)
    Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
    Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
    Return WinMove($win, $txt, $x, $y)
EndFunc

SplashImageOn("ECESplash", "c:\ECE.jpg", 450,100,(@DesktopWidth / 2) ,(@DesktopHeight / 2),1)

_Middle('ECESplash','')

;Call function for mapping drive 
If $windowsuser="Tano" Then
    MapDrive ("Z:",$FILESERVER,"xxxYW4H1S\gsiano","xxx")
    MapDrive ("Y:",$ECE3,        "MARIO-KPW65TU02\Mario", "xxx")
    MapDrive ("S:",$DOCUMENTS,"xxxYW4H1S\gsiano","xxx")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths", "Tano", "REG_SZ", "S:\")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Personal", "REG_SZ", "S:\")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Personal", "REG_EXPAND_SZ", "S:\")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "My Pictures", "REG_EXPAND_SZ", "S:\My Pictures")
EndIf

If $windowsuser="Mario" Then
    MapDrive ("Z:",$FILESERVER,"xxxYW4H1S\msiano","xxx")
EndIf

If $windowsuser="Dave" Then
    MapDrive ("Z:",$FILESERVER,"xxxW4H1S\dsiano","xxx")
    MapDrive ("X:",$ECE2,     "Tano-4msme0hiey\Tano",  "xxx")
    MapDrive ("S:",$DOCUMENTS,"xxxW4H1S\dsiano","xxx")
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths", "Dave", "REG_SZ", "S:\")
EndIf
Sleep(3000)
SplashOff()

Func MapDrive($Drive, $Share, $User, $Pass)
Local $retVal
$retVal = DriveMapAdd($Drive, $Share, 0, $User, $Pass)
If $retVal = 1 Then
    TrayTip("Mapping Drive: " & $Drive, "Currently mapping network share: " & $Share, 30, 1)
    Return 0
Else
    MsgBox(16 + 4096, "Mapping Failure", "An error has occurred mapping to a network share (" & $Share & ")     using username (" & $User & "), please contact the network administrator for more information.")
    Return -1
EndIf
EndFunc
Edited by tarns

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

And the script did successfully add these entries into the registry.. see below screenshot.

Explorer/UserShellFolders and Explorer/ShellFolders are the only 2 registry keys that changed when i set it manaully and my script creates the exact same entries but dosnt work.

Edited by tarns

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

there are also 2 user specific keys that get changed... i tried this and it seemed to work(after a reboot)...you may also want to change the my music and other folders other than my pictures

$basedir = "C:\temp"
If NOT FileExists($basedir) Then DirCreate($basedir)
If NOT FileExists($basedir & "\My Pictures") Then DirCreate($basedir & "\My Pictures")

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths", @UserName, "REG_SZ", $basedir)

$HKCUS1521 = "HKEY_USERS\" & _FindReg ("HKEY_USERS", "S-1-5-21")
RegWrite($HKCUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "My Pictures", "REG_SZ", $basedir & "\My Pictures")
RegWrite($HKCUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", "Personal", "REG_SZ", $basedir)

RegWrite($HKCUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "My Pictures", "REG_EXPAND_SZ", $basedir & "\My Pictures")
RegWrite($HKCUS1521 & "\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", "Personal", "REG_EXPAND_SZ", $basedir)


;this is a function from my prepsys program, i couldn't find a way to get this S-1-5-21 key (it changes depending on the user)
Func _FindReg($regsearchstart, $regsearch, $key = 1)
    While 1
        $result = RegEnumKey($regsearchstart, $key)
        If @error = -1 Then
            MsgBox(0, "Error", "Registry key Not Found")
            Exit
        EndIf
        If StringInStr($result, $regsearch) = 1 Then
            If StringInStr($result, "_Classes", 0) Then
                ExitLoop
            EndIf
        EndIf
        $key = $key + 1
    WEnd
    $result = StringTrimRight($result, 8)
    Return $result
EndFunc  ;==>_FindReg
Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Share this post


Link to post
Share on other sites

cheers ,thanks for the help.

All the folders are working properly except in explorer view. Eg Opening word or paint and clicking the My Documents folder shows all the files, but when u open the folder in explorer then the folder displays it empty.

*and yes i am opening the exact same folder in my programs.

Share this post


Link to post
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
Sign in to follow this  
Followers 0