1

我想发布一个绑定到特定 PC 的 DM 脚本。GMS 许可证不起作用,因为免费许可证具有通用许可证 ID,

"GATAN_FREE"

当脚本在另一台机器上运行时,如何插入密码以提供错误消息?我正在考虑使用计算机名称或用户名。有没有办法读取 Windows 系统变量?如果使用

LaunchExternalProcessAsync(callString)

启动 DOS 命令“echo -username”,如何捕捉输出?有什么解决方案或建议吗?

4

2 回答 2

0

不错的想法。诀窍LaunchExternalProcess是创建一些可以“执行”的有用字符串。您可以使用自己的命令行参数尝试各种应用程序。


在最一般的情况下,您可以创建一个虚拟批处理文件并执行它。(前提是您在计算机上具有读/写权限!)

由于LaunchExternalProcess还从启动的进程返回退出代码,您至少可以直接传回一个整数变量。否则,您需要将批处理文件保存到文件中并让 DM 读取该文件。

// Temporary batch file creation
    string batchPath = "C:\\Dummy.bat"
    string batchText

    string auxFilePath = "C:\\tmp_dummy.txt"
    batchText += "dir *.* >> " + auxFilePath + "\n"
    batchText += "exit 999" + "\n"

// Ensure no files exist...
    if ( DoesFileExist(auxFilePath) )
        DeleteFile(auxFilePath)

    if ( DoesFileExist(batchPath) )
        DeleteFile(batchPath)

// Write the batch file....
    number fileID = CreateFileForWriting(batchPath)
    WriteFile(fileID,batchText)
    CloseFile(fileID)

// Call the batch file and retrieve its exit code
    number kTimeOutSec = 5      // Prevent freezing of DM if something in the batch file is wrong
    number exitCode = LaunchExternalProcess( batchPath, kTimeOutSec ) 

// Do something with the results
    Result( "\n Exit value of batch was:" + exitCode )
    if ( DoesFileExist(auxFilePath) )
    {
        string line
        fileID = OpenFileForReading(auxFilePath)
        ReadFileLine( fileID, line )
        CloseFile(fileID)
        Result("\n First line of auxiliary file:" + line )
    }

// Ensure no files exist...
    if ( DoesFileExist(auxFilePath) )
        DeleteFile(auxFilePath)

    if ( DoesFileExist(batchPath) )
        DeleteFile(batchPath)
于 2016-06-02T08:59:59.277 回答
0

这不是对您的问题的直接回答,而是对您提到的总体目标的回答。

限制脚本访问的另一种“仅限 DM”解决方案是使用应用程序本身的持久标签!(这些存储在应用程序的首选项中。)


string tagPath = "MyScripts:LicensedComputer"
string installPW = "password"                   

string mayLoadPassCode = ""
GetPersistentStringNote( tagPath, mayLoadPassCode )
if ( mayLoadPassCode != installPW )
{
    string pw
    if ( !GetString( "Forbidden.\n Enter password:", pw, pw ) )
        exit(0)

    if ( pw != installPW )
        Throw( "Invalid password." )

    SetPersistentStringNote( tagPath, pw )  
}

OKDialog( "You may use my script..." )

显然这不是最安全的锁定,因为任何用户也可以手动设置标签,但只要标签路径是“秘密”并且密码保持“秘密”(即您不共享源代码中的脚本)它是合理的“保存”。

以类似的方式,您可以让您的脚本将特定的“许可证”文件写入计算机并每次检查。优点是,删除/重置 DM 首选项文件不会对此产生影响。

于 2016-06-02T09:12:30.170 回答