一个关于c的函数的问题

chchzh1978 2003-03-01 09:41:07
在c语言中,如何获得的系统说在路径,如在windows2000中是c:\winnt; 在windowsxp中是c:\windows
...全文
37 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouzhaohan 2003-03-03
  • 打赏
  • 举报
回复
getenv()是标准的库函数。
同时再调用main的时候也可以把环境变量传进来,main( int argc, char *argv[ ], char *envp[ ] )
那个环境变量应该叫windir吧!
具体你可以查查手册。
xdspower 2003-03-03
  • 打赏
  • 举报
回复
注意如果你的当前驱动盘不是系统盘,则还要到系统盘上来
xdspower 2003-03-03
  • 打赏
  • 举报
回复
system("cd %windir%");
是十分可行得,可以考虑,这样来完成:
system("cd %windir%");
system("md a");
system("cd a");
...

fireseed 2003-03-02
  • 打赏
  • 举报
回复
回复人: chchzh1978(no) ( ) 信誉:100 2003-03-02 11:28:00 得分:0

我位,我说的是在纯C下面!!!!!!!!!!!!!!!!!

===========================================================================

那你的问题就是错误的,你想要获得windows的系统目录,一定是和windows相关的。而C的运行库和操作系统是无关的,只用纯C的话如何办到?真是笑话。
shine333 2003-03-02
  • 打赏
  • 举报
回复
%windir%
system("cd %windir%");
mikespook 2003-03-02
  • 打赏
  • 举报
回复
纯C?一点库都不用?
不可能吧?
Frank001 2003-03-02
  • 打赏
  • 举报
回复

要是在纯C希望获得windows的系统路径,你可以读系统盘根目录下的这两个文件:

msdos.sys(如存在的话,里面会有win9x的系统路径,不是win9x系统的,有可能也有这个文件,因为dos也有这个文件,注意区分,比较好识别的)

boot.ini(如存在的话,里面有win nt/2000/xp的系统路径)
chchzh1978 2003-03-02
  • 打赏
  • 举报
回复
上面那位大哥见笑了,你说得很有道理,不过我的问题就不知道解决了,一会给分!!!

那这样问吧:
在C下有没有这样一来一个函数,可以创建一个目录较深的结构,用来放密码文件。

或者,这样说吧,我想在一个系统上第一次运行某个应用程序 就创建密码文件,
以记录权限,然后每次在启动发应用程序,就只是从密码文件中读取内容,而不再
创建,我的目标是防止用户人为的删掉这个密码文件,从而是以前的加密设置不起
效果。
请高手指教!!!

我的想法,找一个较深的目录,是用户不易发现!!!所以才会提出刚才那个问题
chchzh1978 2003-03-02
  • 打赏
  • 举报
回复
我位,我说的是在纯C下面!!!!!!!!!!!!!!!!!
fireseed 2003-03-02
  • 打赏
  • 举报
回复
HRESULT SHGetFolderPath(
HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
LPTSTR pszPath
);

用这个函数可以获得各种系统指定的路径

第一个参数设NULL,
第二个参数下面再讲,
第三个参数设NULL,
第四个参数设SHGFP_TYPE_CURRENT,
第五个参数设为一个char型的MAX_PATH(常量)大小的字符串数组。

第二个参数指定不同的值时,LPTSTR pszPath中就会存储不同的目录字符串:

CSIDL_ADMINTOOLS
管理员工具目录。

CSIDL_ALTSTARTUP
启动程序组目录。

CSIDL_APPDATA
应用程序数据目录,一般位于C:\Documents and Settings\username\Application Data。

CSIDL_BITBUCKET
回收站目录。

CSIDL_COMMON_ADMINTOOLS
所有用户管理员工具目录。

CSIDL_COMMON_ALTSTARTUP
所有用户启动程序组目录。

CSIDL_COMMON_APPDATA
所有用户应用程序数据目录。

CSIDL_COMMON_DESKTOPDIRECTORY
所有用户桌面目录。

CSIDL_COMMON_DOCUMENTS
所有用户我的文档目录。

CSIDL_COMMON_FAVORITES
所有用户收藏夹目录。

CSIDL_COMMON_PROGRAMS
所有用户开始菜单目录。

(不想再翻译了,累死了,大家自己看吧)
CSIDL_COMMON_STARTMENU
File system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT® systems.
CSIDL_COMMON_STARTUP
File system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT® systems.
CSIDL_COMMON_TEMPLATES
File system directory that contains the templates that are available to all users. A typical path is C:\Documents and Settings\All Users\Templates. Valid only for Windows NT® systems.
CSIDL_CONTROLS
Virtual folder containing icons for the Control Panel applications.
CSIDL_COOKIES
File system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies.
CSIDL_DESKTOP
Windows Desktop—virtual folder that is the root of the namespace.
CSIDL_DESKTOPDIRECTORY
File system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). A typical path is C:\Documents and Settings\username\Desktop
CSIDL_DRIVES
My Computer—virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.
CSIDL_FAVORITES
File system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites.
CSIDL_FONTS
Virtual folder containing fonts. A typical path is C:\WINNT\Fonts.
CSIDL_HISTORY
File system directory that serves as a common repository for Internet history items.
CSIDL_INTERNET
Virtual folder representing the Internet.
CSIDL_INTERNET_CACHE
Version 4.72. File system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Temporary Internet Files.
CSIDL_LOCAL_APPDATA
Version 5.0. File system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data.
CSIDL_MYMUSIC
File system directory that serves as a common repository for music files. A typical path is C:\My Music.
CSIDL_MYPICTURES
Version 5.0. My Pictures folder. A typical path is C:\Documents and Settings\username\My Documents\My Pictures.
CSIDL_NETHOOD
A file system folder containing the link objects that may exist in the My Network Places virtual folder. It is not the same as CSIDL_NETWORK, which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood.
CSIDL_NETWORK
Network Neighborhood—virtual folder representing the root of the network namespace hierarchy.
CSIDL_PERSONAL
File system directory that serves as a common repository for documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace. To access that virtual folder, use the technique described in Managing the File System.
CSIDL_PRINTERS
Virtual folder containing installed printers.
CSIDL_PRINTHOOD
File system directory that contains the link objects that may exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood.
CSIDL_PROFILE
Version 5.0. User's profile folder.
CSIDL_PROGRAM_FILES
Version 5.0. Program Files folder. A typical path is C:\Program Files.
CSIDL_PROGRAM_FILES_COMMON
Version 5.0. A folder for components that are shared across applications. A typical path is C:\Program Files\Common. Valid only for Windows NT® and Windows® 2000 systems.
CSIDL_PROGRAMS
File system directory that contains the user's program groups (which are also file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs.
CSIDL_RECENT
File system directory that contains the user's most recently used documents. A typical path is C:\Documents and Settings\username\Recent. To create a shortcut in this folder, use SHAddToRecentDocs. In addition to creating the shortcut, this function updates the Shell's list of recent documents and adds the shortcut to the Documents submenu of the Start menu.
CSIDL_SENDTO
File system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo.
CSIDL_STARTMENU
File system directory containing Start menu items. A typical path is C:\Documents and Settings\username\Start Menu.
CSIDL_STARTUP
当前用户启动程序组目录。

CSIDL_SYSTEM
系统目录,一般为系统安装目录下的system32或system目录。

CSIDL_TEMPLATES
临时文件夹目录

CSIDL_WINDOWS
Windows安装目录
ckacka 2003-03-02
  • 打赏
  • 举报
回复
两个都可以
ckacka 2003-03-02
  • 打赏
  • 举报
回复
GetSystemDirectory
The GetSystemDirectory function retrieves the path of the system directory. The system directory contains such files as dynamic-link libraries, drivers, and font files.

UINT GetSystemDirectory(
LPTSTR lpBuffer, // buffer for system directory
UINT uSize // size of directory buffer
);
Parameters
lpBuffer
[out] Pointer to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named Windows\System on drive C, the path of the system directory retrieved by this function is C:\Windows\System.
uSize
[in] Specifies the maximum size of the buffer, in TCHARs. This value should be set to at least MAX_PATH+1 to allow sufficient space for the path and the null terminator.
Return Values
If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Applications should not create files in the system directory. If the user is running a shared version of the operating system, the application does not have write access to the system directory. Applications should create files only in the directory returned by the GetWindowsDirectory function.

Windows 95/98/Me: GetSystemDirectoryW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example Code
For an example, see Getting System Information.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode.
ckacka 2003-03-02
  • 打赏
  • 举报
回复
GetEnvironmentVariable
The GetEnvironmentVariable function retrieves the contents of the specified variable from the environment block of the calling process. The contents are in the form of a null-terminated string of characters.

DWORD GetEnvironmentVariable(
LPCTSTR lpName, // environment variable name
LPTSTR lpBuffer, // buffer for variable value
DWORD nSize // size of buffer
);
Parameters
lpName
[in] Pointer to a null-terminated string that specifies the name of the environment variable.
lpBuffer
[out] Pointer to a buffer that receives the contents of the specified environment variable. An environment variable has a maximum size limit of 32,767 bytes, including the trailing null terminator.
nSize
[in] Specifies the size, in TCHARs, of the buffer pointed to by the lpBuffer parameter.
Return Values
If the function succeeds, the return value is the number of TCHARs stored into the buffer pointed to by lpBuffer, not including the terminating null character.

If the specified environment variable name was not found in the environment block for the current process, the return value is zero.

If the buffer pointed to by lpBuffer is not large enough, the return value is the buffer size, in TCHARs, required to hold the value string and its terminating null character.

Windows 95/98/Me: GetEnvironmentVariableW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example Code
For an example, see Changing Environment Variables.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode.
brucegong 2003-03-02
  • 打赏
  • 举报
回复





windows的API好像叫做GetSystemDirectory







69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧