简体   繁体   English

如何制作将在cmd中运行多个查询并记录它们的批处理文件

[英]How to make a batch file that will run multiple queries in cmd and log them

I want to create a batch file that I can keep on a flash drive and take around to my users's machine's to determine their computer name and their Office 2013 License, I would then like the results to be pasted into a text file on the flash drive. 我想创建一个可以保存在闪存驱动器上的批处理文件,并转到用户计算机上以确定他们的计算机名称和Office 2013许可证,然后将结果粘贴到闪存驱动器上的文本文件中。

I know cscript "C:\\Program Files\\Microsoft Office\\Office15\\OSPP.VBS" /dstatus works to get the last 5 digits of the product key but I do not know how to create the batch file to query the computer name, nor how to have it paste this information into a text file. 我知道cscript "C:\\Program Files\\Microsoft Office\\Office15\\OSPP.VBS" /dstatus可以获取产品密钥的最后5位数字,但是我不知道如何创建批处理文件来查询计算机名称,如何将这些信息粘贴到文本文件中。 Is this even possible? 这有可能吗?

假设您的文本文件是DataCollected.csv,并假定它与批处理文件相邻,则有些提示[未测试]:

findstr /r "^%ComputerName%," "%~dp0DataCollected.csv" || for /f "delims=" %%a in ('cscript "C:\Program Files\Microsoft Office\Office15\OSPP.VBS" /dstatus') do echo %computername%,%%a>> "%~dp0DataCollected.csv"

Wow you hit the nail right on the head Parag! 哇,您在Parag的头上碰到了钉子! thanks 谢谢

Now to make it even more complicated, is there a way to null out the write feature if there is no office 2013 license, and instead have it look for 2010 should it fail to find 2013? 现在让它变得更加复杂,如果没有Office 2013许可证,是否有一种方法可以使写入功能无效,而如果找不到2013,则可以寻找2010?

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. Microsoft(R)Windows脚本主机版本5.8版权所有(C)Microsoft Corporation。 All rights reserved. 版权所有。 Input Error: Can not find script file "C:\\Program Files\\Microsoft Office\\Office15\\OSPP.VBS". 输入错误:找不到脚本文件“ C:\\ Program Files \\ Microsoft Office \\ Office15 \\ OSPP.VBS”。

is what it returns on machines without it. 是没有它的机器返回的东西。 if not, I can just edit that out in my DataCollected. 如果没有,我可以在DataCollected中进行编辑。

EDIT: This does print out the data, but it overwrites each time I rerun the batch file, almost there :) 编辑:这确实打印出数据,但每次我重新运行批处理文件时,它几乎都会覆盖它:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM