Page 1 of 3
How I can get the path of the programs folder?
Posted: Wed Jan 26, 2005 4:07 am
by Armoured
Hi
How I can get the path of the program folder?
There is an Env variable for this path?
P.S.
I have WinXP
Thanks.
Re: How I can get the path of the programs folder?
Posted: Wed Jan 26, 2005 7:10 am
by Randy Walker
Every windows since '95 has used C:\Program Files as the default location for this directory. Other than placing on another (boot) drive I don't think it can go anywhere else.
I'm lazy and I don't like fiddling with registry stuff (even to just read) so I would take the easy way out and use an if then approach.
Code: Select all
If Filesize("C:\Program Files") = -2
path$="C:\Program Files"
ElseIf Filesize("D:\Program Files") = -2
path$="D:\Program Files"
ElseIf Filesize("E:\Program Files") = -2
path$="E:\Program Files"
;etc.
Endif
EDIT - You might want to add a backslash to your search string and path$ depending on your needs.
Re: How I can get the path of the programs folder?
Posted: Wed Jan 26, 2005 9:00 am
by Blade
Randy Walker wrote:
I'm lazy and I don't like fiddling with registry stuff (even to just read) so I would take the easy way out and use an if then approach.
Non-english users (PB has many of them) will thank you for sure!

Re: How I can get the path of the programs folder?
Posted: Wed Jan 26, 2005 9:24 am
by Randy Walker
To answer your second question....
I am certain the path would be in the registry because Windows does allow D: or E: or F: etc to be your boot drive and so Windows has to keep record of this somewhere.
If you really want it, open regedit and search for ":\Program Files" without the quote marks. This will help you to locate the path to the KEY. Further examples here in the forum will show you how to read the registry. I do read it when I absolutely have to but I just prefer to leave it alone. This is an instance where I simply would not bother with the regisrty.
Posted: Wed Jan 26, 2005 9:30 am
by El_Choni
You can use this:
Code: Select all
ProgramFiles$ = Space(#MAX_PATH)
GetEnvironmentVariable_("PROGRAMFILES", ProgramFiles$, #MAX_PATH)
Debug ProgramFiles$
@Randy: so you're one of these programmers who hardcode the program files dir path? ("C:\Archivos de programa" here) tsk, tsk...

Posted: Wed Jan 26, 2005 9:51 am
by Randy Walker
El_Choni wrote:
@Randy: so you're one of these programmers...
Hold on one ding dang minute. Where in world did you ever get the notion that I was a programmer. A novice hacker at best maybe and I don't mean that in the typical misnomer (cracker) fashion. I understand a little bit and hack at it like hell until I get it to do something close to what I hope for. I consider programmers to be deeply versed individuals in the science and although I consider myself well versed in some respects, I have never ever refered to myself as a programmer.
The sample I gave was cut and paste, thrown together without much thought and left that way because of it's clarity. I could have cut it down and packed strings and substrings into variables but why bother when cut and past is easier?
Anyway, you came up with a much cleaner solution. New to me because anything in 32 bit APIs are all new to me. Catching up slowly though.
Posted: Wed Jan 26, 2005 9:57 am
by Randy Walker
@ El_Choni
Speaking of clarity. There is nothing a newcomer would find obscure in my code sample. Your's... well been here a while and never ran into #MAX_PATH before. Is this a PureBasic constant or one that you created but left out any assignment in your sample?
EDIT - catagory says beginners... can't believe this guy was laughing at me

Posted: Wed Jan 26, 2005 10:09 am
by El_Choni
(I wasn't laughing at you, I just put that emoticon to make clear I was kidding, not flaming you)
#MAX_PATH is a Windows constant, equal to 260. It represents the maximum number of characters that the string representation of a path can have. So it's often used when allocating memory to call a function which returns a path. You can use 1024 if you wish.
If you code programs, I would say you're a programmer. If I'm wrong, then ok, you're not a programmer. Neither am I. I am a tea biscuit.

Posted: Wed Jan 26, 2005 10:21 am
by GedB
Hey Randy,
Taking little digs at each other is a European thing.
I know from past experience that this is something Americans aren't used too, so I hope you don't take any offence at El_Choni's comments.
It's a sign of friendliness, like a hearty slap on the back.

Posted: Wed Jan 26, 2005 10:27 am
by Randy Walker
El_Choni wrote:(I wasn't laughing at you, I just put that emoticon to make clear I was kidding, not flaming you)
Now what? You're saying I not worhty of flaming?

Posted: Wed Jan 26, 2005 10:28 am
by Randy Walker
GedB wrote:I know from past experience that this is something Americans aren't used too, so I hope you don't take any offence at El_Choni's comments.
Yes I caught that. I was joking as well... look up to see my smiley

Re: How I can get the path of the programs folder?
Posted: Wed Jan 26, 2005 10:29 am
by GPI
Randy Walker wrote:Every windows since '95 has used C:\Program Files as the default location for this directory.
Code: Select all
If Filesize("C:\Program Files") = -2
path$="C:\Program Files"
ElseIf Filesize("D:\Program Files") = -2
path$="D:\Program Files"
ElseIf Filesize("E:\Program Files") = -2
path$="E:\Program Files"
;etc.
Endif
.
Congratulation. With this code, you faild to find my Program files-folder. Because i have a german system and this folder is called "C:\Programme". And when you have installed more than on Windows in diffrent partitions...
Very Bad code.
One of best methode is:
Code: Select all
Procedure.s Reg_GetValue(topKey, sKeyName.s, sValueName.s, ComputerName.s)
lpData.s
GetValue.s =""
If Left(sKeyName, 1) = ""
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbData = 255
lpData = Space(255)
GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)
If GetHandle = #ERROR_SUCCESS
Select lType
Case #REG_SZ
GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)
If GetHandle = 0
GetValue = Left(lpData, lpcbData - 1)
Else
GetValue = ""
EndIf
Case #REG_DWORD
GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lpType, @lpDataDWORD, @lpcbData)
If GetHandle = 0
GetValue = Str(lpDataDWORD)
Else
GetValue = "0"
EndIf
EndSelect
EndIf
EndIf
RegCloseKey_(hKey)
ProcedureReturn GetValue
EndProcedure
Procedure.s GetProgramFilesFolder()
Type = $2
location$=Reg_GetValue(#HKEY_LOCAL_MACHINE ,"SOFTWARE\Microsoft\Windows\CurrentVersion","ProgramFilesDir","")
ProcedureReturn location$
EndProcedure
Debug GetProgramFilesFolder()
Posted: Wed Jan 26, 2005 10:36 am
by Randy Walker
@ El_Choni
I mean no offense here either. When I am in the beginner forum I make efforts to post self explanitary code. Not always possible and sometimes I forget where I am... how I got here... what day it is... you know

Re: How I can get the path of the programs folder?
Posted: Wed Jan 26, 2005 10:42 am
by Randy Walker
GPI wrote:Congratulation. With this code, you faild to find my Program files-folder. Because i have a german system and this folder is called "C:\Programme". And when you have installed more than on Windows in diffrent partitions...
Very Bad code.
Now we are in the presence of a true programmer and we have confirmation... I AM NOT A PROGRAMMER
Who'd of thought anyone would install Windows in some foreign language?
(Ignorence spilling out all over me here

)
Thanks GPI!!!
Re: How I can get the path of the programs folder?
Posted: Wed Jan 26, 2005 11:00 am
by gnozal
Randy Walker wrote:Who'd of thought anyone would install Windows in some foreign language?
English is a foreign language for most people in the world
