Hyper-V Migration and HAL

August 7th, 2010 Ali Moeen No comments

When a Windows 2003/XP virtual machine is migrated to Hyper-V, it is not easy to migrate it back to Virtual PC – or VirtualBox. The reason is Hyper-V changes HAL and it is not easy to change the HAL on 2003/XP machine. This issue is solved since windows Vista and up. Starting windows vista, Windows can detect and change HAL. The detect and change HAL option is available in MSConfig->Boot Tab->Advanced Options->Detect HAL

Detect HAL

Windows 2008 guest has built in support for Hyper-V; however, when a Windows 2008 image is migrated to Hyper-V, “Detect HAL” option should be selected or Hyper-V drivers won’t work. The following screenshot shows the symptoms of undetected HAL in a windows 2008 guest:

Undetected HAL Symptoms

Categories: Uncategorized Tags:

How to start and wait for a SQL Server JOB – The feature should be added to sp_start_job

May 8th, 2010 Ali Moeen No comments

There are straight forward options to start a SQL Server agent job. The options include sp_start_job and “Execute SQL Server Agent Job Task” in SSIS and Maintenance Plans. The issue is that there is no way to start a job and wait until the job is finished. That means the next TSQL or SSIS task starts right after.

I created with the following small stored procedure that becomes handy when it is required to start an Agent Job and wait until it finishes its work.

CREATE PROC [dbo].[usbStartAndMonitorJob]
(
	@JobName	VARCHAR(200)
)
AS
BEGIN
	IF 1<>(SELECT COUNT(*)
		FROM
			OPENROWSET(
			'SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
			'EXEC MSDB.dbo.sp_help_job  ')
		WHERE name = @JobName)
	BEGIN
		PRINT 'CANNOT FIND JOB: ' + ISNULL(@JobName,'')
		RETURN -1
	END
	DECLARE @StartTime DATETIME
	DECLARE @JobStatus INT
	SET @JobStatus = 0
	SET @StartTime = GETDATE()
	PRINT 'Execute and wait: '+@JobName
	EXEC MSDB.dbo.sp_start_job @Job_Name = @JobName
	WAITFOR DELAY '00:00:03'

	SELECT TOP 1 @JobStatus=current_execution_status
		FROM
			OPENROWSET(
			'SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
			'EXEC MSDB.dbo.sp_help_job  ')
		WHERE name = @JobName
	-- This is just to flush the output messages while waiting
	RAISERROR ('', 10,1)  WITH NOWAIT
	WHILE @JobStatus <> 4
	BEGIN
		WAITFOR DELAY '00:00:03'
		SELECT @JobStatus=current_execution_status
			FROM
				OPENROWSET(
				'SQLNCLI', 'Server=localhost;Trusted_Connection=yes;',
				'EXEC MSDB.dbo.sp_help_job  ')
			WHERE name = @JobName
		PRINT 'Afert '+CAST(DATEDIFF(second,@StartTime , GETDATE()) AS VARCHAR)
			+' seconds, the status is: '+CAST(@JobStatus AS VARCHAR)
		-- This is just to flush the output messages while waiting
		RAISERROR ('', 10,1)  WITH NOWAIT 

	END
	PRINT 'Job executed ended'
RETURN 0
END
Categories: SQL Tags:

Top 10 Reasons Notepad Should Be Replaced With Notepad++ On Developer Machines

August 12th, 2009 Ali Moeen No comments

Text editors are essential part of our day to day work and there are many to choose. Perhaps, Visual Studio?s test editor is the first choice for .NET development. Besides that, usually we need a light and fast text editor for the rest of text editing work. Notepad++ (NPP) is my favorite.Here are my top ten reasons why:

  1. NPP includes most standard features other text editors have (i.e regex search and replace, bookmarks, macros, multi document, multi view, accurate zoom, etc…)
  2. NPP does rectangular block text selection (Alt-Shift-Arrows or Alt-Mouse) and rectangular text clipboard operations. Rectangular operations becomes even more powerful when used with Edit->Column Editor
  3. NPP includes syntax highlight and auto complete for popular languages including XML. Also, NPP highlights brace { } [ ] ( ) and indent guideline.
    Highlighted Brace
  4. NPP is slim, low foot print and fast. It is able to load and handle large files
  5. Includes many handy utilities including:
    • HTML and RTF syntax highlight export to file or clipboard
    • MIME tools and Base64 encode/decode
    • Converts DEC, HEX, OCT, Bin, Text, EBSDIC and ASCII to each other.
  6. NPP includes a powerful hex/binary editor plug-in. The hex editor is flexible and offers many options. One key switches back and forth between text and HEX view/Edit: 

    HexEditor

  7. NPP supports many text file format including Linux, Windows and Mac format:Formats
  8. NPP monitors file system and notifies user when another program modifies the file being edited
  9. XCopy is an option. It is included in Portable Apps as well
  10. The last but not least, It is free!
Categories: Tools Tags:

How to get details about svchost.exe entries in the task manager

May 31st, 2009 Ali Moeen No comments

We don?t get much information about bunch of svchost.exe entries in windows task manager. The KB314056 explains how to use Tasklist /SVC command line at the command prompt to get the details:

image

The alternative method is adding the command line column to the task manager:

image

Categories: OS Tags:

Invading classes’ privacy with reflection

June 1st, 2007 Ali Moeen No comments

This is not a new technique, but I found it interesting. We can easily manipulate private or protected member of a class by using reflection. It shouldn’t be used in normal circumstances, but it could become a useful hack when we have to use an assembly developed by someone else and some minor manipulations are necessary;) Here is a sample:


using System.Reflection; 

 namespace PrivateMembersExposed 

 {
     class Program
     {
        static void Main(string[] args)
        {
            ClassWithPrivateMembers c = new ClassWithPrivateMembers();
            c.PrintThePrivateString();
            FieldInfo fieldInfo;
            fieldInfo = c.GetType().GetField("privateString", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldInfo.SetValue(c, "Yes, I can!");
            c.PrintThePrivateString();
            System.Console.ReadKey();
        }
     }
     public class ClassWithPrivateMembers
     {
         public void PrintThePrivateString()
         {
             System.Console.WriteLine(privateString);
         }
         private string privateString = "Can you aecess this?";
     }
 }
 
Categories: .NET, C# Tags:

My Visual Studio 2005 External Tools

April 23rd, 2007 Ali Moeen No comments

Here are items I have in my Visual Studio external tools as little shortcuts:

  • Refelctor the Compiled Assembly
  • Gacutil the class library
  • Put a strong name key in the project directory. Once I use the .snk file, I make it read-only so it won?t be over written by running this command again

Click to Enlarge

Click to Enlarge

Click to Enlarge
Categories: Visaul Studio Tags:

This one is even better than Google Calculator!

April 20th, 2007 Ali Moeen No comments

Google calculator works perfect. But when we don’t have internet connection or for some complex calculations javascript is the solution! Here is a sample:

So you think it is not powerful enough? Copy and paste this line to your browser’s address bar (one line) :

javascript:for (var x = 0; x <= 4*Math.PI; x+=.5) document.write("********************".substr(0,5+5*Math.sin(x))+ "<br/>");

It works in both IE and Firefox.

Categories: Windows User Tags:

Visual Studio’s Hidden Icon Library

April 17th, 2007 Ali Moeen No comments

When we add a ToolBar to a WonForm form, we can add a set of standard button to the toolbar. I searched my local hard drive for the icon files and I couldn?t find them. After a little investigation I fond that the Icon and Image Library is stored within a zip file at this location:

C:\Program Files\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary\ VS2005ImageLibrary.zip

There are bunch of nice images and icons inside the zip file. Enjoy!

Categories: Visaul Studio Tags:

How to audit HDD used space

April 10th, 2007 Ali Moeen No comments

I ran out of HDD free space last week and I knew it can?t be for real. I used WinDirStat and in a snap I found I have couple of abandoned virtual machines somewhere on my hard drive. WinDirStat efficiently illustrates big files and folders and makes it easy to go through big folders and inspect their contents: 

 

Categories: Windows User Tags:

How to take a copy of an assembly from GAC

July 1st, 2005 Ali Moeen No comments

Putting an assembly into GAC is easy, but how about taking a copy of that assembly back? I needed to have Microsoft.Sharepoint.DLL on my development machine to compile a project and I had to take Microsoft.Sharepoint.DLL from the server?s GAC. Assemblies are stored in:

C:\Windows\assembly\GAC\{assemblyname}\{version}__{publickey}\

The easiest way to access that location is using command prompt.

Categories: .NET Tags: