Launching wordpad

How can I launch wordpad from my application?
winexec('Wordpad.exe myfile.txt')shownormal does not do the trick...
srbenavrbeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

m_adilCommented:
hi,
use following path. Wordpad.exe is not in path so you have to give complete path.

winexec('c:\program files\accessories\Wordpad.exe myfile.txt', 1);
0
srbenavrbeAuthor Commented:
It does not work.
winexec('c:\program files\WindowsNT\accessories\Wordpad.exe myfile.txt', 1);
fails to launch Wordpad...
0
guntherdsCommented:
when you execute the code of m_adil, what kind of error do you get, or don't you get any message?
Have you ever trie CreateProcess???
It's a lot more difficult than WinExec but you can also do a lot more!
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

philipleighsCommented:
Probably because you need some ".

winexec('"c:\program files\accessories\Wordpad.exe" myfile.txt', 1);

A better approach would be to get the path to wordpad from the registry. On my WinNT machine, the path to Wordpad is:
C:\Program Files\Windows NT\Accessories\WORDPAD.EXE

So the original call would fail.

Your program should look in this registry key:
HKEY_LOCAL_MACHINE
  Software
    Microsoft
      Windows
        CurrentVersion
          App Paths
            Wordpad.exe
and read the default value.

Then call WinExec.

Let me know if you need code.

Cheers,
Phil.
0
m_adilCommented:
>> winexec('c:\program files\WindowsNT\accessories\Wordpad.exe
I think there is a space in *WindowsNT* i.e. *Windows Nt*

but no doubt the best way is to get the path from registry
0
srbenavrbeAuthor Commented:
No,winexec does not do the trick...
I think the Reg is the only way.
Phil,can I see the code for launching
Wordpad by means of registry?
0
CalvinDayCommented:
uses
  ShellApi;
 
ShellExecute(Handle, 'open', 'wordpad.exe', 'c:\myfile.txt', nil, SW_SHOW);
0
srbenavrbeAuthor Commented:
ShellApi does not work either!
0
srbenavrbeAuthor Commented:
Adjusted points to 30
0
Fatman121898Commented:
Try this function. Using it, you can execute WIN and DOS application as well.

function ExecApplication(CmdLine: String; ShowMode: Dword): Dword;
  var StartInfo: TStartupInfo;
      ProcInfo: TProcessInformation;
      ErrCode: Integer;
  begin
    StartInfo.cb:=SizeOf(StartInfo);
    FillChar(StartInfo, SizeOf(StartInfo), 0);
    StartInfo.dwFlags:=STARTF_USESHOWWINDOW;
    StartInfo.wShowWindow:=ShowMode;
    CreateProcess(nil, PChar(CmdLine), nil, nil, False, 0, nil, nil, StartInfo, ProcInfo);
    //next call is optional :
    //when running DOS apps - to prevent multiple instances;
    //when runnind WIN apps - to wait until started app has been closed  
    WaitForSingleObject(ProcInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcInfo.hProcess, ErrCode);
    Result:=ErrCode;
  end;

As you can see, the core is CreateProcess().
In your case the command statement will look as follows:

ExecApplication('C:\Program Files\Accessories\Wordpad.exe C:\Temp\Mydoc.doc',SW_MAXIMIZE {SW_HIDE, SW_MINIMIZE} );
         
Enjoy!

Jo.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srbenavrbeAuthor Commented:
Havent tested jet,but hmmm...
I get the idea
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.