|
★☆☆☆☆☆☆☆☆☆ |
积分:285 |
发帖:317 |
登录:2024/3/26 |
注册:2006/6/28 |
|
(1楼)【原创】一段利用WSH获取系统信息的代码
另存为OsInfo.jse或者OsInfo.js,双击即可运行。 var WMI = GetObject("WinMgmts://127.0.0.1");
/* 用于远程调用
var objRmt = new ActiveXObject("WbemScripting.SWbemLocator");
WMI = objRmt.ConnectServer("www.fengyun.org", "", "Administrator", "");
//*/
var arrOS = new Array;
/* 查询系统信息 */
var sql = "select * from Win32_OperatingSystem";
GetInfo(sql, function(obj)
{
var arrTmp = ["系统"];
arrTmp.push("计算机名:" + obj.CSName);
arrTmp.push("操作系统:" + obj.Caption + "(" + obj.CSDVersion + ")");
arrTmp.push("安装时间:" + ParseTime(obj.InstallDate));
arrTmp.push("启动时间:" + ParseTime(obj.LastBootUpTime));
return arrTmp;
});
sql = "select * from Win32_BIOS";
GetInfo(sql, function(obj)
{
var arrTmp = ["BIOS"];
arrTmp.push("名 称:" + obj.Name);
arrTmp.push("版 本:" + obj.Version);
arrTmp.push("发布日期:" + ParseTime(obj.ReleaseDate));
return arrTmp;
});
sql = "select * from Win32_Processor";
GetInfo(sql, function(obj)
{
var arrTmp = ["中央处理器"];
arrTmp.push("设备标示:" + obj.DeviceID);
arrTmp.push("名 称:" + obj.Name);
arrTmp.push("说 明:" + obj.Description);
arrTmp.push("版 本:" + obj.Version);
arrTmp.push("工作频率:" + ParseSpeed(obj.CurrentClockSpeed));
return arrTmp;
});
sql = "select * from Win32_PhysicalMemory";
GetMemInfo(sql);
sql = "select * from Win32_LogicalDisk where DriveType=3";
GetDiskInfo(sql);
sql = "select * from Win32_VideoController";
GetInfo(sql, function(obj)
{
var arrTmp = ["显卡"];
arrTmp.push("芯片类型:" + obj.VideoProcessor);
arrTmp.push("制造厂商:" + obj.AdapterCompatibility);
arrTmp.push("显存大小:" + ParseMemory(obj.AdapterRAM));
return arrTmp;
});
WSH.Echo(arrOS.join("\r\n\r\n"));
function GetInfo(sql, func)
{
var enmObj = new Enumerator(WMI.ExecQuery(sql));
while(!enmObj.atEnd())
{
arrOS.push(func(enmObj.item()).join("\r\n"));
enmObj.moveNext();
}
}
function ParseTime(strTime)
{
return strTime.replace(/(.{4})(.{2})(.{2})(.{2})(.{2})(.{2}).*/, "$1-$2-$3 $4:$5:$6");
}
function ParseSpeed(speed)
{
if(speed < 1000) return speed + " MHz";
return (speed / 1000) + " GHz";
}
function GetMemInfo(sql)
{
var totalSize = 0;
var enmObj = new Enumerator(WMI.ExecQuery(sql));
while(!enmObj.atEnd())
{
totalSize -= -enmObj.item().Capacity;
enmObj.moveNext();
}
var arrTmp = ["物理内存(总共 " + ParseMemory(totalSize) + ")"];
enmObj.moveFirst();
while(!enmObj.atEnd())
{
var obj = enmObj.item();
arrTmp.push(obj.Tag + ": " + ParseMemory(obj.Capacity));
enmObj.moveNext();
}
arrOS.push(arrTmp.join("\r\n"));
}
function ParseMemory(size)
{
var i = 0, arrExt = ["字节", "KB", "MB", "GB", "TB"];
while(true)
{
if(size < 1024) return size.toFixed(2).replace(/\.00$/, "") + " " + arrExt[ i ];
size /= 1024;
i++;
}
}
function GetDiskInfo(sql)
{
var totalSize = 0;
var enmObj = new Enumerator(WMI.ExecQuery(sql));
while(!enmObj.atEnd())
{
totalSize -= -enmObj.item().Size;
enmObj.moveNext();
}
var arrTmp = ["本地硬盘(总共 " + ParseMemory(totalSize) + ")"];
enmObj.moveFirst();
while(!enmObj.atEnd())
{
var obj = enmObj.item();
arrTmp.push(obj.Name + "(" + obj.FileSystem + "): 总共 " + ParseMemory(obj.Size) + "," + ParseMemory(obj.FreeSpace) + " 可用。");
enmObj.moveNext();
}
arrOS.push(arrTmp.join("\r\n"));
}
|