Thursday, February 28, 2008

How to stop Windows Update nagging you to restart after an update

How to stop Windows Update nagging you to restart after an update

After Windows Automatic Updates has downloaded updates to your computer, it may display a dialog that says: "Updating your computer is almost complete. You must restart your computer for the updates to take effect. Do you want to restart your computer now?" If you click "Restart Later", the dialog will appear again after 10 minutes, which is very annoying if you are busy and consider that your computer should not put its needs above your own.
Solution

Windows may need to be restarted after an update has occurred, in order to allow files that are in use to be replaced. If you would prefer to restart the computer at your convenience, and not be nagged to do so, try one of the following solutions:

Method 1

* Click Start, Run and enter the command net stop wuauserv

This will stop the Windows Update service until the next restart of the computer, which will stop the reminders to restart your computer for this update.

Method 2

If you are running Windows XP Professional, the following steps will increase the period between restart reminders to the maximum possible.

* Click Start, Run and enter the command gpedit.msc
* Select Local Computer Policy, Computer Configuration, Administrative Templates, Windows Components, Windows Update
* Double-click Re-prompt for restart with scheduled installations
* Change the value to 1440
* Close the Group Policy Editor
* Click Start, Run and enter the command gpupdate /force

This will stop the repeated reminders for this and all future Windows updates.

If you have Windows XP Home instead of Windows XP Pro, you will probably get the following message:

Windows cannot find 'gpedit.msc'. Make sure you typed the name correctly, and then try again. To search for a file, click the Start button, and then click Search.

GPEDIT doesn't exist on Windows XP Home edition, since it's for Group Policy, a Windows XP Pro feature. However, you can set the key in the group policy area of your registry. Google for the links, or just download and double-click on the .reg file mentioned in this post: http://computer-vet.com/weblog/2005/05/20/windows_automatic_reboots.html

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
DWORD value "NoAutoRebootWithLoggedOnUsers" set to 1.

Monday, February 4, 2008

Using Microsoft Excel within your ASP.NET application

If you add a reference to Microsoft Excel and then try to use it within your ASP.NET application you may receive the following error.

Server Error in '/excel' Application.


Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.

Example Application

The problem is that by default Microsoft Excel as a COM object can only activated by the following accounts:

  • Administrator
  • System
  • Interactive

When you are running your ASP.Net account on Windows XP your web application is running as the ASPNET account.

The way to resolve this issue is to edit the DCOM configuration settings for the Microsoft Excel Application object.

Configure DCOM

  • Go to the Start-Run menu item.
  • Type in "DCOMCNFG" and hit enter.
  • This should load the "Component Services" MMC (you can also load from Administrative Tools - Component Services"
  • Expand "Component Services"
  • Expand "Computers"
  • Expand "My Computer"
  • Select the "DCOM Config" item
  • Select the "Microsoft Excel Application" item.
  • Right click and select Properties
  • Select the Security Tab and you should see the following:



  • Under "Launch and Activation Permissions" select the "Customize" option.
  • Click the "Edit" button

    Windows XP

    Windows 2003 Server



  • Click the "Add" button to add a new account to the list.
  • On the dialog that is displayed click the Locations button

    (this is because by default your domain will be selected and we need a local account)

    In this dialog scroll the list to the top (sometimes the first item is not visible) but scroll to the top and select the first item which is your computer name. In the list below "CCROWE" is the name of my computer.



  • Click the OK button
  • On the dialog that is displayed enter "ASPNET" as the account name (make sure location is set to the name of the computer that IIS is on) on Windows XP or if you are running on Windows 2003 Server you must enter the account that the Application Pool is running as, by default "Network Service"

    Windows XP

    Windows 2003 Server

    Note: A quicker way on Windows XP is to just enter the computer name and the account
    so in my case that would be:

    ccrowe\ASPNET


  • Click the OK button
  • Now make sure you select the following options for the "ASP.NET Machine Account" or the account that is the application pool identity ( by default Network Service)
    • Local Launch : Allow
    • Remote Launch : [blank]
    • Local Activation : Allow
    • Remote Activation : [blank]

    These settings can be seen below:

  • Windows XP

    Windows 2003 Server

  • Click the OK button and test your web application again and it should work fine.

Note: Remember if you are running on Windows 2003 Server you must use the application pool identity as the account and not the ASPNET account.

posted on Thursday, March 02, 2006 4:18 AM | Filed Under [ ASP.Net c# IIS ]

Friday, February 1, 2008

Capitalize Initial in C#

private static string CapitalizeInitial(string strValue)
{
if (strValue.Length == 0)
return strValue;

return String.Concat( strValue.Substring( 0, 1 ).ToUpper(),
strValue.Substring( 1 ) );
}

Converting Excel dates (numeric) to regular dates

When importing dates from Excel, it is common to obtain a number instead of a date. That is the number of days after 1/1/1900.

private static string ConvertExcelDate(string strDate)
{
int iDate = 0;
if (! int.TryParse(strDate, out iDate))
return "";
DateTime dtDate = new DateTime(1900, 1, 1);
dtDate = dtDate.AddDays(iDate - 2);
return dtDate.ToShortDateString();
}

101 Design Patterns & Tips for Developers

101 Design Patterns & Tips for Developers

Friday, January 25, 2008

The file web.sitemap required by XmlSiteMapProvider does not exist

The file web.sitemap required by XmlSiteMapProvider does not exist

I used a custom XMLSiteMapProvider where in i have defined a web.sitemap file with urls.
The application worked fine in the test environment and for administrators but errored out for other users.

The actual error was that the normal anonymous user didn't have enough permission to access the web.sitemap file - in fact it needed permission for the whole directory.

It seems IIS still has some issues with directory/file permissions and the account used for anonymous access (e.g.: IUSR_MACHINENAME).

Monday, January 14, 2008

How to email using TELNET

TELNET mail.plano1.tx.home.com 25
HELO test (127.0.0.2)
MAIL FROM:billgates@richguy.com
RCPT TO:fulano@sicrano.com
DATA
bla-bla-bla

. (<- enter-dot-enter to finish)

QUIT

Sunday, January 13, 2008

Fixing Error when IIS doesn't start

A convenient way to deal with "Unexpected Error 0x8ffe2740"

Ever had the annoying problem of IIS not wanting to start, coughing up the message "Unexpected Error 0x8ffe2740 Occurred."? The reason is that some other application has grabbed port 80. The most common applications doing this are Skype or Trillion. You can try just ending task on them and see if IIS will then start. If you're not running either of those then what could it be? Microsoft's KB article about the subject describes using the third-party utilities TCPView or FPort. But I think an easier way to find the issue is to simply drop out to a command prompt and run:

netstat -aon

Scroll up to the top part with TCP listings and you'll see something like this:

Then under "Local Address" look for 0.0.0.0:80. This is your entry, and a the far right is the PID you're after. With that number you can then run Task Manager, select the Process tab, and add the PID column in the display from View / Select Columns:

When you've found the process with the same PID, end task on it. The universe should then return to a state of perfect harmony. (Or at least your IIS will be able to start at that point!)

Another more geeky option to kill the offending app is to compile and run this line of .NET code:

System.Diagnostics.Process.GetProcessById( PID# ).Kill()

(Of course putting in the proper PID where indicated there.)

With everything that the Process class does, you could actually write your own highly effective Task Manager application in .NET if you really wanted to!

Utilities to replace SpinRite

The UBCD (http://www.ultimatebootcd.com/) has several (free) utilities for scanning disks for physical failures.


For data recovery tools: Undelete Plus (http://www.undelete-plus.com/) and TestDisk (http://www.cgsecurity.org/wiki/TestDisk).

Monday, December 24, 2007

Asynchronous Web Services with MSMQ

Learn how to overcome a common scalability limitation of Web Services.
Based on an article by Josh Lane

Many of the first Web Services you create are likely to be synchronous, where processing for each service invocation is handled at the time of the invocation. However, Web Services of this sort can have scalability limitations. You can overcome these issues by using Microsoft Message Queue (MSMQ) with Web Services.

Imagine you've decided to implement a help-desk-request logging system for a large IT department as a Web Service. This web service defines a single public SubmitRequest() method. The user request is processed immediately, regardless of current server load or database availability. This can limit scalability and robustness.

Public Function SubmitRequest(ByVal request As HelpDeskRequest)
Try
Dim oldWriter as New OldSystemWriter
oldWriter.SubmitRequest(request)
dim newWriter as New NewSystemWriter
newWriter.SubmitRequest(request)
ContextUtil.SetComplete()
Catch ex As Exception
EventLog.WriterEntry("HelpDeskRequestProcessor", _
ex.Message,EventLogEntryType.Error )
ContextUtil.SetAbort()
End Try

You can solve scalability problems by changing the web service from a synchronous request model to an asynchronous request model, introducing an intermediate component into the request-logging architecture that can take requests rapidly and guarantee their eventual delivery.

Such an asynchronous system can be built using MSMQ, a middleware subsystem that comes pre-installed on all Windows 2000 and upwards. It provides a means of storing messages of arbitrary content for forwarding or retrieval in operating-system-level structures called queues. MSMQ queues are Distributed Transaction Coordinator (DTC)-aware resource managers, meaning that send and receive operations against a queue can operate within a COM+ transaction. You can access the full complement of MSMQ services from the System.Messaging API in .NET.

First, you need to build a component that's triggered when the request message queue on the server receives a help request. This component removes the message from the queue and performs the processing.

The trigger calls this method each time a new message arrives in the
target queue. Note that the queue path is passed in as a parameter. Also
note that all work is performed inside a COM+ transaction, so the MSMQ
receive operation and both SQL Server write operations are treated as
a single atomic operation.


Public Sub ProcessMessage(ByVal path As String) _
Implements IMsgHandler.ProcessMessage
Dim mq As MessageQueue
Dim m As Message
Dim oldWriter as IRequestWriter
Dim newWriter as IRequestWriter
Try
mq = New MessageQueue( path )
m = mq.Receive()
m.Formatter = New XmlMessageFormatter( _
New Type() { GetType( _
VSM_ShareTypes.HelpDeskRequest ) } )
oldWriter = New OldSystemRequestWriter()
oldWriter.WriteRequest( m.Body )
newWriter
= New NewSystemRequestWriter()
newWriter.WriteRequest( m.Body )
ContextUtil.SetComplete()
Catch ex As Exception
EventLog.WriterEntry("VSM_RequestHandler", _
ex.Message,EventLogEntryType.Error )
ContextUtil.SetAbort()
Finally
mq.Dispose()
End Try
End Sub

Create an MSMQ Trigger Rule and register the COM+ components using regsvcs.exe. Trigger rules allow your components to be invoked automatically as a result of messages arriving at the target queue. You can use MSMQ triggers to process queue messages instead of implementing a traditional queue listenener; be sure you understand the usage semantics of each option before choosing one.

New Rule (set up in the Computer Management Console):
Invoke COM component
Component ProgID: VSM_MessageHandler.HelpDeskRequestHandler
Method Name: ProcessRequest

Here the public web service is responsible only for receiving incoming requests and writing them to the target request queue. This simple, fast operation minimizes the work performed by the web server and allows you to maximize precious web server resources and minimize client response times. Note the use of a local transaction instead of a COM+ transaction (which would be overkill since it involves only a single resource manager - the queue).


Public Function SubmitOrder( ByVal order As HelpDeskRequest)
Dim mqt As New MessageQueueTransaction()
Dim mq As MessageQueue
Try
mq = New MessageQueue(m_QueuePath)
mqt.Begin()
mq.Send(order)
mqt.Commit()
Catch ex As Exception
EventLog.WriteEntry( "VSM_RequestTaker", _
ex.Message, EventLogEntryType.Error )
mqt.Abort()
Finally
mq.Dispose()
End Try
End Function

Also see Using MSMQ message triggers (PDF file)