Sunday, August 15, 2021

(Automation) BAT file: Clearing cookies, cache of the browsers and all the temporary file


erase "%TEMP%\*.*" /f /s /q

for /D %%i in (“%TEMP%\*”) do RD /S /Q "%%i"


erase "%TMP%\*.*" /f /s /q

for /D %%i in (“%TMP%\*”) do RD /S /Q “%%i”


erase “%ALLUSERSPROFILE%\TEMP\*.*” /f /s /q

for /D %%i in (“%ALLUSERSPROFILE%\TEMP\*”) do RD /S /Q “%%i”


erase “%SystemRoot%\TEMP\*.*” /f /s /q

for /D %%i in (“%SystemRoot%\TEMP\*”) do RD /S /Q “%%i”


@rem Clear IE cache – (Deletes Temporary Internet Files Only)

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

@rem (Deletes ALL History)

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

@rem (Deletes History Only)

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

@rem (Deletes Cookies Only)

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

@rem (Deletes Form Data Only)

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16 (Deletes Form Data Only)

@rem (Deletes Password History Only)

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32 (Deletes Password History Only)

@rem (Deletes All)

rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351

set DataDir=C:\Users\%USERNAME%\AppData\Local\Microsoft\Intern~1

del /q /s /f “%DataDir%”

rd /s /q “%DataDir%”

set History=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\History

del /q /s /f “%History%”

rd /s /q “%History%”

set IETemp=C:\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Tempor~1

del /q /s /f “%IETemp%”

rd /s /q “%IETemp%”

set Cookies=C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Cookies

del /q /s /f “%Cookies%”

rd /s /q “%Cookies%”

erase “%LOCALAPPDATA%\Microsoft\Windows\Tempor~1\*.*” /f /s /q

for /D %%i in (“%LOCALAPPDATA%\Microsoft\Windows\Tempor~1\*”) do RD /S /Q “%%i”


@rem Clear Google Chrome cache

erase “%LOCALAPPDATA%\Google\Chrome\User Data\*.*” /f /s /q

for /D %%i in (“%LOCALAPPDATA%\Google\Chrome\User Data\*”) do RD /S /Q “%%i”


@rem Clear Firefox cache

erase “%LOCALAPPDATA%\Mozilla\Firefox\Profiles\*.*” /f /s /q

for /D %%i in (“%LOCALAPPDATA%\Mozilla\Firefox\Profiles\*”) do RD /S /Q “%%i”



Sunday, February 17, 2013

Finding JRE Version using VBScript

Code Snippet
Set wshShell = WScript.CreateObject("WSCript.shell")
If Err.Number <> 0 Then
Wscript.Quit  
End If
return=WshShell.Run("%comspec%  java -version" ,0,false)  
return = WshShell.Run("%comspec% /c for /f ""tokens=3"" %g in ('java -version 2^>^&1 ^| findstr /i ""version""') do ( @echo %~g ) > %TEMP%\output.txt", 0, true) {
Set oShell = WScript.CreateObject("WScript.Shell")
filename = oShell.ExpandEnvironmentStrings("%TEMP%\output.txt") 
Set objFileSystem = CreateObject("Scripting.fileSystemObject") 
Set oFile = objFileSystem.OpenTextFile(filename, 1) 
text = oFile.ReadAll 
oFile.Close 
msgbox text 

Sunday, March 4, 2012

DateTime TryParse() and ParseExact() Methods

Most of us have dealt with using DateTime.Parse() for these tasks, but sometimes you are wanting to parse something that may not be a valid DateTime, or may be in a non-standard format. So let’s look at the TryParse() and ParseExact() methods that can
TryParse() – When your string may not be in a valid format
   2: var dt1 = DateTime.Parse("");
   3:  
   4: // throws FormatException, February doesn’t have a 30th day
   5: var dt2 = DateTime.Parse("02/30/2010 12:35");
   6:  
   7: // succeeds
   8: var dt3 = DateTime.Parse("01/11/1984 13:00");

This is pretty much what you’d expect for many situations, but what if you are processing a file or user input that has a fairly high chance of having an invalid value, what would we do?

Well, obviously, we could just handle the exception and use that to decide how to proceed. For example, if anytime we can’t parse a date we want to assume the current date and time, we could do:

   1: string input = "02/30/2010 12:35";
   2: DateTime recordDate;
   3:  
   4: // let's say we want to parse the date, but if we can't, then we'll assume now...
   5: try
   6: {
   7:     recordDate = DateTime.Parse(input);
   8: }
   9: catch (Exception)
  10: {
  11:     recordDate = DateTime.Now;
  12: }

This works, obviously, but the try/catch block eats up a lot of vertical space, and it incurs the cost of throwing an exception if an error is encountered. When there is a chance that the input is invalid, and you want to handle that invalid situation instead of just bubbling up an exception, consider TryParse() instead.

The TryParse() methods have much the same signature as Parse(), except that they take a final out parameter of DateTime where the value is placed (if successful), and return a bool that indicates if the parse was successful or not. Thus, the code above could be rewritten as:

   1: string input = "02/30/2010 12:35";
   2: DateTime recordDate;
   3:  
   4: // let's say we want to parse the date, but if we can't, then we'll assume now...
   5: if(!DateTime.TryParse(input, out recordDate))
   6: {
   7:     recordDate = DateTime.Now;
   8: }

Notice that the code is much more concise without the try/catch, this way, we can attempt the parse, and if all is well the result will be in our recordDate variable, and if not we go into the body of the if (since TryParse() returns false on an error, and we negate the result) and we can then assign a “default” value for recordDate.

It should be noted that Parse() actually calls TryParse() and just throws the exception in the event TryParse() returns false. That is, Parse() is roughly equivalent to:

   1: // rough psuedo-code of Parse()
   2: public DateTime Parse(string inputString)
   3: {
   4:     DateTime result;
   5:  
   6:     if (!DateTime.TryParse(inputString, out result))
   7:     {
   8:         throw new FormatException(...);
   9:     }
  10:  
  11:     return result;
  12: }

So calling TryParse() directly is more efficient because it avoids the wrapper call, and it doesn’t allocate and throw an unneeded exception in the case of an error.

So let’s time the two methods above on bad data and see what we get over 1,000,000 iterations:

   1: TryParse() took: 610 ms, 0.00061 ms/item.
   2: Parse() took: 26645 ms, 0.026645 ms/item.

To be fair, these are time differences for 1 million bad items, when you parse good items the times of the two methods perform identically, but if you have a good chance of receiving a badly formatted string and want to directly handle it, then using TryParse() is more efficient.

ParseExact() – When your string is in a non-standard format

What if you were reading data from a file, and the DateTime contained in it was a non-standard format. For example, let’s say we’re parsing a log file that begins with a timestamp that is a date in the format yyyyMMdd HHmmss (like 20111231 031505 for 12/31/2011 03:15:05 AM).

If we attempt to do a DateTime Parse() or TryParse() on this, we will get a failure because it is not one of the standard formats that DateTime’s parsing mechanisms understand.

   1: string logString = "20111231 031505";
   2: DateTime logEntryTime;
   3:  
   4: try
   5: {
   6:     logEntryTime = DateTime.Parse(logString);
   7: }
   8: catch (Exception ex)
   9: {
  10:     // the above will throw
  11:     Console.WriteLine("Didn't understand that DateTime.");
  12: }

What we can do in this situation is to call ParseExact() and tell it the exact format we are expecting. We do this by specifying a standard format string or custom format string (much the same as you’d pass to DateTime.ToString() to modify it’s output if you don’t like the default output format).

   1: // Note: MM is months, mm is minutes, see MSDN for details
   2: logEntryTime = DateTime.ParseExact(logString, "yyyyMMdd HHmmss", null);
   3:  
   4: // outputs: 12/31/2011 3:15:05 AM
   5: Console.WriteLine(logEntryTime);

Note that when using the custom format strings, the case and quantity of the format specifiers can matter. For example, “MM” is months and “mm” is minutes, “HH” is 24-hour format and “hh” is 12-hour format, “mm” is zero-padded where “m” is not, etc. For further details see the MSDN.

Also notice that in the snippet above we passed a null for the IFormatProvider. Doing this uses the current culture’s DateTime format provider. If you want to use the invariant culture’s instead you can specify it manually:

   1: // these two are identical (current culture)
   2: logEntryTime = DateTime.ParseExact(logString, "yyyyMMdd hhmmss", null);
   3: logEntryTime = DateTime.ParseExact(logString, "yyyyMMdd hhmmss", DateTimeFormatInfo.CurrentInfo);
   4:  
   5: // this one is invariant
   6: logEntryTime = DateTime.ParseExact(logString, "yyyyMMdd hhmmss", DateTimeFormatInfo.InvariantInfo);

So this will help you parse non-standard formats, but in addition to handling invalid formats, ParseExact() is also useful if you want to only accept one format as valid (even if it’s a standard format). This is because you are telling it the explicit format you want to accept, and it doesn’t need to try several formats to see which one works – it only tries the single format specified.

For example, let’s compare doing 1,000,000 iterations of the two pieces of code below:

   1: string logString = "12/31/2011";
   2: DateTime logEntryTime;
   3:  
   4: // Both work, but ParseExact() wants an explicit format
   5: logEntryTime = DateTime.Parse(logString);
   6: logEntryTime = DateTime.ParseExact(logString, "MM/dd/yyyy", null);

If we test both of these, we see that ParseExact() is more efficient:

   1: Parse() took: 700 ms, 0.0007 ms/item.
   2: ParseExact() took: 494 ms, 0.000494 ms/item.

So, if you know the exact format that the date time representation should be, ParseExact() is more efficient. In addition, it will only accept that format, so you can use ParseExact() to narrow the parse behavior to only accept a single format.

Finally, it should be noted that just like Parse(), ParseExact() has a TryParseExact() that returns a bool instead of throwing if the input string is not in the expected format.

Summary

The DateTime struct has a lot of methods for parsing a string into a DateTime. Most everyone has used the Parse() method, but the cost of the exception throws on an error can become a performance bottleneck if improperly formatted input is possible.

Thus, use TryParse() when you want to be able to attempt a parse and handle invalid data immediately (instead of bubbling up the exception), and ParseExact() when the format you are expecting is not a standard format, or when you want to limit to one particular standard format for efficiency.

Sunday, January 15, 2012

Factory pattern

Please find below link to explain about design patterns in .Net http://www.codeproject.com/KB/aspnet/SoftArchInter1.aspx

Monday, January 24, 2011

Drop down in XSLT

ADJUSTMENT (CREDIT) CORRECTION ERROR ERROR OFFSET (CREDIT) SPECIAL FEES LEVIED OTHER

Thursday, July 29, 2010

WCF Client Sample code

static void Main(string[] args)
{
using (WCFServiceClient client = new WCFServiceClient("WSDualHttpBinding_IWCFService"))
{
string output = client.MyOperation1("Manoj");
Console.WriteLine(output);
DataContract1 dc = new DataContract1();
dc.FirstName = "Shankar";
dc.LastName = "Mahadevan";
output = client.MyOperation2(dc);
Console.WriteLine(output);
Console.ReadLine();
}

Configuration of WCF in Host

Service.cs
[OperationContract]
[System.ServiceModel.Web.WebGet(UriTemplate = "/MyOperation/MyOperation1/{myValue1}", ResponseFormat = System.ServiceModel.Web.WebMessageFormat.Json, BodyStyle = System.ServiceModel.Web.WebMessageBodyStyle.WrappedResponse)]

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, IncludeExceptionDetailInFaults = true)]

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

Generating a proxy for the client
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:2409/WCF_Host/Service.svc