Hey there!

We often come across Error codes (or Exit Codes) in windows operating system environment, but most of the time we’re unsure what these numerical values actually mean, unless we try Googling it out the number.

WHAT IS ERROR \ EXIT CODE ?

The Exit code or Return code or System Error code of a process in computer programming is a small number passed from a child process (or CALLEE) to a parent process (or CALLER) when it has finished executing a specific procedure or delegated task.

Windows uses 32-bit signed integers as exit codes.If a process fails initialization, a Windows system error code may be returned

So, in order to decipher these numbers, I wrote two PowerShell functions –

Import-WindowsErrorCode : To import all these error Code information from series of MSDN URL’s mention HERE Get-WindowsErrorCodeInfo : To query the information of a specific Error Code from imported data..

PURPOSE :

Quickly lookup for Error description depending upon the Windows Error Code/ Exit Code passed. Adding some verbosity to plain simple Error/Exit Codes. Could be utilized for a better Error Handling and better Investigation and Analysis .

Like in the below screenshot I passed the exit code returned while installing a .MSI file to the function Get-WindowsErrorCodeInfo to get information like ErrorString, Description and corresponding Hexa-Decimal value

Similarly, more information can be queried from the Error codes generated by running .exe or .MSU files, like in below image.

IMPORTING/SAVING SYSTEM ERROR INFORMATION :

Run the below mentioned function from a Powershell console and it will make web Queries to Microsoft MSDN Web sites to capture all error codes, like in the following screenshot.

Its nothing but a series of Invoke-WebRequest’s on MSDN URL’s to web scrap the error code information, Sort them and make them in presentable format, which could be easily parsed.

Now you can either convert and Save the results locally in a JSON file (You can also choose CSV) ,

Or, convert it to JSON , then COPY the result

and upload it to your Github Gist.

HOW TO RUN IT :

Get the script from HERE on my Github Repository and you can run the Import-WindowsErrorCode function to save the information and then Get-WindowsErrorCode to query the error codes.

Following are some ways to Query information using the Error/Exit Codes

You can query single exit code or can pass multiple value through Pipeline.

By default it queries my Github Gist available over internet.

You can also query the exit code information from a local JSON file .

Or you can dump the JSON data on your Github Gist and retrieve the exit code information like below, by passing your URL under -GitHubJSONUrl switch

In case you don’t mention any specific exit code or path ; The function will return all exit code available from my Github gist , which I would advise to be the preferable method. Which will fetch around 2700 Exit Codes

NOTE :

You can skip the importing part and directly use the Get-WindowsErrorCodeInfo function which will query my Github gist URL by default ( but Requires Internet Connectivity).

I’ve taken care of the importing part for you guys 🙂 by importing and saving the all Windows System Error codes on my public Github gist.

Updated on 21 July :

From few comments on Reddit link sharing, I’ve learned that this may not be the smartest way to get the error code description. You can also use windows Native command (Net Helpmsg Errorcode) to get the description which uses native windows API to get this information.

but after some hit and trial I’ve found that this approach has some limitations and doesn’t identifies every exit code we fetched form Microsoft websites. Like in the example in following screenshot for ERROR_INTERNET_* type error messages



I think both approaches are good and there is a trade-off between Speed and More information. Choice is yours!

Hoping you find it useful in your day to day work, comment and let me know for any improvements! Happy Learning 🙂

@SinghPrateik