1

I'm trying to get the activation status of Windows. I've got this code:

 Process proc = new Process();


 proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
 proc.StartInfo.FileName = "cmd.exe";
 proc.StartInfo.Arguments = "/C slmgr /xpr";
 proc.StartInfo.UseShellExecute = false;
 proc.StartInfo.CreateNoWindow = true;
 proc.StartInfo.RedirectStandardOutput = true;
 proc.StartInfo.RedirectStandardInput = true;
 proc.Start();

 string x = "";

 while (!proc.HasExited)
 {
     x += proc.StandardOutput.ReadToEnd();
 }

 return x;

As some of you may know, the command "slmgr /xpr" will make a pop-up appear informing you of your Windows activation status.

Executing this code, I get the pop-up box (and "x" is empty). What I want is to get the text that's in it (so it appears on a label in my form). I wonder if there's any way to extract just the text from inside the pop-up that appears, in this case it would be something like "the machine is permanently activated".

Is there any simple way to achieve this?

Alex K.
  • 171,639
  • 30
  • 264
  • 288
S. M.
  • 227
  • 1
  • 12

1 Answers1

5

slmgr is actually a VBScript file not an executable, when you run it it will default to using the WScript runtime which is for windowed scripts and uses Message Boxes for default output. If you change to CScript you will get console output:

proc.StartInfo.FileName = "cscript.exe";
proc.StartInfo.Arguments = "/nologo \"" + Path.Combine(Environment.SystemDirectory, "slmgr.vbs") + "\" /xpr";

You can then capture this: Capturing console output from a .NET application (C#)

You could also look inside the script file, see whats its doing & reimplement it in your code (ymmv).

Alex K.
  • 171,639
  • 30
  • 264
  • 288