<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; WSH, JS: Базовая информация об ОС, процессах, программах]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=7154&amp;type=atom" />
	<updated>2012-04-26T17:41:18Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=7154</id>
		<entry>
			<title type="html"><![CDATA[WSH, JS: Базовая информация об ОС, процессах, программах]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=59760#p59760" />
			<content type="html"><![CDATA[<p>Указанный ниже код создает файл с информацией о<br />1. названии, версии и разрядности ОС<br />2. имени текущего пользователя<br />3. логических разделах дисков<br />4. запущенных процессах<br />5. установленных программах<br />6. модели ПК</p><div class="codebox"><pre><code>var FSO = fso = WScript.CreateObject(&quot;Scripting.FileSystemObject&quot;);
var WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;);

Enumerator.prototype.toArray = function ()
{
    var Result = [];
    for (;!this.atEnd();this.moveNext())
    Result.push(this.item())
    return Result;
}

function CreateTextFile(Path)
{
    Path = WshShell.ExpandEnvironmentStrings(Path);
    return fso.OpenTextFile(Path, 2, 1)
}

function isFile(Path)
{
    return fso.FileExists(Path);
}

function WMIQuery(Moniker, Query)
{
    var Service =  GetObject(Moniker),
    Items = Service.ExecQuery(Query);
    return new Enumerator(Items).toArray();
    return true;
}


function DetectWindowsVersion()
{
    var Windows = WMIQuery(&quot;winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2&quot;, &quot;Select * from Win32_OperatingSystem&quot; );
    var Processor = WMIQuery(&quot;winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2&quot;, &quot;Select * from Win32_Processor&quot; );
        return Windows[0].Caption+&quot;\t&quot;+Windows[0].Version+&quot;\t&quot;+Processor[0].AddressWidth+&quot;bit&quot;; 
}

function GetUserName()
{
    try{return &quot;CurrentUser\t&quot;+WScript.CreateObject(&quot;WScript.NetWork&quot;).UserName;}catch(e){return &quot;CurrentUser\tUnknown&quot;;}
}

function GetDrives()
{
    var D = (new Enumerator(FSO.Drives).toArray().toString().replace(/A:,/,&quot;&quot;).replace(/:/g,&quot;:\\&quot;).split(&quot;,&quot;));
    var Drives=[];
    for (var i=0; i&lt;D.length; i++)
    {
        try {
            if (FSO.GetDrive(D[i]).IsReady) Drives.push(D[i]);
        } catch (e) {}
    }
    return Drives;
}

function GetDrivesInformation()
{
    var Drives = GetDrives(), Drive, Result=[&quot;\r\nDRIVES&quot;];
    for (var i=0; i&lt;Drives.length; i++)
    {
        Drive = FSO.GetDrive(Drives[i]);
        Result.push(
        [
        &quot;============================&quot;,
        &quot;Drive.DriveLetter: &quot;+Drive.DriveLetter,
        &quot;Drive.VolumeName: &quot;+Drive.VolumeName,
        &quot;Drive.DriveType: &quot;+Drive.DriveType,
        &quot;Drive.FileSystem: &quot;+Drive.FileSystem,
        &quot;Drive.TotalSize: &quot;+Drive.TotalSize,
        &quot;Drive.AvailableSpace: &quot;+Drive.AvailableSpace
        ].join(&quot;\r\n&quot;)
        );
    }
    Result.push(&quot;============================&quot;)
    return Result.join(&quot;\r\n&quot;);
}

function GetProcessInformation()
{
    var Ar = WMIQuery(&quot;winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\CIMV2&quot;, &quot;SELECT * FROM Win32_Process&quot;);
    var Result=[];
    
    for (var i=0;i&lt;Ar.length; i++)
    Result.push(Ar[i].Name +&quot;\t&quot;+ Ar[i].CommandLine);
    
    Result=Result.sort();
    Result.push(&quot;============================&quot;);
    Result.unshift(&quot;\r\nPROCESSES&quot;, &quot;============================&quot;);
    return Result.join(&quot;\r\n&quot;);
}

function GetComputerInformation()
{
        function WMIDateStringToDate(dtmDate)
    {
    if (dtmDate == null)
    {
    return &quot;null date&quot;;
    }
    var strDateTime;
    if (dtmDate.substr(4, 1) == 0)
    {
    strDateTime = dtmDate.substr(5, 1) + &quot;/&quot;;
    }
    else
    {
    strDateTime = dtmDate.substr(4, 2) + &quot;/&quot;;
    }
    if (dtmDate.substr(6, 1) == 0)
    {
    strDateTime = strDateTime + dtmDate.substr(7, 1) + &quot;/&quot;;
    }
    else
    {
    strDateTime = strDateTime + dtmDate.substr(6, 2) + &quot;/&quot;;
    }
    strDateTime = strDateTime + dtmDate.substr(0, 4) + &quot; &quot; +
    dtmDate.substr(8, 2) + &quot;:&quot; +
    dtmDate.substr(10, 2) + &quot;:&quot; +
    dtmDate.substr(12, 2);
    return(strDateTime);
    }

    var Result=[];

    var wbemFlagReturnImmediately = 0x10;
    var wbemFlagForwardOnly = 0x20;

        var objWMIService = GetObject(&quot;winmgmts:\\\\.\\root\\CIMV2&quot;);
        var colItems = objWMIService.ExecQuery(&quot;SELECT * FROM Win32_SystemEnclosure&quot;, &quot;WQL&quot;,
        wbemFlagReturnImmediately | wbemFlagForwardOnly);

        var enumItems = new Enumerator(colItems);
        for (; !enumItems.atEnd(); enumItems.moveNext()) {
        var objItem = enumItems.item();

        if (objItem.AudibleAlarm) Result.push(&quot;AudibleAlarm: &quot; + objItem.AudibleAlarm);
        if (objItem.BreachDescription) Result.push(&quot;BreachDescription: &quot; + objItem.BreachDescription);
        if (objItem.CableManagementStrategy) Result.push(&quot;CableManagementStrategy: &quot; + objItem.CableManagementStrategy);
        if (objItem.Caption) Result.push(&quot;Caption: &quot; + objItem.Caption);
        try {Result.push(&quot;ChassisTypes: &quot; + (objItem.ChassisTypes.toArray()).join(&quot;,&quot;)); }
        catch(e) {}
        if (objItem.CreationClassName) Result.push(&quot;CreationClassName: &quot; + objItem.CreationClassName);
        if (objItem.CurrentRequiredOrProduced) Result.push(&quot;CurrentRequiredOrProduced: &quot; + objItem.CurrentRequiredOrProduced);
        if (objItem.Depth) Result.push(&quot;Depth: &quot; + objItem.Depth);
        if (objItem.Description) Result.push(&quot;Description: &quot; + objItem.Description);
        if (objItem.HeatGeneration) Result.push(&quot;HeatGeneration: &quot; + objItem.HeatGeneration);
        if (objItem.Height) Result.push(&quot;Height: &quot; + objItem.Height);
        if (objItem.HotSwappable) Result.push(&quot;HotSwappable: &quot; + objItem.HotSwappable);
        Result.push(&quot;InstallDate: &quot; + WMIDateStringToDate(objItem.InstallDate));
        if (objItem.LockPresent) Result.push(&quot;LockPresent: &quot; + objItem.LockPresent);
        if (objItem.Manufacturer) Result.push(&quot;Manufacturer: &quot; + objItem.Manufacturer);
        if (objItem.Model) Result.push(&quot;Model: &quot; + objItem.Model);
        if (objItem.Name) Result.push(&quot;Name: &quot; + objItem.Name);
        if (objItem.NumberOfPowerCords) Result.push(&quot;NumberOfPowerCords: &quot; + objItem.NumberOfPowerCords);
        if (objItem.OtherIdentifyingInfo) Result.push(&quot;OtherIdentifyingInfo: &quot; + objItem.OtherIdentifyingInfo);
        if (objItem.PartNumber) Result.push(&quot;PartNumber: &quot; + objItem.PartNumber);
        if (objItem.PoweredOn) Result.push(&quot;PoweredOn: &quot; + objItem.PoweredOn);
        if (objItem.Removable) Result.push(&quot;Removable: &quot; + objItem.Removable);
        if (objItem.Replaceable) Result.push(&quot;Replaceable: &quot; + objItem.Replaceable);
        if (objItem.SecurityBreach) Result.push(&quot;SecurityBreach: &quot; + objItem.SecurityBreach);
        if (objItem.SecurityStatus) Result.push(&quot;SecurityStatus: &quot; + objItem.SecurityStatus);
        if (objItem.SerialNumber) Result.push(&quot;SerialNumber: &quot; + objItem.SerialNumber);
        try {Result.push(&quot;ServiceDescriptions: &quot; + (objItem.ServiceDescriptions.toArray()).join(&quot;,&quot;)); }
        catch(e) {}
        try {Result.push(&quot;ServicePhilosophy: &quot; + (objItem.ServicePhilosophy.toArray()).join(&quot;,&quot;)); }
        catch(e) {}
        if (objItem.SKU) Result.push(&quot;SKU: &quot; + objItem.SKU);
        if (objItem.SMBIOSAssetTag) Result.push(&quot;SMBIOSAssetTag: &quot; + objItem.SMBIOSAssetTag);
        if (objItem.Status) Result.push(&quot;Status: &quot; + objItem.Status);
        if (objItem.Tag) Result.push(&quot;Tag: &quot; + objItem.Tag);
        try {Result.push(&quot;TypeDescriptions: &quot; + (objItem.TypeDescriptions.toArray()).join(&quot;,&quot;)); }
        catch(e) {}
        if (objItem.Version) Result.push(&quot;Version: &quot; + objItem.Version);
        if (objItem.VisibleAlarm) Result.push(&quot;VisibleAlarm: &quot; + objItem.VisibleAlarm);
        if (objItem.Weight) Result.push(&quot;Weight: &quot; + objItem.Weight);
        if (objItem.Width) Result.push(&quot;Width: &quot; + objItem.Width);
        }

    Result.push(&quot;============================&quot;)
    Result.unshift(&quot;\r\nCOMPUTER INFO\r\n============================&quot; );
    return Result.join(&quot;\r\n&quot;);
}

function ExportAddRemoveProgramsDataToFile(FilePath)
{
    var Postfix =  /Windows 7/i.test(DetectWindowsVersion())?&quot; /y&quot;:&quot;&quot;;
    FilePath = FilePath || &quot;%TMP%\\~SDPASDSDPROGSQW.tmp&quot;;
    var e, Command = &#039;REG EXPORT &quot;HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall&quot; &quot;&#039;+FilePath+&#039;&quot;&#039;+Postfix;
    try {WshShell.Run(Command,0,1);} catch (e) {};
    
//    Echo(Command);
    return WshShell.ExpandEnvironmentStrings(FilePath);
}

function GetInstalledProgramsInformation()
{
    var Result=[];
    
    function c(r, r1)
    {
        Result.push(r1);
    }
    
    var ADODBStream = WScript.CreateObject(&quot;ADODB.Stream&quot;);
    ADODBStream.Type = 2;
    ADODBStream.Charset =  &quot;UTF-16LE&quot;;
    ADODBStream.Open();
    ADODBStream.LoadFromFile(ExportAddRemoveProgramsDataToFile());
    var Data = ADODBStream.ReadText();
    WScript.Echo(Data);
    Data.replace(/&quot;DisplayName&quot;=&quot;([^&quot;]+)&quot;/gi, c);
    
    
    Result = Result.sort();
    Result.push(&quot;============================&quot;)
    Result.unshift(&quot;\r\nINSTALLED PROGRAMS:&quot;,&quot;============================&quot;);

    return Result.join(&quot;\r\n&quot;);
}

var TextFileName = &quot;%TMP%\\Info.txt&quot;;

var Text = CreateTextFile(TextFileName);
Text.WriteLine(DetectWindowsVersion());
Text.WriteLine(GetUserName());
Text.WriteLine(GetDrivesInformation());
Text.WriteLine(GetProcessInformation());
Text.WriteLine(GetComputerInformation());
Text.WriteLine(GetInstalledProgramsInformation());
Text.Close();

WshShell.Run(&quot;notepad %TMP%\\info.txt&quot;, 1, 1);

TextFileName = WshShell.ExpandEnvironmentStrings(TextFileName);
FSO.GetFile(TextFileName).Delete(true);</code></pre></div>]]></content>
			<author>
				<name><![CDATA[JSmаn]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24434</uri>
			</author>
			<updated>2012-04-26T17:41:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=59760#p59760</id>
		</entry>
</feed>
