5

I'm doing some build automation and would like to run the Delphi 7 IDE from an Application that I'm writing using Delphi XE.

My Delphi 7 IDE is at:

'C:\Program Files\Borland\Delphi7\Bin\delphi32.exe'

yet doing:

ShellExecute( Handle, 'Open', 'C:\Program Files\Borland\Delphi7\Bin\delphi32.exe', '', '', sw_ShowNormal );

eventually gets into the Delphi 7 IDE but only after lots of missing package errors.

Doing:

ShellExecute( Handle, 'Open', 'C:\windows\notepad.exe', '', '', sw_ShowNormal );

works file opening Notepad.

I also have a batch file called 'Delphi7IDE.bat' which opens Delphi 7 when I click the batch file, but doing:

ShellExecute( Handle, 'Open', 'C:\sys\batch\Delphi7IDE.bat', '', '', sw_ShowNormal );

produces the same errors as above.

I've tried using the directoy as specified in my Delphi 7 menu shortcut (i.e calling:

ShellExecute( Handle, 'Open', 'C:\Program Files\Borland\Delphi7\Bin\delphi32.exe', '', 'C:\Program Files\Borland\Delphi7\Projects\', sw_ShowNormal );"

but this gives the same error (and this is to be expected because the batch file example above has no fixed directory and runs fine when clicked).

There are multiple errors, but an exampler of one is this one

What am I doing wrong please?

Brian Frost
  • 13,334
  • 11
  • 80
  • 154
  • 2
    More of a guess than an answer, but have you set the current directory properly? – Mason Wheeler May 15 '11 at 15:56
  • @Mason: Thanks but I had tried that without success and I've updated the post to include this and an error message in case there is a prompt there. – Brian Frost May 15 '11 at 20:44
  • This shouldn't be it, but you have tried to pass `0` as the handle and `nil` as the verb (first and second argument, respectively) to `ShellExecute`? – Andreas Rejbrand May 15 '11 at 20:50
  • Also more of a guess: maybe this is a matter of access restrictions to some of your files/Packages? – Andreas May 16 '11 at 06:27

3 Answers3

3

Now I think I get it. Delphi 7 is old. Windows Vista (or 7) is new. You are running delphi32.exe as administrator, for compatibility, aren't you? That is, if you right-click delphi32.exe (or the short cut), you have selected "Run this program as an administrator" in the "Compatibility" tab. If you run delphi32.exe as an administrator, everything is fine, but if you don't, you get all these errors during startup.

And now, when you ShellExecute delphi32.exe from your Delphi application, delphi32.exe inherits the privileges of your Delphi application. This is most likely running without any elevated privileges, and so will delphi32.exe.

The solution: right-click your Delphi application (Project1.exe, say), select the "Compatibility" tab, and click the "Run this program as an administrator" checkbox.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • You're absolutely right. Well done. I also tried running the XE IDE as admin but the error remained. So, how does XE launch a process then? I will check out elevation in code. Thanks. – Brian Frost May 16 '11 at 12:41
2

You probably get the working directory wrong. Right-click the "Delphi 7" icon on the Start Menu, and Ctrl+C the working directory of this shortcut. Use this string as the Directory parameter of ShellExecute.

I don't have any Delphi 7 system to experiment with, but in my virtual WIndows 95 machine, in which I have Delphi 4 installed, there is indeed a specified working directory:

Delphi 4 shortcut properties in Windows 95

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
1

This may interest you: http://msdn.microsoft.com/en-us/library/ms682431(v=vs.85).aspx And here's a Delphi example on how to use the function: http://www.delphi3000.com/articles/article_4176.asp

Pateman
  • 2,727
  • 3
  • 28
  • 43