Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

launch a 64-bit exe from within VFP?

Status
Not open for further replies.

Ellen123

Programmer
Nov 7, 2023
3
0
0
US
I have a 64-bit utility program that I want to launch from within a compiled VFP dll. It doesn't seem to be working, I'm guessing because VFP needs 32-bit compatible components. I'm using ShellExecute. I'd like to avoid making the new utility program 32-bit (some libraries are not compatible). Is there a way that VFP could call the 64-bit exe?
 
I am not sure if it would help but as far as I know VFPA can be compiled into a 64bit forxpro version. (


If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Ellen,

Can you try to run a batch file with ShellExecute? In the batch file you call your 64-bit utility.
Perhaps worth trying this. If you do, please report your findings.

Regards, Gerrit
 
I've never had a problem using ShellExecute()to launch a 64-bit executable. The only issue I can think of is if the target program resides in System32, the file redirector might come into play:

Microsoft Ignite said:
A 64-bit executable file located under %windir%\System32 cannot be launched from a 32-bit process, because the file system redirector redirects the path. Do not disable redirection to accomplish this; use %windir%\Sysnative instead.

Source:
If that doesn't help, perhaps you could tell us what exactly you are seeing. Is ShellExecute() returning an error code (an integer less than 32)?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Running another 64bit process is not a problem at all, shellexecute does so, RUN /N does so, you start a new independent process and that can be 32bit, 64bit, it could even be 16bit, if that was an option of the OS, or 5bit, or 153bit, it doesn't matter. It's not loaded into the 32bit process you run in.

The only hurdle you have is with excecutables part of the system by Microsoft or by some vendor putting it into System32 or SysWow64 or both, because even if you try to run somethng from System32 (the Windows system folder for 64bit system tools like regsrv, regasm, odbc manager and many more, even notepad), then UAC redirection would reroute you to use the 32bit equivalent in SysWow64 instead. But you can access any EXE in C:\Program Files\ and are not limited to C:\Program Files (x86)\ only, access to 64bit applications installed there is not redirected. And executables installed in non default locations only depend on file permissions, whether you can or cannot execcute them, which applies to any EXE anyway.

The only other things restricting you are system policies a company may use or blacklisting or whitelisting of executables. But then it becomes just a negotioation with the on site adminstration to allow what you need.

PS: I see Mike also already addressed the System32 issue. I wonder if that's even the case. Usually, if an executable is useful to you, you could put it side by side to your own EXE. And I do realize you talk of a VFP DLL you created and runnung an executable from that DLL, but any VFP DLL is 32bit and will be used by some 32bit process and could use RUN, shellexecute, createprocess and all other means of starting a new process, it doesn't matter whether that starting code is part of a VFP DLL or a VFP EXE.

Chriss
 
If Gerrit's batch file idea doesn't work, you might also try PowerShell, as it's 64bit, and may be able to run in its environment.


Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS, ATD

"I try to be nice, but sometimes my mouth doesn't cooperate.
 
Are you perhaps declaring ShellExecute wrong? Or are you forgetting to pass in the full path to the executable you want to execute?

This runs fine
Code:
DECLARE INTEGER ShellExecute IN shell32.dll ; 
  INTEGER hndWin, ; 
  STRING cAction, ; 
  STRING cFileName, ; 
  STRING cParams, ;  
  STRING cDir, ; 
  INTEGER nShowWin

cFileName = "C:\Program Files\7-Zip\7zFM.exe" && choose any other 64bit executable
cAction = "open" 
nRetval = ShellExecute(0,cAction,cFileName,"","",1)
? nRetval

And in task manager you can see and verify it's a 64bit process, if it's not enough to know C:\Program Files\ is for 64bit executables.
running64bit_e3wwjw.jpg


There's really no need to indirectly execute via something else like a bat file. You can execute 64bit executables, no problem.

Chriss
 
And it would be really helpful to know what value ShellExecute() is returning. As I mentioned earlier, a returned value of 32 or less is an error code.

The most common errors involve invalid file or path names, or invalid action parameters (that is, either the second parameter is an action that is not registered for the executable, or there are no actions registered, or the second parameter is blank).

But without knowing the returned value, it is difficult to give more help.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,

I just checked the app I’m working on right now. It’s a taskscheduler running in systray.
It uses ShellExecute to start a task. It runs 32-bit and 64-bit tasks without a problem.

Regards, Gerrit
 
Ellen,

It has been several days since you posted your question, and you have had eight replies.

It would be helpful if you could now come back and give us some feedback on our posts. Did any of the replies solve the problem? If not, can you provide the further information that we have requested.

At the very least, it would be polite to acknowledge the replies that you have received.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you everyone!!
OK so if it *should* work then yes I hope that means I'm doing something wrong. I'm going to try a few things and let you know again.
Thanks
Ellen
 
It *does* work, you can verify this yourself with my sample code.

Chriss
 
ShellExecute returns 42 (great number...) so it was running fine.

I also tried a different 64-bit exe and it works fine, so I started calling the one I'm using manually with different parameters - and the problem was it was trying to use data from a directory with no permissions.

Thank you for the help.
Ellen
 
Great stuff, glad it's been resolved.


Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS, ATD

"I try to be nice, but sometimes my mouth doesn't cooperate.
 
Ellen123 said:
it was trying to use data from a directory with no permissions
So you were assuming it didn't run, because it failed to do what you expected it to do?

Okay, but then indeed knowing the meaning of the returnvalue of ShellExecute is really important to look for other problems like the directory permissions.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top