【问题标题】:How to use batch file to compare and get uuid如何使用批处理文件比较和获取 uuid
【发布时间】:2018-08-05 20:18:31
【问题描述】:

我最近对批处理文件编码产生了兴趣,现在我正在处理一个项目。 在项目中,我创建了一个基本程序,要求用户输入我存储在文本文件(大约 50 行许可证)中的许可证代码,并将其嵌入到我的批处理文件中,并使用第三方应用程序转换我的批处理文件到 .exe(大约 50 行许可证)。我的组织分支中有大约 42 台计算机,我想在其中部署该程序。

然而,我的挑战是,由于批处理文件和许可证文件都在一个 .exe 中,所以一个密钥可以在所有 42 台计算机上工作。这很糟糕。

我曾尝试使用 wmic csproduct get uuid 来比较计算机,但我找不到自己的方式。

我真的需要这方面的帮助。

这是我目前的工作:

SETLOCAL
:startup
SET "Password_File=%UserProfile%\Desktop\Password_File.txt"
set "fail="
set "Activation_Code="
set /p "Activation_Code=Your Activation Code Here: "
REM cls
IF NOT DEFINED Activation_Code ( GOTO :startup

 )

findstr /X /l /c:"%Activation_Code%" <"%Password_File%" >nul || set fail=1
if defined fail (
echo Invalid Activation Code!
"%UserProfile%\Desktop\Msgbox Failed.vbs"
    GOTO :startup
)


:yes

REM cls

echo Success, you have access!
REm >> %Password_File% echo %Activation_Code%
    "%UserProfile%\Desktop\MsgboxSuccess.vbs"
"C:\Program Files (x86)\Foxit Software\Foxit Reader\FoxitReader.exe"

:: This line remove the already entered activation code from the licence file copied to the computer


type %Password_File% | find /V "%Activation_Code%" >XXFile.txt
del "%UserProfile%\Desktop\Password_File.txt" 
ren %UserProfile%\Desktop\XXFile.txt Password_File.txt

goto :eof


:nope
REM cls
echo Activation Code has already been used or Invalid!
"%UserProfile%\Desktop\Msgbox Failed.vbs"
:: ping locahost -n 3 >nul

GOTO :startup

我希望我的批处理文件将以下内容记录到 destkop 文件中 其中 LOG_FILE = %Userprofile%\Desktop\LogFolder\LOG_FILE.txt

wmic csproduct get name >>%LOG_FILE%
wmic csproduct get UUID>>%LOG_FILE%

然后比较%LOG_FILE中的UUID日志是否与当前计算机的UUID相同 如果是这样,那么它应该验证计算机名称是否相同。

整体思路

@echo off

if wmic csproduct get UUID == "DAC2D186-1AB9-E111-A120-B888E34233CEE" (echo Done! ) else (  echo Not Done!) pause

【问题讨论】:

    标签: batch-file cmd


    【解决方案1】:

    使用for /f 循环来获取命令的输出:

    for /f "delims=" %%a in ('wmic csproduct get UUID^, name /format:list ^|find "="') do set "%%a"
    echo "%uuid%"
    echo "%name%"
    

    【讨论】:

      【解决方案2】:

      微软所说的未来是 PowerShell 和 CIM。我还没有找到包含 UUID 的 CIM 类,但这可以工作。

      FOR /F %%u IN ('powershell -NoLogo -NoProfile -Command "(Get-CimInstance -ClassName Win32_ComputerSystemProduct).UUID"') DO (SET "UUID=%%u")
      ECHO UUID is set to %UUID%
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-11
        • 1970-01-01
        • 2022-11-21
        • 1970-01-01
        相关资源
        最近更新 更多