// WinExecAndWait is based on a similar routine by Brad Choate referenced in // old posts to comp.lang.pascal.delphi.misc and another by Oliver Townshend // in comp.lang.pascal.delphi.databases FUNCTION WinExecAndWait(CONST Path: pCHAR; CONST Visibility: WORD; CONST Wait: BOOLEAN): BOOLEAN; VAR ProcessInformation: TProcessInformation; StartupInfo : TStartupInfo; BEGIN FillChar(StartupInfo, SizeOf(TStartupInfo), 0); WITH StartupInfo DO BEGIN cb := SizeOf(TStartupInfo); lpReserved := NIL; lpDesktop := NIL; lpTitle := NIL; dwFlags := STARTF_USESHOWWINDOW; wShowWindow := Visibility; cbReserved2 := 0; lpReserved2 := NIL END; RESULT := CreateProcess(NIL, {address of module name} Path, {address of command line} NIL, {address of process security attributes} NIL, {address of thread security attributes} FALSE, {new process inherits handle} NORMAL_PRIORITY_CLASS, {creation flags} NIL, {address of new environment block} NIL, {address of current directory name} StartupInfo, ProcessInformation); IF RESULT THEN BEGIN WITH ProcessInformation DO BEGIN IF Wait THEN WaitForSingleObject(hProcess, INFINITE); CloseHandle(hThread); CloseHandle(hProcess) END END END {WinExecAndWait}; // See DejaNews, borland.public.delphi.winapi, "Re: Control Panel Applications," // Joe Miserendino, joe@been-there.com, Aug 20, 1997 PROCEDURE CallControlPanelApplet(CONST name: STRING; CONST option: STRING); VAR Applet : STRING; BEGIN Applet := 'CONTROL.EXE ' + name + '.CPL,' + option + ',ADD'; WinExecAndWait(pChar(Applet), SW_SHOWNORMAL, FALSE); END {CallControlPanelApplet}; procedure TForm1.ButtonShowDateTimeClick(Sender: TObject); begin CallControlPanelApplet('TIMEDATE','') end;