我想发布与特定 PC 绑定(bind)的 DM 脚本。 GMS 许可证不起作用,因为免费许可证具有通用许可证 ID,
"GATAN_FREE"
当脚本在不同的机器上运行时,如何插入密码以给出错误消息? 我正在考虑使用计算机名称或用户名。有没有办法读取Windows系统变量?如果使用
LaunchExternalProcessAsync(callString)
启动DOS命令“echo -username”,如何捕获输出? 有什么解决方案或建议吗?
最佳答案
不错的想法。
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)
关于dm-script - 如何使用DM脚本读取PC信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37582820/