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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Composing a &macro with System Variables

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

How do I compose and run a command that contains windows variables like %PATH% and others as listed here: ?

Something like this...

Code:
lcDrive = 'E:'
Store "%PATH%\sdelete.exe -p2 -s -q -z " + (lcDrive) To eCmd
oWsh = Createobject("wscript.shell")
oWsh.Run(eCmd, 0, .F.)
Release oWsh

Thanks,
Stanley
 
Thank you Olaf,

It is exactly as you say, and thanks for the full explanation. I just tested the full scenario with both commands. Make perfect sense...

I see that there is a version of notepad in system32 that has a different size than notepad which is in the sysWOW64 folder. That accounts why notepad would work in all places, as vfp was running the syswow64 version and the os was running the system32 version.

I MOVED the sdelete command into the syswow64 folder and it worked from VFP and quit working from the os. I made a COPY of it and placed it into the system32 folder and now the os can run it as well.

Thanks again,
Stanley
 
Stanley,

Olaf has answered your question about why Notepad worked and SDELETE didn't.

On the point about GETENV("PATH"), I've shown you how to get the full contents of the Path variable. But keep in mind that there is really no point in doing that. It doesn't help locate a specific program or to run a program whose location you don't know. But I hope it will be a useful workaround for the bug in GETENV().

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Very good points, Mike. Indeed knowing the %PATH% variable doesn't help you very much, it's a systeem thing anyway, you maintain it in the control panel and Windows uses it to find some EXEs, etc. If you want to use something in Syswow64 or system32 depending on the OS being a 64bit or 32bit version you simply check the existance of Syswow64 first.

Taking into account bjitima use %SystemRoot% to test for Syswow64:
Code:
LOCAL lcSystemDir 
lcSystemDir = Addbs(GetEnv("SystemRoot"))+"SysWOW64"
IF !Directory(lcSystemDir)
   lcSystemDir = Addbs(GetEnv("SystemRoot"))+"System32"
ENDIF

That's all there is to it to find out which is the system dir for you to use as a 32bit process. Besides that due to system directory redirection you can always use Addbs(GetEnv("SystemRoot")+"System32", as access to it is redirected to SysWow64, but knowing the right dir in advance helps to save the redirection, of course.

Anything, that is officially installed via Installshield or other installers making use of the Windows Installer service have uninstall info in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\, the ffc registry class in registry.prg will help you read info from there.

That's another source of info and you know many programs install in %PROGRAMFILES%, if a user doesn't choose a different location, that different location still is stored in the uninstall information.

If you need the path to some automatable tool like Embarcadero Studio, why not talk to the vendor?

Anyway, define your environment as you need it, install some tool you need at your location configure it to a known location and make it configurable in case it's installed somewhere else. There also are lots of API calls to get a system directories or OLE server locations, eg see and
Bye, Olaf.
 
Thanks guys for this very informative thread... Issue solved for now with great howtos and workarounds for tomorrow. I've learned from the best! Seriously...

Thanks, Stanley


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top