Welcome to zewaren.net. This site presents myself and mostly archives the solutions to some problems I once had.

Force ShellExecute to run and wait for completion with elevated privileges in Delphi

Not so frequently asked questions and stuff: 
function RunAsAdminAndWaitForCompletion(hWnd: HWND; filename: string; Parameters: string): Boolean;
{
    See Step 3: Redesign for UAC Compatibility (UAC)
    http://msdn.microsoft.com/en-us/library/bb756922.aspx
}
var
    sei: TShellExecuteInfo;
    ExitCode: DWORD;
begin
    ZeroMemory(@sei, SizeOf(sei));
    sei.cbSize := SizeOf(TShellExecuteInfo);
    sei.Wnd := hwnd;
    sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI or SEE_MASK_NOCLOSEPROCESS;
    sei.lpVerb := PChar('runas');
    sei.lpFile := PChar(Filename); // PAnsiChar;
    if parameters  '' then
        sei.lpParameters := PChar(parameters); // PAnsiChar;
    sei.nShow := SW_SHOWNORMAL; //Integer;

   if ShellExecuteEx(@sei) then begin
     repeat
       Application.ProcessMessages;
       GetExitCodeProcess(sei.hProcess, ExitCode) ;
     until (ExitCode  STILL_ACTIVE) or  Application.Terminated;
   end;
end;

Source:
* http://delphi.about.com/od/windowsshellapi/a/executeprogram.htm

How to send a file via HTTP specifying a custom filename, using PHP

Not so frequently asked questions and stuff: 
\n";
} else {
 srand((double)microtime()*1000000);
 $boundary = "---------------------".substr(md5(rand(0,32000)),0,10);
    
    $data = "";
 
    $header = "";
    $header .= "POST $service HTTP/1.1\r\n";
    $header .= "Host: $host\r\n";
    $header .= "Content-Type: multipart/form-data; boundary=$boundary\r\n"; 
    
    $APOST = array("a" => "b", "c" => "d");
    
        foreach($APOST AS $index => $value){
            $data .="--$boundary\r\n";
            $data .= "Content-Disposition: form-data; name=\"".$index."\"\r\n";
            $data .= "\r\n".$value."\r\n";
            $data .="--$boundary\r\n";
        } 
    
  $data .= "--$boundary\r\n";
   $content_file = join("", file($filetosend));
    $content_type = "";
 $file_name = $filenametosend;
   $data .="Content-Disposition: form-data; name=\"userfile\"; filename=\"$file_name\"\r\n";
 $data .= "Content-Type: $content_type\r\n\r\n";
 $data .= "".$content_file."\r\n";
 $data .="--$boundary--\r\n";
        
    $header .= "Content-length: " . strlen($data); 
    $header .= "\r\n\r\n";
    $out = $header.$data;
    
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 4096);
    }
    fclose($fp);
}
?>

Pages

Subscribe to Front page feed