"c:/Program Files/...."的目录在Delphi中可不可以用其他方式写码?(300分)

  • 主题发起人 主题发起人 田伯光
  • 开始时间 开始时间

田伯光

Unregistered / Unconfirmed
GUEST, unregistred user!
我想在写程序的时候外挂程序读"c:/Program Files/...."下的文件,<br>但是发布的时候又不能保证其他机器的操作系统一定是装在C盘所以就带来可能会出错,<br>所以想用另一种的方式写,只要能找到和Windows在同一分区上的'Program Files/...."<br>路经就可以<br>
 
学习一下
 
我想应该是读取注册表中windows的安装位置,然后确定应该是哪一个分区吧。
 
简单问题,不用300分吧?<br>var<br>&nbsp; S: string;<br>begin<br>&nbsp; SetLength(S, 250);<br>&nbsp; SetLength(S, GetWindowsDirectory(PChar(S), 250)); //用API取得Windows目录<br>&nbsp; ShowMessage(ExtractFileDrive(S) + '/Program Files/....');<br><br>
 
干脆再给你一贴:<br>获得系统缺省目录.<br>uses Registry;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; reg : TRegistry;<br>&nbsp; ts : TStrings;<br>&nbsp; i : integer;<br>begin<br>&nbsp; reg := TRegistry.Create;<br>&nbsp; reg.RootKey := HKEY_CURRENT_USER;<br>&nbsp; reg.LazyWrite := false;<br>&nbsp; reg.OpenKey(<br>&nbsp; &nbsp;'Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; false);<br>&nbsp; &nbsp; ts := TStringList.Create;<br>&nbsp; &nbsp; reg.GetValueNames(ts);<br>&nbsp; &nbsp; for i := 0 to ts.Count -1 do begin<br>&nbsp; &nbsp; &nbsp; Memo1.Lines.Add(ts.Strings +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' = ' +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reg.ReadString(ts.Strings));<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; ts.Free;<br>&nbsp; reg.CloseKey;<br>&nbsp; reg.free;<br>end;<br><br>
 
在程序启动时写点代码, 将当前程序所在目录写入到注册表保存就行了
 
uses ShlObj, ActiveX;<br><br>function GetSystemPath(Folder: Integer): string;<br>var<br>&nbsp; PIDL: PItemIDList;<br>&nbsp; Path: LPSTR;<br>&nbsp; AMalloc: IMalloc;<br>begin<br>&nbsp; Path := StrAlloc(MAX_PATH);<br>&nbsp; SHGetSpecialFolderLocation(Application.Handle, Folder, PIDL);<br>&nbsp; if SHGetPathFromIDList(PIDL, Path) then<br>&nbsp; &nbsp; Result := Path;<br>&nbsp; SHGetMalloc(AMalloc);<br>&nbsp; AMalloc.Free(PIDL);<br>&nbsp; StrDispose(Path);<br>end;<br>&nbsp; &nbsp; <br>你可以使用不同的参数调用这个函数,例如:<br><br>CSIDL_DESKTOP --- WINDOWS/Desktop<br>CSIDL_DESKTOPDIRECTORY --- WINDOWS/Desktop<br>CSIDL_FONTS --- WINDOWS/FONTS<br>CSIDL_NETHOOD --- WINDOWS/NetHood<br>CSIDL_PERSONAL --- X:/My Documents<br>CSIDL_PROGRAMS --- WINDOWS/StartMenu/Programs<br>CSIDL_RECENT --- WINDOWS/Recent<br>CSIDL_SENDTO --- WINDOWS/SendTo<br>CSIDL_STARTMENU --- WINDOWS/Start Menu<br>CSIDL_STARTUP --- WINDOWS/Start Menu/Programs/StartUp<br>CSIDL_TEMPLATES --- WINDOWS/ShellNew<br>
 
xianjun, 很想你交个朋友,我的QQ是14375503有空和我联系
 
后退
顶部