一个关于c的函数的问题

chchzh1978 2003-03-01 09:41:07
在c语言中,如何获得的系统说在路径,如在windows2000中是c:\winnt; 在windowsxp中是c:\windows
...全文
50 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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







1. C 语言中的指针和内存泄漏 5 2. C语言难点分析整理 10 3. C语言难点 18 4. C/C++实现冒泡排序算法 32 5. C++中指针和引用的区别 35 6. const char*, char const*, char*const的区别 36 7. C中可变参数函数实现 38 8. C程序内存中组成部分 41 9. C编程拾粹 42 10. C语言中实现数组的动态增长 44 11. C语言中的位运算 46 12. 浮点数的存储格式: 50 13. 位域 58 14. C语言函数二维数组传递方法 64 15. C语言复杂表达式的执行步骤 66 16. C语言字符串函数大全 68 17. C语言宏定义技巧 89 18. C语言实现动态数组 100 19. C语言笔试-运算符和表达式 104 20. C语言编程准则之稳定篇 107 21. C语言编程常见问题分析 108 22. C语言编程易犯毛病集合 112 23. C语言缺陷与陷阱(笔记) 119 24. C语言防止缓冲区溢出方法 126 25. C语言高效编程秘籍 128 26. C运算符优先级口诀 133 27. do/while(0)的妙用 134 28. exit()和return()的区别 140 29. exit子程序终止函数与return的差别 141 30. extern与static存储空间矛盾 145 31. PC-Lint与C\C++代码质量 147 32. spirntf函数使用大全 158 33. 二叉树的数据结构 167 34. 位运算应用口诀和实例 170 35. 内存对齐与ANSI C中struct内存布局 173 36. 冒泡和选择排序实现 180 37. 函数指针数组与返回数组指针的函数 186 38. 右左法则- 复杂指针解析 189 39. 回车和换行的区别 192 40. 堆和堆栈的区别 194 41. 堆和堆栈的区别 198 42. 如何写出专业的C头文件 202 43. 打造最快的Hash表 207 44. 指针与数组学习笔记 222 45. 数组不是指针 224 46. 标准C中字符串分割的方法 228 47. 汉诺塔源码 231 48. 洗牌算法 234 49. 深入理解C语言指针的奥秘 236 50. 游戏外挂的编写原理 254 51. 程序实例分析-为什么会陷入死循环 258 52. 空指针究竟指向了内存的哪个地方 260 53. 算术表达式的计算 265 54. 结构体对齐的具体含义 269 55. 连连看AI算法 274 56. 连连看寻路算法的思路 283 57. 重新认识:指向函数的指针 288 58. 链表的源码 291 59. 高质量的子程序 295 60. 高级C语言程序员测试必过的十六道最佳题目+答案详解 297 61. C语言常见错误 320 62. 超强的指针学习笔记 325 63. 程序员之路──关于代码风格 343 64. 指针、结构体、联合体的安全规范 346 65. C指针讲解 352 66. 关于指向指针的指针 368 67. C/C++ 误区一:void main() 373 68. C/C++ 误区二:fflush(stdin) 376 69. C/C++ 误区三:强制转换 malloc() 的返回值 380 70. C/C++ 误区四:char c = getchar(); 381 71. C/C++ 误区五:检查 new 的返回值 383 72. C 是 C++ 的子集吗? 384 73. C和C++的区别是什么? 387 74. 无条件循环 388 75. 产生随机数的方法 389 76. 顺序表及其操作 390 77. 单链表的实现及其操作 391 78. 双向链表 395 79. 程序员数据结构笔记 399 80. Hashtable和HashMap的区别 408 81. hash 表学习笔记 410 82. C程序设计常用算法源代码 412 83. C语言有头结点链表的经典实现 419 84. C语言惠通面试题 428 85. C语言常用宏定义 450

70,020

社区成员

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

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