How to get special folders paths?
AntidotE
Member Posts: 61
For example, I need to know, what is direct path to user's "My Documents" folder (i.e. in XP ENU, usually it's %HOMEDRIVE%%HOMEPATH%\<My Documents>, in XP RUS ...\<Рабочий Стол>, and, surely, user can change it to any another path, i.e. my is "E:\AllDocs\")
How to get this?
How to get this?
It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.
0
Answers
-
You can find it through registry...
see e.g. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders0 -
HomePath and HomeDrive is in the Key "HKEY_CURRENT_USER\Volatile Environment". The definition for, example, Start Menu is in the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders folder
If you need this also:
(in my meaning, "My Documents" is here)
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
(and 'Shared Docs')
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
To read the Registry you can use the "Windos Scripting Host" Automation (WSHShell). There exist a function like "RegRead"
RegardsDo you make it right, it works too!0 -
You don't need the registry, below is easier:
CREATE(LautWshShell); LvMyDocuments := 'MyDocuments'; LtPath := FORMAT(LautWshShell.SpecialFolders.Item(LvMyDocuments)); CLEAR(LautWshShell);
0 -
Thanks a lot, it works! =D>
and, some example to move this to Tips'n'Tricks:
FunctionGetFolderPath(Which : Text[20]) : Text[250] CREATE(WSHShell); EXIT(FORMAT(WSHShell.RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\'+Which))); CLEAR(WSHShell);
LocalsName DataType Subtype Length WSHShell Automation 'Windows Script Host Object Model'.WshShell
Examples/list of possible parameter strings:MESSAGE('User Application Data Path: %1',GetFolderPath('AppData')); MESSAGE('User Cache Path: %1',GetFolderPath('Cache')); MESSAGE('User CD Burning Path: %1',GetFolderPath('CD Burning')); MESSAGE('User Cookies Path: %1',GetFolderPath('Cookies')); MESSAGE('User Desktop Path: %1',GetFolderPath('Desktop')); MESSAGE('User Favorites Path: %1',GetFolderPath('Favorites')); MESSAGE('User Fonts Path: %1',GetFolderPath('Fonts')); MESSAGE('User History Path: %1',GetFolderPath('History')); MESSAGE('User Local Application Data Path: %1',GetFolderPath('Local AppData')); MESSAGE('User Local Settings Path: %1',GetFolderPath('Local Settings')); MESSAGE('User My Music Path: %1',GetFolderPath('My Music')); MESSAGE('User My Pictures Path: %1',GetFolderPath('My Pictures')); MESSAGE('User My Video Path: %1',GetFolderPath('My Video')); MESSAGE('User NetHood Path: %1',GetFolderPath('NetHood')); MESSAGE('User My Documents Path: %1',GetFolderPath('Personal')); MESSAGE('User PrintHood Path: %1',GetFolderPath('PrintHood')); MESSAGE('User Programs Path: %1',GetFolderPath('Programs')); MESSAGE('User Recent Path: %1',GetFolderPath('Recent')); MESSAGE('User SendTo Path: %1',GetFolderPath('SendTo')); MESSAGE('User Start Menu Path: %1',GetFolderPath('Start Menu')); MESSAGE('User Startup Path: %1',GetFolderPath('Startup')); MESSAGE('User Templates Path: %1',GetFolderPath('Templates'));
It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.0 -
I was in process of writing previous post, when your appeared...ajhvdb wrote:You don't need the registry, below is easier:
CREATE(LautWshShell); LvMyDocuments := 'MyDocuments'; LtPath := FORMAT(LautWshShell.SpecialFolders.Item(LvMyDocuments)); CLEAR(LautWshShell);
Can you show the list of all possible parameters?It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.0 -
Ah, btw, this all concerns XP, what about Vista? Is there the same regpath? I haven't vista here and can't look at...It is hard to swim against self bloodstream... (c) Old, experienced kamikadze.0
-
The path I wrote is from Vista, it means same path, but may be more keys... there is backward-compatibility...0
-
[Topic moved from 'NAV/Navision' forum to 'NAV Tips & Tricks' forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Just a quick update on this one after 11 years to make it work on RTC-based clients without Automation Security warning on RTC:
To do this, have a variable defined as DotNet variable and RunOnClient=true parameter setup:
Name DataType Subtype Length
Environment DotNet System.Environment.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
And if you would like to access i.e. Local AppData folder for any file saving operation, get the path string without "\" at the end:
Folder := Environment.GetEnvironmentVariable('localappdata') + '\';1 -
@gycsiak or using the same class:
Environment.GetFolderPath(Environment.SpecialFolder.System))
https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions