This is a little more generic. My original request to obtain status codes was due to an error I was getting trying to connect to a WEB IDE server and wanted to see if it was interpreted with a description rather than just a number. Then I got to thinking about enums in general and how they might be like WB's maps. Finally wondered if WB could write a C# dll to create or update custom enums for scripts (or would it just be better to stick with maps : albeit the dll might work with versions after 2013).
Anyway. The Powershell code seems to handle all sorts of enums.
;Winbatch 2019B - Use CLR/Powershell to detail enumerations
;This should work with versions after 2013
;Stan Littlefield, August 25,2019
;/////////////////////////////////////////////////////////////////////////////////////////////////////////
Gosub udfs
IntControl(73,1,0,0,0)
If Version( )< '2013A'
Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
Exit
EndIf
enums="System.Net.HttpStatusCode":@TAB
enums=enums:"System.ConsoleColor":@TAB
enums=enums:"System.DateTimeKind":@TAB
enums=enums:"System.DayOfWeek":@TAB
enums=enums:"System.ConsoleKey":@TAB
enums=enums:"System.StringComparison":@TAB
enum = AskItemlist("Select Enumeration", enums, @TAB, @SORTED, @SINGLE, @FALSE)
cFile=Dirscript():"%enum%.txt"
If FileExist(cFile) Then FileDelete(cFile)
enumvalues()
If FileExist(cFile)
runwait("Notepad",cFile)
Else
Display(2,"File Not Created",cFile)
Endif
Exit
:WBERRORHANDLER
geterror()
Message("Error Encountered",errmsg)
Exit
:udfs
#DefineSubroutine enumvalues()
IntControl(73,1,0,0,0)
cScript = '[Enum]::GetValues([%enum%]) |':@CRLF
cScript = cScript:'ForEach-Object {':@CRLF
cScript = cScript:'[PSCustomObject]@{':@CRLF
cScript = cScript:' Code = [int]$_ ':@CRLF
cScript = cScript:' Description = $_.toString()':@CRLF
cScript = cScript:' }':@CRLF
cScript = cScript:' } | out-file "%cFile%"'
BoxOpen("Please Wait","Processing... ")
ObjectClrOption("useany", "System.Management.Automation")
objAutoPs = ObjectClrNew("System.Management.Automation.PowerShell")
oPshell = objAutoPs.Create()
oScope = ObjectType("BOOL",@TRUE)
oPshell.AddScript(cScript,oScope)
objAsync = oPshell.BeginInvoke()
oPShell.EndInvoke(objAsync)
oPshell.Dispose()
oPshell=0
BoxShut()
Return (1)
:WBERRORHANDLER
oPshell=0
geterror()
Message("Error Encountered",errmsg)
Exit
#EndSubroutine
#DefineSubRoutine geterror()
wberroradditionalinfo = wberrorarray[6]
lasterr = wberrorarray[0]
handlerline = wberrorarray[1]
textstring = wberrorarray[5]
linenumber = wberrorarray[8]
errmsg = "Error: ":lasterr:@LF:textstring:@LF:"Line (":linenumber:")":@LF:wberroradditionalinfo
Return(errmsg)
#EndSubRoutine
Return