Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Only run VFP exe when called by another program?
Message
 
To
14/06/2011 13:22:50
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01514336
Message ID:
01514348
Views:
77
>I'm currently working on a small launcher program in .NET that would eventually launch a VFP executable. Is there any reasonably sane method by which I can prevent execution of the VFP executable by any means other than by the launcher? In other words, the user should not be able to start the VFP executable by clicking on it.
>
>Thanks...


The code I have in my launcher class to do that is something like this:
	lcMap	= '{drive}:\{path}\' && x:\foxv\myApp\
	lcUNC	= '\\{Server}\{Share}\{Path}\' && \\myServer\myShare\foxv\myApp\
	if not Inlist(Nvl(Lower(getParentProgram()), ''), lcMap + 'launcher.exe', lcUNC + 'launcher.exe') && I want to be sure this is my launcher exe and not a copy in a different folder
		Messagebox('This program cannot run independently' + Chr(13) + 'You must use the Local Launcher application, contact IT for directions', 64, 'Direct access disabled!')
		return .f.
	endif
where getParentProgram is
local loLocator, loWMI, loProcesses, loProcess, lnProgID, loParentProcesses, loParentProcess, lcParent

declare integer GetCurrentProcessId in WIN32API

lcParent		= null
lnProgID		= GetCurrentProcessId()
loLocator		= CREATEOBJECT('WBEMScripting.SWBEMLocator')
loWMI			= loLocator.ConnectServer()
loProcesses		= loWMI.ExecQuery([SELECT * FROM Win32_Process WHERE ProcessId = ] + Transform(lnProgID))

For each loProcess in loProcesses
	loParentProcesses	= loWMI.ExecQuery([SELECT * FROM Win32_Process WHERE ProcessId = ] + Transform(loProcess.ParentProcessID))
	for each loParentProcess in loParentProcesses
		lcParent		= loParentProcess.ExecutablePath
	endfor
endfor

return lcParent
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Reply
Map
View

Click here to load this message in the networking platform