Solved

Open My Computer

Posted on 2002-07-26
7
224 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

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!

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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