Solved

Open My Computer

Posted on 2002-07-26
7
225 Views
Last Modified: 2010-04-04
How do i run My Computer?
0
Comment
Question by:easysoft_studios
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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