Wind4 / vlmcsd

KMS Emulator in C (currently runs on Linux including Android, FreeBSD, Solaris, Minix, Mac OS, iOS, Windows with or without Cygwin)
https://forums.mydigitallife.net/threads/50234
8.35k stars 2.22k forks source link

Error not passed to output cmd #72

Closed KoalafiedDev closed 2 years ago

KoalafiedDev commented 2 years ago

When using the command: START "" /WAIT /b "%~dp0vlmcs-Windows-x64.exe" 192.168.2.14 -v the output is missing information when the kms server cannot be contacted.

for example; when the kms server can't be contacted, the output from cmd is:

Request Parameters
==================

Protocol version                : 6.0
Client is a virtual machine     : No
Licensing status                : 2 (OOB grace)
Remaining time (0 = forever)    : 43200 minutes
Application ID                  : 55c92734-d682-4d71-983e-d6ec3f16059f (Windows)
SKU ID (aka Activation ID)      : 8de8eb62-bbe0-40ac-ac17-f75595071ea3 (Windows Server 2019 ARM64)
KMS ID (aka KMS counted ID)     : 8449b1fb-f0ea-497a-99ab-66ca96e9a0f5 (Windows Server 2019)
Client machine ID               : e6448d51-6852-48f1-a6d7-4a7df1d5bc4f
Previous client machine ID      : 00000000-0000-0000-0000-000000000000
Client request timestamp (UTC)  : 2022-07-29 21:17:17
Workstation name                : ns1.microsoft.com.tw
N count policy (minimum clients): 5

Connecting to 192.168.2.14:1688 ...

but the error part is missing from the output:

Connecting to 192.168.2.14:1688 ... 192.168.2.14:1688: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Fatal: Could not connect to any KMS server

I know that I can use the Pause or Timeout /t command, but I'm trying to pass the output to a C# application, and I can't get it to work. Is there a solution for this?

rouben commented 2 years ago

Rather than parse the output, have you tried looking at the return code? On Linux, at least, vlmcs returns a non-zero exit code when it encounters an error.

Also, why is the workstation name ns1.microsoft.com.tw? Do you work for Microsoft?? 😅

KoalafiedDev commented 2 years ago

Thanks for your reply. The return code is a great tip. Although I can't directly see what the error code means, I know that an error occurred and that is enough. I applied the solution in the code below.

 public static string vlmcs(string server, string port)
        {
            Cursor.Current = Cursors.AppStarting;
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "vlmcs-Windows-x64.exe",
                    Arguments = $"{server}:{port} -v",
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
            };

            proc.Start();

            string output = proc.StandardOutput.ReadToEnd();
            proc.WaitForExit();
            Cursor.Current = Cursors.Default;

            if (proc.ExitCode != 0)
            {
                output = output + "Fatal: Could not connect to any KMS server";
            }

            return output;
        }

And btw no, I do not work for Microsoft 😂. This is a test request performed by vlmcs to test the connection to the kms server lol.

rouben commented 2 years ago

Glad it was a helpful tip. Unfortunately, the error handling code (and other types of code) in vlmcs and vlmcsd is all over the place, so it's kind of a pain to map all possible return codes out... unless they are documented in the man pages? But I doubt that.