Canalblog
Suivre ce blog Administration + Créer mon blog

Développeur fou

26 février 2008

JScript test 2

//==============================================================================
//         PS_LPad
//------------------------------------------------------------------------------
// Description     : Left fills the input string until a specified length
// Input        : szString        -> input string to pad
//                  szChar            -> character to add
//                  nLength            -> final length of the string
// Output        :    the lpadded string
//==============================================================================
function PS_LPad(szString, szChar, nLength)
{

  try
  {
        if (szChar.length > 0)
      {
        var szLength = szString.length;   
         szString += '';    // convert to string for sure
         var slen = szString.length;
         for (var i=0; i < nLength - slen; i++)
      {
        szString = szChar + szString;
         }
    }
  }
  catch (e)
  {
      // Handle exception
  }

  return szString;   
}

Publicité
Publicité
26 février 2008

Exemple C#

Test pour voir si l'affichage des catégories

26 février 2008

Récupérer l'utilisateur connecté

Le script ci-dessous permet de récupérer l'utilisateur ayant ouvert la session Windows

var wsh = new ActiveXObject("WScript.Shell");
wsh.popup("Current user is " + PS_GetUserName());

//==============================================================================
//         PS_GetUserName
//------------------------------------------------------------------------------ 
//    Description : Renvoie le nom de l'utilisateur connecté
//    Entrée            :
//    Sortie            :  Nom de l'utilisateur (vide si non trouvé)
//==============================================================================
function PS_GetUserName()
{
  var strUser = "";
  try
  { 
      var WshNetwork = new ActiveXObject("WScript.Network");
      strUser = WshNetwork.userName;
    }
  catch(e)
  {
    // Handle exception
  }
       
  return strUser;
}

Publicité
Publicité
Développeur fou
Publicité
Publicité