C# 윈도우 인식된 환경변수 정리

윈도우 프로그램을 사용하다보면 고정된 환경변수가 필요합니다. 내피씨의 내문서 파일과 저멀리 부산에 있는 친구의 내친구 피씨의 내문서 폴더의 절대 경로는 다를 수 있기 때문에 프로그램 설계시 머리가 아파지는 일을 겪을 수 있습니다.

 

이러한 문제점을 해결 하기 위해서 윈도우에서는 환경변수를 제공하고 있습니다.

예를 들어 내문서의 환경 변수는 %CSIDL_DEFAULT_MYDOCUMENTS 로 각기다른 피씨의 내문서 경로를 동일하게 로드를 할 수 있게 됩니다.

 

MSDN에서는 해당 내용 전부를 확인할 수 있으며, 자주 사용하는 것만 정리해 보도록 하겠습니다.

 

C#에서의 인식된 환경변수 사용법

제가 잘몰라서 처음에 무척 헤매였었는데, 이걸 그대로 사용을 할수가 없었습니다.

Enviroment.SpecialFolder 의 호출값을 통해서 시스템 경로를 파악할 수가 있어서 아래에 있는 내용은 윈도우 환경에서 참고만 해 주시기 바라며, 직접 사용이 안되더군요.

 

이것도 MSDN을 참고해 주시면 감사하겠습니다.

 

주로 사용하는게 문서폴더나 바탕화면/ 프로그램 경로 등인데, 잘 찾아서 즐코딩 하시기 바랄께요.

 

예) Environment.SpecialFolder.LocalApplicationData > C:\Users\피씨이름\AppData\Local

 

 

 

 

 

 

AdminTools 48 The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user.
ApplicationData 26 The directory that serves as a common repository for application-specific data for the current roaming user. A roaming user works on more than one computer on a network. A roaming user's profile is kept on a server on the network and is loaded onto a system when the user logs on.
CDBurning 59 The file system directory that acts as a staging area for files waiting to be written to a CD.
CommonAdminTools 47 The file system directory that contains administrative tools for all users of the computer.
CommonApplicationData 35 The directory that serves as a common repository for application-specific data that is used by all users.
CommonDesktopDirectory 25 The file system directory that contains files and folders that appear on the desktop for all users.
CommonDocuments 46 The file system directory that contains documents that are common to all users.
CommonMusic 53 The file system directory that serves as a repository for music files common to all users.
58 This value is recognized in Windows Vista for backward compatibility, but the special folder itself is no longer used.
CommonPictures 54 The file system directory that serves as a repository for image files common to all users.
CommonProgramFiles 43 The directory for components that are shared across applications.
To get the x86 common program files directory in a non-x86 process, use the ProgramFilesX86 member.
CommonProgramFilesX86 44 The Program Files folder.
CommonPrograms 23 A folder for components that are shared across applications.
CommonStartMenu 22 The file system directory that contains the programs and folders that appear on the Start menu for all users.
CommonStartup 24 The file system directory that contains the programs that appear in the Startup folder for all users.
CommonTemplates 45 The file system directory that contains the templates that are available to all users.
CommonVideos 55 The file system directory that serves as a repository for video files common to all users.
Cookies 33 The directory that serves as a common repository for Internet cookies.
Desktop 0 The logical Desktop rather than the physical file system location.
DesktopDirectory 16 The directory used to physically store file objects on the desktop. Do not confuse this directory with the desktop folder itself, which is a virtual folder.
Favorites 6 The directory that serves as a common repository for the user's favorite items.
Fonts 20 A virtual folder that contains fonts.
History 34 The directory that serves as a common repository for Internet history items.
InternetCache 32 The directory that serves as a common repository for temporary Internet files.
LocalApplicationData 28 The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user.
LocalizedResources 57 The file system directory that contains localized resource data.
MyComputer 17 The My Computer folder. When passed to the Environment.GetFolderPath method, the MyComputer enumeration member always yields the empty string ("") because no path is defined for the My Computer folder.
MyDocuments 5 The My Documents folder. This member is equivalent to Personal.
MyMusic 13 The My Music folder.
MyPictures 39 The My Pictures folder.
MyVideos 14 The file system directory that serves as a repository for videos that belong to a user.
NetworkShortcuts 19 A file system directory that contains the link objects that may exist in the My Network Places virtual folder.
Personal 5 The directory that serves as a common repository for documents. This member is equivalent to MyDocuments.
PrinterShortcuts 27 The file system directory that contains the link objects that can exist in the Printers virtual folder.
ProgramFiles 38 The program files directory.
In a non-x86 process, passing ProgramFiles to the GetFolderPath(Environment+SpecialFolder) method returns the path for non-x86 programs. To get the x86 program files directory in a non-x86 process, use the ProgramFilesX86 member.
ProgramFilesX86 42 The x86 Program Files folder.
Programs 2 The directory that contains the user's program groups.
Recent 8 The directory that contains the user's most recently used documents.
Resources 56 The file system directory that contains resource data.
SendTo 9 The directory that contains the Send To menu items.
StartMenu 11 The directory that contains the Start menu items.
Startup 7 The directory that corresponds to the user's Startup program group. The system starts these programs whenever a user logs on or starts Windows.
System 37 The System directory.
SystemX86 41 The Windows System folder.
Templates 21 The directory that serves as a common repository for document templates.
UserProfile 40 The user's profile folder. Applications should not create files or folders at this level; they should put their data under the locations referred to by ApplicationData.
Windows 36 The Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables.

 

 

자주 사용하는 인식된 환경변수 안내

CSIDL_DEFAULT_APPDATA %DEFAULTUSERPROFILE%의 Appdata 폴더를 참조합니다.
C SIDL_DEFAULT_LOCAL_APPDATA %DEFAULTUSERPROFILE%의 로컬 Appdata 폴더를 참조합니다.
CSIDL_DEFAULT_COOKIES %DEFAULTUSERPROFILE%의 Cookies 폴더를 참조합니다.
CSIDL_DEFAULT_CONTACTS %DEFAULTUSERPROFILE%의 연락처 폴더를 참조합니다.
CSIDL_DEFAULT_DESKTOP %DEFAULTUSERPROFILE%의 Desktop 폴더를 참조합니다.
CSIDL_DEFAULT_DOWNLOADS %DEFAULTUSERPROFILE%의 다운로드 폴더를 참조합니다.
CSIDL_DEFAULT_FAVORITES %DEFAULTUSERPROFILE%의 즐겨찾기 폴더를 참조합니다.
CSIDL_DEFAULT_HISTORY %DEFAULTUSERPROFILE%의 사용 기록 폴더를 참조합니다.
CSIDL_DEFAULT_INTERNET_CACHE %DEFAULTUSERPROFILE%의 인터넷 캐시 폴더를 참조합니다.
CSIDL_DEFAULT_PERSONAL %DEFAULTUSERPROFILE%의 개인 폴더를 참조합니다.
CSIDL_DEFAULT_MYDOCUMENTS %DEFAULTUSERPROFILE%의 내 문서 폴더를 참조합니다.
CSIDL_DEFAULT_MYPICTURES %DEFAULTUSERPROFILE%의 내 사진 폴더를 참조합니다.
CSIDL_DEFAULT_MYMUSIC %DEFAULTUSERPROFILE%음악 My 음악 참조합니다.
CSIDL_DEFAULT_MYVIDEO %DEFAULTUSERPROFILE%의 내 비디오 폴더를 참조합니다.
CSIDL_DEFAULT_RECENT %DEFAULTUSERPROFILE%의 Recent 폴더를 참조합니다.
CSIDL_DEFAULT_SENDTO %DEFAULTUSERPROFILE%의 보내기 폴더를 참조합니다.
CSIDL_DEFAULT_STARTMENU %DEFAULTUSERPROFILE%의 시작 메뉴 폴더를 참조합니다.
CSIDL_DEFAULT_PROGRAMS %DEFAULTUSERPROFILE%의 Programs 폴더를 참조합니다.
CSIDL_DEFAULT_STARTUP %DEFAULTUSERPROFILE%의 시작 폴더를 참조합니다.

 

이러한 변수값의 경우