CMD到C#的翻译

时间:2013-08-15 13:30:22

标签: c# cmd

有人可以帮我把这个.cmd翻译成c#

@echo off

title Windows Activation check by dsoft

cscript C:\Windows\system32\slmgr.vbs /dli | FIND "259200" >NUL
IF '%ERRORLEVEL%' EQU '0' (
echo Windows is already activated.
) ELSE (
echo Windows is not activated, Try later again.
)
pause

1 个答案:

答案 0 :(得分:2)

您需要为cscript启动一个进程,并提供vbs文件和Find命令作为参数。结果可以通过exitcode检查:

        Process p = new Process();
        p.StartInfo.FileName = "cscript";
        p.StartInfo.Arguments = " C:\\Windows\\system32\\slmgr.vbs /dli | FIND \"259200\" >NUL";
        p.Start();
        p.WaitForExit();

        if (p.ExitCode == 0)
        {
            MessageBox.Show("Windows is already acivated.");
        }
        else
        {
            MessageBox.Show("Windows is not activated, Try later again.");
        }