Notifications
Clear all

[Closed] Access registry values

I’m trying to get the stored Windows Documents path, which seems to be stored in the registry at:

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

However, even after looking at the maxscript documentation, I don’t really understand how to get the value. Using dotnet I tried this, but not sure if I’m on the right track or not…

reg = dotNetClass “Microsoft.Win32.Registry”
regKeyDir = reg.CurrentUser.OpenSubKey(@“Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders”)

2 Replies

Hi Greg,

Yes, on the right track! Are you looking for the documents folder of the current user? To use the dotnet registry class you can use the following method…

regPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
evalKey = ((dotnetclass "Microsoft.Win32.Registry").CurrentUser).OpenSubKey regPath	
docFolder = evalKey.GetValue "Personal"
evalKey.Close()	


However a simpler way would be to use this

((dotnetclass "system.environment").GetFolderPath \
	(dotnetclass "system.environment+SpecialFolder").MyDocuments) 
 

Hope this helps.

Seems if the user has their Documents directory on a separate drive it returns just the drive letter for both methods, but that’s better then nothing. For now I’m just having it try to find a viable folder in the root when that happens, or have a popup asking user to choose the documents manually if nothing is found.

Anyhow, thanks for the help!