6 июн. 2010 г.

JScript: How to get AllUsers AppData directory

var osXP = 0;
var osVista = 1;
var osWin7 = 2;

function getOsVersionString()
{
    var wbemFlagReturnImmediately = 0x10;
    var wbemFlagForwardOnly = 0x20;
    var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
    var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
    
    var enumItems = new Enumerator(colItems);
    var objItem = enumItems.item();
    
    return objItem.Caption;
}

function getOsVersion()
{
    var osVersionString = getOsVersionString();

    if (osVersionString.indexOf("Windows Vista") != -1)
    {
        return osVista;
    }

    if (osVersionString.indexOf("Windows 7") != -1)
    {
        return osWin7;
    }

    return osXP;
}

function getAllUsersAppData()
{
    var result;
    
    var wsShell = new ActiveXObject("WScript.Shell");
    result = wsShell.ExpandEnvironmentStrings("%ALLUSERSPROFILE%");
    
    try
    {
        var osVersion = getOsVersion();
        
        if (osVersion == osXP)
            result += "\\Application Data";
    }
    catch(err)
    {
    }

    return result;
}

Комментариев нет:

Отправить комментарий