[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Assistance required with running application from external resource

Posted on 2007-12-06
18
Medium Priority
?
174 Views
Last Modified: 2010-04-21
Hi experts,

I have created an active form.

Form the htm page I double-click on the image and here's is what it should do:

It all works...well kind off! Sometimes I need to double-click 5 times before the APPLICATION runs :o/

The main problem is that the application that it runs...has a button which shellexecute's another external application.

This does not run.

If I run the application directly without running it from the active form it's ok but I get errors or no outcome
when doing it via the active form.

Can anyone help me please?

Thanks

ST3VO

procedure TVRShowroom.Image1DblClick(Sender: TObject);
begin
 if fileexists('C:\myapplication.exe') then
    begin
      try
        memo1.Lines.SaveToFile('C:\test.dat');
      finally
       shellExecute(handle,'open',pchar('C:\myapplication.exe'),nil,nil,SW_SHOWNORMAL);
        
      end;
    end
  else
  if not fileexists('C:\myapplication.exe') then
 
    begin
      ShellExecute(Handle, 'open', PChar('http://www.website.com/Setup.exe'), nil, nil, SW_SHOWNORMAL);
    end;
end;

Open in new window

0
Comment
Question by:ST3VO
  • 10
  • 8
18 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 20426468
first, you don't need the line number 13. the else means just exactly that, that the file does not exist :)

second: you say you doubleclick on an image from a htm. that looks weird to me because you will not have an image component there to doubleclick but the browser object. so I need a little more explanation from your side as to what that image is and how it got there.
because If I make you a sample project with a TImage on the form and at that image doubeclick putting your code, it will run just fine every time.
so in your project there is something extra. I need that somethign extra. what's the relation between the image and the htm you mentioned? etc.
0
 

Author Comment

by:ST3VO
ID: 20426484
First....Yes I agree :o)

Second...It's an ActiveX Form....I've inserted a TImage on it and that is what you see on the webpage!

Then I put the code above on the Double-Click event of the TImage.

Hope this answers your question!

Thanks

ST3VO
0
 
LVL 28

Expert Comment

by:2266180
ID: 20426539
I never done an activex, yet alone to be used from a webpage, but the first thing that comes to mind is: security. is the activex allowed to read from the root of drive C? what about to execute a program?

quick solution to find those out:
place showmessages in the calls:

also, related to security, keep in mind that the application you will execute from the activex WILL INHERIT the security attributes of the activex control. that is very important because if your myapplication.exe requires soem stuff that the activex is not allowed to, it wil not be able to do it because it was run from the activex. (for example, registry access, some file system access, etc).

procedure TVRShowroom.Image1DblClick(Sender: TObject);
begin
  showmessage('Double clicked on image. file exists? '+booltostr(fileexists('C:\myapplication.exe'), true));
 if fileexists('C:\myapplication.exe') then
    begin
      try
        memo1.Lines.SaveToFile('C:\test.dat');
      finally
       shellExecute(handle,'open',pchar('C:\myapplication.exe'),nil,nil,SW_SHOWNORMAL);
        
      end;
    end
  else
  if not fileexists('C:\myapplication.exe') then
 
    begin
      ShellExecute(Handle, 'open', PChar('http://www.website.com/Setup.exe'), nil, nil, SW_SHOWNORMAL);
    end;
end;

Open in new window

0
Independent Software Vendors: 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!

 

Author Comment

by:ST3VO
ID: 20426571
The application actually runs and opens so that works!

Is there a way of getting the ActiveX Form to not have anything to do with C:\myapplication.exe after it has opened it?

For example...let another process load my application up?

0
 
LVL 28

Expert Comment

by:2266180
ID: 20426607
>> The application actually runs and opens so that works!
the fact that it runs and opens when you execute it, it's one thing, the key thing is to run and open when executed from the activex.

>> Is there a way of getting the ActiveX Form to not have anything to do with C:\myapplication.exe after it has opened it?
For example...let another process load my application up?

this I don't understand.you talk about open and load, but theya re one and the same thing. so either you want your activex to noe have anythgin to do with the program after opening/loading (which I don't understand what you want exactly, so give more explanation. for ex what operations are you thinking about (I don't know what your program do ;) )
OR, you want another process to open/load your application.
so ... what is it?

you can do something like:
- mae a "loader" application/service" that runs on the PC and when you click on the image the activex will jsut communicate with that applicaiton/service and tell it to start myprogram.exe
BUT, you need a way to install that loader as well, so you're in a loop there.

better tell me from a to z what you are actually trying to do.
0
 

Author Comment

by:ST3VO
ID: 20426710
Right....

I have an application that the user will install on the computer via setup!

Once installed the user can run it from the desktop and it works perfectly.

The actual application consists of 2 separate .exe's

1. The Main (Does Queries etc)
2. The App that displays the results
(There are reasons with they are two separate exe's) :o)

Anyway...the Main Application.exe ....Does the queries and then Runs the Second .exe via Shellexecute.

All this works fine from the actual desktop.

BUT, the reason I created the activeX Control is so that the user can go the my webpage and click on the ActiveX which runs the application from the actual webpage instead of going to the Desktop icon of via Start -->Program Files...

The activeX actually does run the application and does the Queries and it's stuff!!! BUT It's not running Application 2.

There is where the problem is!

Hope this helps!
0
 
LVL 28

Expert Comment

by:2266180
ID: 20426732
and application 2 is actually c:\myapplication.exe from your code? if so, does the showmessage I posted appear? does it show true or false for the fileexist?
0
 

Author Comment

by:ST3VO
ID: 20426809
No c:\myapplication.exe is the application the the ActiveX Control runs!

Then myapplication.exe then Runs Application2.exe using ShellExecute!

The ActiveX Control only Runs c:\myapplication.exe the rest is does from the actually c:\myapplication.exe not the ActiveX Control!
0
 
LVL 28

Expert Comment

by:2266180
ID: 20426954
and the problem is in application2.exe? then why do you say the problem is in the activex form and image?

you lost me :)
0
 

Author Comment

by:ST3VO
ID: 20427006
The problem is that when I Run application1.exe directly from the Desktop application1.exe can Run application2.exe

BUT

When the ActiveX Control Runs Application1.exe, Application1.exe does not RUN application2.exe.

0
 
LVL 28

Expert Comment

by:2266180
ID: 20427229
that pushes us back to what I explained about security :) you need to configure your activex security to allow the execution of other programs.

BUT, I don't think this is possible. imagine what would happen if any activex control could execute arbitrary programs on ones PC. format c: , regedt.exe some_key_here_with_value_to_some_malware_to_autostart, etc.
it's a big security risk. probalby that is why you cannot control that from the IE options.

here is an article I just found explaining such problems: http://www.computerbytesman.com/acctroj/hp.htm

basically, this is not a delphi issue but an activex security issue :)
you should post in community support to have your question moved to the right TA
at least here: http://www.experts-exchange.com/Microsoft/Development/Microsoft_Programming/Active-X/
0
 

Author Comment

by:ST3VO
ID: 20427396
Right....I 've done a little test and added another button to application1.exe where I added a shellexecute for running notepad.exe and it worked, so this means that I have permissions to execute external exe's from application1.exe.

I also managed to get an error report of what was wrong with application1.exe not working in this case processing properly.

Here is the error:

The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data.

So, now we know what's going on at least :o)

I tried setting the ADOConnection to DenyNone and it's works fine when you run application1.exe directly BUT when the ActiveX control runs it I get the error above!

Any ideas???

0
 

Author Comment

by:ST3VO
ID: 20427820
Right....Here's an update:

I've put a load of showmessages throught the code and the error comes from here:

See code below:

The only thing I don't understand is what has the error:

"The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data."

Have to do with it :o/

Hope this helps :o)


Var
exInfo: TShellExecuteInfo;
Begin
if fileexists('C:\vrsoft\AutoExposure\StrImg.dll') then renamefile('C:\vrsoft\AutoExposure\StrImg.dll','C:\vrsoft\AutoExposure\StrImg.exe');
 
FillChar( exInfo, Sizeof(exInfo), 0 );
With exInfo Do Begin
cbSize:= Sizeof( exInfo );
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
Wnd := GetActiveWindow();
ExInfo.lpVerb := 'open';
lpFile:= 'C:\vrsoft\AutoExposure\StrImg.exe';
nShow := SW_SHOWNORMAL;
End;
If fileexists(exinfo.lpFile) and ShellExecuteEx( @exInfo ) Then Begin
ProcHandle := exInfo.HProcess;
while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do
Application.ProcessMessages;
End
Else
//ShowMessage(SysErrorMessage( GetLastError ));
CloseHandle(ProcHandle);

Open in new window

0
 
LVL 28

Accepted Solution

by:
2266180 earned 2000 total points
ID: 20427861
>> "The Microsoft Jet database engine cannot open the file ''

why is it empty string? there should be the path to the file. which means that the activex for some reason doesn't find the mdb. is that possible? how do you manahe the connection string?
0
 

Author Comment

by:ST3VO
ID: 20428083
I'm checking that out right now!

I think it has to do with not having adsolute paths....

I have the feeling it's going to be that!

0
 

Author Closing Comment

by:ST3VO
ID: 31413427
YESSS!!! Everthing works now!!! What you said clicked the paths in my head.
You need to have full paths for it to work and not relative! Changed it all and IT WORKS!!!! hehehe :o)

Thanks a million for your time and patiance!
0
 
LVL 28

Expert Comment

by:2266180
ID: 20428818
you're welcome :)
0
 

Author Comment

by:ST3VO
ID: 20428844
I've opened a couple of other simpler questions that I need to complete the program :o)

Thanks again!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

872 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