What arguments needed to exec MSIscsiInitiator_TargetClass:Login?

534 views Asked by At

I trying to connect to iSCSI target via WMI (class WMI\MSIscsiInitiator_TargetClass, which is distributed with Microsoft software initiator), but always get a generic failure (80041001). Here is my code:

var mgmts = GetObject("winmgmts:\\\\.\\root\\WMI");
function login (path, login, passwd) {
    var portal = mgmts.Get("MSIscsiInitiator_Portal").SpawnInstance_(),
    target = mgmts.Get("MSIscsiInitiator_TargetClass"
              ).SpawnInstance_(),
    args = target.Methods_("Login").InParameters.SpawnInstance_(),
    options = mgmts.Get("MSIscsiInitiator_TargetLoginOptions"
               ).SpawnInstance_();

    target.TargetName = path;
    target.Put_();

    with ( portal ) {
        Address = '10.0.0.100';
        Port = 3260;
        Index = 1;
        SymbolicName = 'default';
        Put_();
    };

    args.TargetPortal = portal;
    args.IsPersistent = false;

    with ( options ) {
        HeaderDigest = 1; // CRC32C
        DataDigest = 1; // CRC32C
        AuthType = 1; // CHAP
        Username = login.split('');
        Password = passwd.split('');
        InformationSpecified = 0xE3; // 227 = 11100011 !! 0x67 = 1100111
        if ( ! ( login && passwd ) ) {
            AuthType = 0;
            // 0000011;
            InformationSpecified = InformationSpecified ^ 0x03;
        };
        DefaultTime2Retain = 0;
        DefaultTime2Wait = 0;
        LoginFlags = 10; // 1010
        MaximumConnections = 0;
        Version = 0;
    };

    args.LoginOptions = options;
    return target.ExecMethod_("Login", args); // <- this line fails
}

using like this:

login('iqn.2004-04.com.qnap:ts-859proplus:iscsi.test.c620aa',
      'test', 'verylongpassword');

What's wrong?

P.S: the same task with iscsicli.exe

var portal_parameter = '10.0.0.100 3260';

function login (path, login, passwd) {
    shell.run('iscsicli AddTargetPortal' +
          portal_parameter +
          ' * * * * * * * * * * * *',
          0, true);
    var auth = '1'; // CHAP
    if ( ! ( login && passwd ) ) {
        auth = '0'; // NO
        login = '*';
        passwd = '*';
    };

    shell.run('iscsicli LoginTarget ' +
          path + ' T ' + // PNP
          portal_parameter +
          ' * * * * 1 1 * * * ' +
          login + ' ' + passwd + ' ' + auth + ' * 0',
          0, true);
}

works (without result check), but I need WMI.

0

There are 0 answers