Solved

Open My Computer

Posted on 2002-07-26
7
222 Views
Last Modified: 2010-04-04
How do i run My Computer?
0
Comment
Question by:easysoft_studios
7 Comments
 
LVL 1

Expert Comment

by:PeterZG
ID: 7181363
?
0
 

Author Comment

by:easysoft_studios
ID: 7181366
Like then you click at the My Computer icon on the desktop.
0
 
LVL 1

Expert Comment

by:PeterZG
ID: 7181395
do you want to simulate clicking the icon (shortcut) or open it within your own application?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:ginsonic
ID: 7181569
uses ShellApi,ShlObj;

procedure TForm1.Button1Click(Sender: TObject);
var
   PIDL:PItemIDList;
   Info:TShellExecuteInfo;
   pInfo:PShellExecuteInfo;
   WaitCode:DWord;
begin
   SHGetSpecialFolderLocation(Handle,CSIDL_DRIVES,PIDL);
   pInfo:=@Info;
   With Info do begin
    cbSize:=SizeOf(Info);
    fMask:=SEE_MASK_NOCLOSEPROCESS+SEE_MASK_IDLIST;
    wnd:=Handle;
    lpVerb:=nil;
    lpFile:=nil;
    lpParameters:=nil;
    lpDirectory:=nil;
    nShow:=SW_ShowNormal;
    hInstApp:=0;
    lpIDList:=PIDL;
   end;
   ShellExecuteEx(pInfo);
   repeat
    WaitCode := WaitForSingleObject(Info.hProcess,500);
    Application.ProcessMessages;
   until (WaitCode <> WAIT_TIMEOUT);
end;

 
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 7181653
uses ShellApi, ShlObj, ActiveX;

procedure TForm1.Button1Click(Sender: TObject);
var
  PIDL: PItemIDList;
  Info: TShellExecuteInfo;
  pInfo: PShellExecuteInfo;
  WaitCode: DWORD;
  Allocator: IMalloc;
begin
  if SHGetMalloc(Allocator) = NOERROR then
  begin
    SHGetSpecialFolderLocation(Handle, CSIDL_DRIVES, PIDL);
    Allocator.Free(PIDL);
    pInfo := @Info;
    ZeroMemory(@Info, SizeOf(Info));
    with Info do
    begin
      cbSize := SizeOf(Info);
      fMask := SEE_MASK_NOCLOSEPROCESS + SEE_MASK_IDLIST;
      wnd := Handle;
      lpVerb := nil;
      lpFile := nil;
      lpParameters := nil;
      lpDirectory := nil;
      nShow := SW_SHOWNORMAL;
      hInstApp := 0;
      lpIDList := PIDL;
    end;
    ShellExecuteEx(pInfo);
    repeat
      WaitCode := WaitForSingleObject(Info.hProcess, 500);
      Application.ProcessMessages;
    until (WaitCode <> WAIT_TIMEOUT);
  end;
end;
0
 
LVL 20

Accepted Solution

by:
Madshi earned 50 total points
ID: 7181674
ginsonic's code doesn't free the pidl -> memory leak!

Tasomia's code does free the pidl, but too early, you're freeing it before it is actually used.

This one works fine on my XP, didn't test it under other OSs, though:

  WinExec('explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}', SW_SHOWNORMAL);

Regards, Madshi.
0
 

Author Comment

by:easysoft_studios
ID: 7181913
I it supposed to work on XP, so Madshi's lookes fine. I'll return when i'm sitting with my IDE running :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question