1,183
社区成员
发帖
与我相关
我的任务
分享
var
Reg:TRegistry;
begin
try
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
If Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',false) then
begin
Reg.OpenKey('路径..',true);
Reg.WriteString('程序名..');
end;
finally
Reg.Free;
end;
end;
If not Reg.KeyExists('\Software\MyApp\SysSet') then //首次运行
begin
Reg.OpenKey('\Software\MyApp\SysSet',true);
Reg.WriteBool('FisrtRun',true);
end
else
procedure TForm1.FormCreate(Sender: TObject);
var
Reg:TRegistry;
begin
if Not FileExists(ChangeFileExt(Application.ExeName,'.ran')) then
begin
CloseHandle(CreateFile(PAnsiChar(ChangeFileExt(Application.ExeName,'.ran')),GENERIC_WRITE,FILE_SHARE_READ,Nil,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0));
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('路径',true);
Reg.WriteString('程序名');
end
end;
uses
shlobj;
function SHGetFolderPath( hwndOwner: HWND;
nFolder: Integer;
hToken: THandle;
dwFlags: DWORD;
pszPath: PAnsiChar
): HRESULT; stdcall; external 'shell32.dll' name 'SHGetFolderPathA';
var
Path: AnsiString;
begin
SetLength(Path, MAX_PATH);
if Failed(SHGetFolderPath(Handle,CSIDL_COMMON_STARTUP (*所有用户,如果是当前用户,则换成CSIDL_STARTUP*),0,0,PAnsiChar(Path))) then
SetLength(Path,StrLen(PAnsiChar(Path)));
ShowMessage(Path);
end;