如何获取当前windows系统目录?急?!!(50分)

  • 主题发起人 主题发起人 zhongjiancai
  • 开始时间 开始时间
Z

zhongjiancai

Unregistered / Unconfirmed
GUEST, unregistred user!
如何获取当前windows系统目录?急?!!
 
The GetSystemDirectory function retrieves the path of the Windows system directory. The system directory contains such files as Windows libraries, drivers, and font files. <br><br>UINT GetSystemDirectory(<br><br>&nbsp; &nbsp; LPTSTR lpBuffer, // address of buffer for system directory <br>&nbsp; &nbsp; UINT uSize // size of directory buffer <br>&nbsp; &nbsp;);
 
三个API函数:<br><br>getsystemdirectory<br>gettemppath<br>extractfilepath
 
var Names: Pchar;<br>begin<br>GetMem( Names, MAX_PATH+1 );<br>GetSystemDirectory(Names, MAX_PATH+1);<br>end;
 
楼上的方法应该可以!
 
我用如下调用:<br>&nbsp; &nbsp; function GetLocalName : String;<br>&nbsp; &nbsp; &nbsp;var cName:Pchar;<br> Size:^DWord;<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp;GetMem(cName,255);<br>&nbsp; &nbsp; &nbsp;new(size);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; // GetcomputerName(cName,size^);<br>&nbsp; &nbsp; &nbsp;GetSystemDirectory(cname,size^);<br>&nbsp; &nbsp; &nbsp;Result := StrPas(cName);<br>&nbsp; &nbsp; &nbsp;finally<br>&nbsp; &nbsp; &nbsp; Dispose(cName);<br>&nbsp; &nbsp; &nbsp; dispose(size);<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;end;<br>为何要执行第3次才得出正确结果
 
多人接受答案了。
 
GetEnvironmentVariable('windir')<br>你在98下试吧,NT下好使
 
后退
顶部