CMD到C#的转换

本文关键字:转换 CMD | 更新日期: 2023-09-27 18:27:53

有人能帮我把这个.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

CMD到C#的转换

您需要启动cscript的进程,并提供vbs文件und Find命令作为参数。可通过出口代码检查结果:

        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.");
        }