您现在的位置:学赛首页 > 计算机等级考试 > 复习资料 > 正文
计算机二级VB:获取系统和Windows目录
http://www.educity.cn 作者:不详 来源:考试大 2007年5月31日 发表评论 进入社区
    当我们需要让自己的程序判断系统目录和windows目录的名字。这时可以调用windowsapi函数getsystemdirectory和getwindowsdirectory。

  声明:

  ' 获取系统目录

以下是引用片段:
  public declare function getsystemdirectory lib 'kernel32' alias 'getsystemdirectorya' _
  (byval lpbuffer as string, byval nsize as long) as long

  ' 获取windows目录

以下是引用片段:
  declare function getwindowsdirectory lib 'kernel32' alias 'getwindowsdirectorya' _
  (byval lpbuffer as string, byval nsize as long) as long

  调用:

  ' 检查系统目录

以下是引用片段:
  public function getsystempath() as string
  dim p as string * 80
  dim length as long
  dim path as string
  length = getsystem directory(p, len(p))
  path = left(p, length)
  getsystempath = path
  end function

  ' 检查windows目录

以下是引用片段:
  public function getwindowspath() as string
  dim p as string * 80
  dim length as long
  dim path as string
  length = getwindows directory(p, len(p))
  path = left(p, length)
  getwindowspath = path
  end function