Wednesday, June 23, 2010

How to: Adding Uninstall start menu item to your .NET deployment project

Its pretty simple. Follow the steps to achieve this.

  • Add the following code snippet  to your projects main method before InitializeComponent();
    string[] arguments = Environment.GetCommandLineArgs();
    foreach (string argument in arguments)
    {
       string[] parameters = argument.Split('=');
       if (parameters[0].ToLower() == "/u")
       {
         string productCode = parameters[1];
         string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
         Process proc = new Process();
         proc.StartInfo.FileName = string.Concat(path, "\\msiexec.exe");
         proc.StartInfo.Arguments = string.Concat(" /i ", productCode);
         proc.Start();
       }
    }



    • Now go to your deployment project and go to the file system editor and right click on File System on Target Machine and Add Special Folder with name User's Programs Menu.


    • Add an additional shortcut to your primary output project and name it Uninstall.


    • Right Click  Shortcut to Set the Arguments property to /u=[ProductCode].


    • Now Build your Deployment setup project. Your are ready to go.


    Deployment project will replace [ProductCode] in the Arguments property with the actual installer project's ProductCode GUID value. Your program will see the /u={Actual ProductCode} argument and pass it to msiexec.exe. If you want the product to remove only, replace the "/i " with "/x ".

    Tuesday, June 22, 2010

    How to: Check whether SQL login exists?

    Try some thing like this.

    DECLARE @SqlStatement NVARCHAR(4000)
    DECLARE @loginName VARCHAR (100)
    SELECT @loginName = 'nagasai'
    IF NOT EXISTS (SELECT loginname FROM master.dbo.syslogins WHERE NAME = @loginName)
    BEGIN
    SET @SqlStatement = 'CREATE LOGIN [' + @loginName + '] WITH PASSWORD=N''angel83'',DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]'
    EXEC sp_executesql @SqlStatement
    END
    ELSE
    BEGIN
    PRINT 'login name ' + @loginName + ' already exists'
    END

    How to: Create login as sysadmin from T-SQL

    Here is the T-SQL code snippet that creates login with sysadmin permissions.

    CREATE LOGIN [nagasai] WITH PASSWORD=N'angel83', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
    GO
    EXEC master..sp_addsrvrolemember @loginame = N'nagasai', @rolename = N'sysadmin'

    Friday, June 18, 2010

    How do I debug a custom action/installer class?

    Here is how you can do debug custom action.  You can try using one of the following methods:

    • Add a call in your code to System.Diagnostics.Debugger.Launch. This method opens Just-In-Time debugging and enables you to attach a new debugger to your code.
    • Add a call in your code to MessageBox.Show("Debug Me"). When the message box is shown, use Visual Studio to attach to the MessageBox process. Then add breaks (for Visual C# projects) or stops (for Visual Basic projects) in the code.
    • Set your debugging preferences to start %windir%\Microsoft.net\Framework\version\InstallUtil.exe as an external program on the Debug Page of the Project Designer. The name of the custom action assembly is the command line arguments. When you press F5, you hit your breakpoint. InstallUtil.exe will run your custom actions just as MSI does.

    Life was difficult until i find this solution from MSDN.

    ASP.NET 4 Breaking Changes

    .Net Framework 4.0 comes up with some of major changes as compare to previous versions of .Net Framework 3.5 and 2.0
    Following are list of Major Changes in .Net 4.0

    • ControlRenderingCompatabilityVersion Setting in the Web.config File 
    • ClientIDMode Changes 
    • HtmlEncode and UrlEncode Now Encode Single Quotation Marks 
    • ASP.NET Page (.aspx) Parser is Stricter 
    • Browser Definition Files Updated 
    • System.Web.Mobile.dll Removed from Root Web Configuration File 
    • ASP.NET Request Validation 
    • Default Hashing Algorithm Is Now HMACSHA256 
    • Configuration Errors Related to New ASP.NET 4 Root Configuration 
    • ASP.NET 4 Child Applications Fail to Start When Under ASP.NET 2.0 or ASP.NET 3.5 Applications 
    • ASP.NET 4 Web Sites Fail to Start on Computers Where SharePoint Is Installed 
    • The HttpRequest.FilePath Property No Longer Includes PathInfo Values 
    • ASP.NET 2.0 Applications Might Generate HttpException Errors that Reference eurl.axd 
    • Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode Changes to the ASP.NET Code Access Security (CAS) Implementation 
    • MembershipUser and Other Types in the System.Web.Security Namespace Have Been Moved 
    • Output Caching Changes to Vary * HTTP Header 
    • System.Web.Security Types for Passport are Obsolete 
    • The MenuItem.PopOutImageUrl Property Fails to Render an Image in ASP.NET 4 
    • Menu.StaticPopOutImageUrl and Menu.DynamicPopOutImageUrl Fail to Render Images When Paths Contain Backslashes 

    Find detail information of ASP.NET 4 Breaking Changes