WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get WinBatch Process Environment Block

 Keywords:  Get WinBatch Process Environment Block Dump GetEnvironmentStringsA FreeEnvironmentStringsA Kernel32.dll DllCall IntControl 32

Use EnvItemize function.

*OR*

DllCall code for looking at the WinBatch process environment block

strOld = DirGet()
DirChange("d:\")  ; Set WD of d drive - assumes d is mounted.
DirChange(strOld)

; Get a pointer to the block.
hKernel32 = DllLoad(StrCat(DirWindows(1),"Kernel32.dll"))
pEnv      = DllCall(hKernel32,long:"GetEnvironmentStringsA")

; Convoluted method for handling embedded nulls.
strEnvBlock = ""
x           = 0
bDone       = 0
While !bDone
   cValue = IntControl(32, pEnv+x, "byte", 0, 0)
   If cValue == 0

      ; Check for double null block terminator.
      If IntControl(32, pEnv+x+1, "byte", 0, 0) == 0 Then bDone = @TRUE
      Else cValue = Char2Num(@LF) ; Change embedded null to lf.
   EndIf
   strEnvBlock = StrCat(strEnvBlock,Num2Char(cValue))
   x = x + 1
EndWhile

; Clean up
DllCall(hKernel32,long:"FreeEnvironmentStringsA",long:pEnv)
DllFree(hKernel32)

; Display the block.
; Note that MSFT flatly states that an env variable cannot have
; an '=' in its name but drive variables do...
AskItemlist("Environment Block Dump",strEnvBlock,@LF,@UNSORTED,@SINGLE,0)

Article ID:   W17930
Filename:   Get WinBatch Process Environment Block.txt
File Created: 2011:09:29:14:47:40
Last Updated: 2011:09:29:14:47:40