[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

Launching wordpad

How can I launch wordpad from my application?
winexec('Wordpad.exe myfile.txt')shownormal does not do the trick...
0
srbenavrbe
Asked:
srbenavrbe
1 Solution
 
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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
 
srbenavrbeAuthor Commented:
Havent tested jet,but hmmm...
I get the idea
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now