Pages

Thursday, January 17, 2013

Passing arguments from VBscript to the executable file and getting value from exe without openning the command box for exe

Create test.vbs file and put the below lines in it

Set oArgs = WScript.Arguments
If oArgs.Length = 0 Then
 WScript.Echo "Please provide arguments"
Else
 For Each sArg In oArgs
  REM WScript.Echo "Hello " & sArg
  s = s & sArg & " "
 Next
 WScript.Echo encryptdecrypt(s)
End If
Function encryptdecrypt(str)
 Set objShell = WScript.CreateObject("WScript.Shell")
 Set objExec = objShell.Exec("E:\encryptdecrypt.exe" &  "  " & str)
 line = objExec.StdOut.ReadAll
 encryptdecrypt=line
End Function


Execute script file on command prompt as
c:\>cscript e:\test.vbs e amit
c:\>cscript e:\test.vbs d 82VoUK9EyZpXVuSlNHvVmA==

Exe file in C#

class Program
{
 static void Main(string[] args)
 {
     if (args.Length == 0)
     {
  Console.WriteLine("Please provide arguments.");
  return; //no command line arg.
     }
     if (args.Length == 2)
     {
  try
  {
      string key = "YourKeyHere";
      if (args[0].Trim().ToLower() == "e")
      {
   string decryptedstring = EncryptDecryptClass.Encrypt(args[1].Trim(), key);
   Console.WriteLine(decryptedstring);
      }
      if (args[0].Trim().ToLower() == "d")
      {
   string decryptedstring = EncryptDecryptClass.Decrypt(args[1].Trim(), key);
   Console.WriteLine(decryptedstring);
      }
  }
  catch (Exception e)
  {
      Console.WriteLine(e.Message);
  }
     }          
 }
}


Execute exe file on command prompt as
C:/>E:\encryptdecrypt e helloworld

Tuesday, January 8, 2013

Display loading image during ajax data call


$(document).ready(function () {
    try {
        $("body").on({
            // When ajaxStart is fired, add 'loading' to body class
            ajaxStart: function () {
                $(this).addClass("loading");
            },
            // When ajaxStop is fired, rmeove 'loading' from body class
            ajaxStop: function () {
                $(this).removeClass("loading");
            }
        });
    } catch (e) {
        alert(e.Description);
        alert(error);
    }
});

/* Start by setting display:none to make this hidden.
   Then we position it in relation to the viewport window
   with position:fixed. Width, height, top and left speak
   speak for themselves. Background we set to 80% white with
   our animation centered, and no-repeating */
.modal
{
    display: none;
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
    background: #f9f9f9 url('images/loader.gif') 50% 50% no-repeat;
    opacity: .70;
    -ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity = 70);
    filter: Alpha(Opacity=70);
}

/* When the body has the loading class, we turn
   the scrollbar off with overflow:hidden */
body.loading
{
    overflow: hidden;
}

/* Anytime the body has the loading class, our
   modal element will be visible */
body.loading .modal
{
    display: block;
}