Code: Select all
EnableExplicit
Define Out
If CreateEnvironmentBlock_(@Out, #Null, #False)
Define Res$ = PeekS(Out)
Debug Res$
DestroyEnvironmentBlock_(Out)
EndIf
Code: Select all
ALLUSERSPROFILE=C:\ProgramData
Code: Select all
EnableExplicit
Define Out
If CreateEnvironmentBlock_(@Out, #Null, #False)
Define Res$ = PeekS(Out)
Debug Res$
DestroyEnvironmentBlock_(Out)
EndIf
Code: Select all
ALLUSERSPROFILE=C:\ProgramData
It's in the manual -> https://www.purebasic.com/documentation ... ables.htmlQuin wrote:I need to get all of the system environment variables in my app on Windows.
Code: Select all
p=RunProgram(GetEnvironmentVariable("comspec"),"/c set","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
If p
While ProgramRunning(p)
If AvailableProgramOutput(p)
Debug ReadProgramString(p)
EndIf
Wend
CloseProgram(p)
EndIf
Because you used the "Debug" command.Quin wrote:It also makes a debugger window pop up, for whatever reason
Code: Select all
EnableExplicit
Define Out
If CreateEnvironmentBlock_(@Out, #Null, #False)
Define Res$
Repeat
Res$ = PeekS(Out)
Out + (Len(Res$)+1)*SizeOf(Character)
Debug Res$
Until Res$ = ""
DestroyEnvironmentBlock_(Out)
EndIfCode: Select all
EnableExplicit
Define Out
If CreateEnvironmentBlock_(@Out, #Null, #False)
Define Res$
Repeat
Res$ = PeekS(Out)
Out + (Len(Res$)+1)*SizeOf(Character)
MessageRequester("", Res$)
Until Res$ = ""
DestroyEnvironmentBlock_(Out)
EndIf
Fred wrote: Mon Mar 11, 2024 11:51 am It returns an array:
Code: Select all
EnableExplicit Define Out If CreateEnvironmentBlock_(@Out, #Null, #False) Define Res$ Repeat Res$ = PeekS(Out) Out + (Len(Res$)+1)*SizeOf(Character) Debug Res$ Until Res$ = "" DestroyEnvironmentBlock_(Out) EndIf
Code: Select all
EnableExplicit
Define *lpEnvironment, *Out, Res$
If CreateEnvironmentBlock_(@*lpEnvironment, #Null, #False)
*Out = *lpEnvironment
Repeat
Res$ = PeekS(*Out)
*Out + (Len(Res$)+1)*SizeOf(Character)
Debug Res$
Until Res$ = ""
DestroyEnvironmentBlock_(*lpEnvironment)
EndIf
mk-soft wrote: Mon Mar 11, 2024 1:32 pm Fred wasn't paying attention
You have to pass the start pointer to release.
Code: Select all
EnableExplicit Define *lpEnvironment, *Out, Res$ If CreateEnvironmentBlock_(@*lpEnvironment, #Null, #False) *Out = *lpEnvironment Repeat Res$ = PeekS(*Out) *Out + (Len(Res$)+1)*SizeOf(Character) Debug Res$ Until Res$ = "" DestroyEnvironmentBlock_(*lpEnvironment) EndIf