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

Configuration of webHttpBinding and wsDualHttpBinding

< ?xml version="1.0"?>
< configuration>
< system.serviceModel>
< serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
< behaviors>
< endpointBehaviors>
< behavior name="webHttpEnablingBehavior">
< webHttp />
< /behavior>
< /endpointBehaviors>
< serviceBehaviors>
< behavior name="webHttpEnablingBehavior">
< serviceMetadata httpGetEnabled="true"/>
< serviceDebug includeExceptionDetailInFaults="true" />
< /behavior>
< /serviceBehaviors>
< /behaviors>
< services>
< service name="WCFService" behaviorConfiguration="webHttpEnablingBehavior">
< endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
< endpoint address="" binding="webHttpBinding" bindingConfiguration="default" contract="IWCFService" behaviorConfiguration="webHttpEnablingBehavior" />
< endpoint address="MyOperation" binding="wsDualHttpBinding" bindingConfiguration="default" contract="IWCFService" />
< /service>
< /services>
< client />
< bindings>
< webHttpBinding>
< binding name="default" />
< /webHttpBinding>
< wsDualHttpBinding>
< binding name="default" />
< /wsDualHttpBinding>
< /bindings>
< /system.serviceModel>
< system.web>
< compilation debug="true"/>
< /system.web>
< /configuration>

Monday, May 24, 2010

Using CSS with Inline Images

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <style type="text/css"> .clip { position: absolute; top: 0; left: 0; } .pos-1 { clip:rect(0 48px 48px 0); } .pos-2 { clip:rect(0 96px 48px 48px); left: -48px; } .pos-3 { clip:rect(48px 48px 96px 0); top: -48px; } .pos-4 { clip:rect(48px 96px 96px 48px); top: -48px;left: -48px; } .clipwrapper { position: relative; height: 48px; width: 48px; } </style> <title></title> </head> <body> <div class="clipwrapper"> <img src="Images/arrow-sprite.png" alt="arrow" class="clip pos-1" /> </div> </body> </html>

Wednesday, May 5, 2010

SQL Server built in functions

1. First day of the week
select @@DateFirst output: 7 - Monday , 1 - Sunday
Set dateFirst 1
To see the permissions in the database.
select * from fn_my_permissions('null','database')
SELECT DISTINCT class_desc FROM fn_builtin_permissions(default) ORDER BY class_desc;
GO

Wednesday, April 7, 2010

Design patterns

One way is to call carpenter and let him take the measurements and then get you the door. --- factory method
Second way is to go to shop which sells doors and get the one which fits your requirements. --- abstract factory
Tracking a Session counter creates a single object - Singleton pattern

Wednesday, March 24, 2010

Using Server.Transfer

This is somewhat complex but sophisticated method of passing values  across pages. Here you expose the values you want to access in other  pages as  properties of the page class. This methods require you to code extra  properties that you can access in another web form. However, the efforts  are worth considering. Overall this method is much cleaner and object  oriented than earlier methods. The entire process works as follows:
  • Create the web form with controls
  • Create property Get procedures that will return control values
  • Provide some button or link button that posts the form back
  • In the button click event handler call Server.Transfer method that will transfer execution to the specified form
  • In the second form you can get a reference to the first form instance by using Context.Handler property. Then you will use the get properties we created to access the control values.
The code to accomplish this is somewhat complex and is shown below:
Source Web Form
Add following properties to the web form:
public string Name
{
get
{
return TextBox1.Text;
}
}

public string EMail
{
get
{
return TextBox2.Text;
}
}
Now, call Server.Transfer.
private void Button1_Click
(object sender, System.EventArgs e)
{
Server.Transfer("anotherwebform.aspx");
}
Destination Web Form
private void Page_Load
(object sender, System.EventArgs e)
{
//create instance of source web form
WebForm1 wf1;
//get reference to current handler instance
wf1=(WebForm1)Context.Handler;
Label1.Text=wf1.Name;
Label2.Text=wf1.EMail;
}

Fault Exception in WCF

calling the FaultException in Catch block

catch (Exception ex)

{

throw ex ;

// useful when FaultException attribute is mentioned in the web method called.

//with method declaration in interface.

////[FaultContract(typeof (MyFaultException))]

//MyFaultException myException = new MyFaultException();

//myException.Reason = "Reason for this error is : " + ex.Message.ToString();

}

Fault exception definition

// optional but a good practice.

[DataContract]

public class MyFaultException

{

private string _reason;

[DataMember]

public string Reason

{

get { return _reason; }

set { _reason = value; }

}

}

Thursday, March 18, 2010

How to Deploy and Test An SSIS Package

When working with SSIS, it is not immediately obvious how to deploy a package. Following are my short notes on deploying an SSIS package*.

Deploy the Package

  1. While in the Package designer, choose Project > [Package Name] Properties. The Configuration manager dialog will appear.
  2. Choose Deployment Utility from the tree.
  3. Change the CreateDeploymentUtility option from False to True. Note the DeploymentOutputPath variable. Push OK to close the dialog.
  4. Open the Solution Explorer and right-click on the .dtsx file and choose Properties. Copy the Full Path variable and use it to find the bin\Deployment folder.
  5. Locate the [Package Name].SSISDeploymentManifest file. Double-click on the file and follow the steps outlined by the wizard to deploy the package.

Test the deployed Package

  1. Open MSFT SQL Server Management Studio and choose Connect > Integration Services from the UI. Choose the Server and connect.
  2. The packages will be saved under the MSDB folder. Right-click on the package to run it.

---

* To re-deploy a package, follow steps 1-5 again.

Assigning a value to an ASP.Net CheckBox

Unlike the html checkbox, the ASP.Net CheckBox control does not have a value property. However, you can add attributes via markup as well as pragmatically via code. Markup:
<asp:checkbox id="CheckBox1" runat="server" value="'<%# Eval(" valuecolumn="">' /> <asp:checkbox id="CheckBox2" runat="server" value="'2'">
Only Eval can be used to bind to "custom" attributes, as compared to properties built into the control which also work with Bind Code:
CheckBox2.Attributes.Add("Value", 2);
The "Add" method add takes two parameters. The first parameter is the name of the attribute . The second parameter is the value for this attribute. This adds a server accessible attribute for the value, the attributes collection is maintained via the viewstate. However the CheckBox control does not render the value attributed (it actually removes the attribute during the render event phase. However, if you want to add the attribute so it is rendered via html then the checkbox has a property called InputAttributes, adding properties to this collection will always be rendered in the html. Code: CheckBox2.InputAttributes.Add("Value", 2);</asp:checkbox></asp:checkbox>

ASP.Net Trace stops showing up

I've noticed that when using asp.net 2.0 dev server that the trace would only show up on one or two pages. I decided to do some research into it and found out it has to do with the trace section of webconfig. There is a attribute called requestLimit whose limit was set to 20. After 20 requests the trace just stops showing up. 20 requests may not sound that bad but with the dev server all requests (including images and everything) go through the asp.net runtime so one page with my website would have 20 requests for other resources. I found out that there is another attribute called mostRecent which when set to true will discard older requests rather than stop working. I also didn't read the note in the webconfig about "you can view the application trace log by browsing the "trace.axd" page from your web application root".

Tuesday, February 16, 2010

Getting columns name from a table in Sql Server

SELECT syscolumns.name FROM sysobjects, syscolumns WHERE sysobjects.id = syscolumns.id and sysobjects.name='Profile'

Thursday, August 20, 2009

Finding the failed feature-id in MOSS 2007

List featIDs = new List();
foreach (SPFeatureDefinition featdef in SPFarm.Local.FeatureDefinitions)
{
try
{
//db5c27c4-6f17-4296-bc05-bbe9978284b4
if (featdef.DisplayName.Contains("manoj"))
{
Console.WriteLine("{0}: {1}", featdef.Id, featdef.DisplayName);
break;
}
}
catch
{
//This code will be executed if the feature does not have the manifest file.
Console.WriteLine("################################################");
Console.WriteLine("Error Ocurrred! Attempting to get feature ID of the feature without manifest file...:");
Console.WriteLine(featdef.Id.ToString());
}

Friday, August 14, 2009

Content Types and Workflows

  • Workflows can be associated with content Type
  • Workflow tasks are special content type(0x010801)
  • Content types can have special new, display and edit forms.
  • Therfore, the task edit page for a workflow task can be customized
  • Thursday, August 6, 2009

    Finding MAC address in VB.Net

    Imports System.Management
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim mc As System.Management.ManagementClass
    Dim mo As ManagementObject
    mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
    Dim moc As ManagementObjectCollection = mc.GetInstances()
    For Each mo In moc
    If mo.Item("IPEnabled") = True Then
    ListBox1.Items.Add("MAC address " & mo.Item("MacAddress").ToString())
    End If
    Next
    End Sub
    End Class