Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Friday, March 3, 2017

.NET: Debugging A Windows Service

1. Navigate to the windows service project.
2. From toolbar, select Project --> Properties
3. Set "Output type:" dropdown to "Console Application"
4. Open Program.cs, locate Main method, and add the following:

       static void Main(string[] args)
        {
            //to test and debug
            if (Environment.UserInteractive)
            {
                YourWinService serviceHb = new YourWinService(args);
                serviceHb.TestStartupAndStop(args);
            }
            else
            {
                var servicesToRun = new ServiceBase[]
            {
                new YourWinService(args)
            };
                ServiceBase.Run(servicesToRun);
            }
        }

5. Navigate to your service code and add the following method:

         internal void TestStartupAndStop(string[] args)
        {
            this.OnStart(args);
            Console.ReadLine();
            this.OnStop();
        }

6. Set breakpoints and run as console app.

Monday, October 29, 2012

Windows 7: Fatal Error: Installation ended prematurely because of an error.

Sometimes I receive the following error when trying to install an application in Vista or Windows 7. The installation seems to go through as expected but then will roll back and throw the following error (note that sometimes this error presents as "Error 2869"):

Fatal Error: Installation ended prematurely because of an error.

Apparently, this occurs when an application attempts to install with the 32-bit version of InstallUtil.exe but actually needs to use the 64-bit version of InstallUtil.exe.

Sometimes, the fix is as simple as running your installation as “Administrator.” The rest of the time, it seems as if you have to somehow point your installation to use the 64-bit version.

First, navigate to C:\Windows\Microsoft.NET\Framework. From here you might see the different versions of the framework installed on your machine. There should be a version of InstallUtil.exe in each folder.

Your installation is probably trying to use 2.0.* instead of 3.0/3.5/4.0.

Work-around:

1. Locate the path to your installation program (ie, C:\Program Files\MyInstallationFolder\MyInstall.exe)

2. Open a command prompt window as administrator

3. Navigate to the version of InstallUtil.exe you want to use (ie, C:\Windows\Microsoft.NET\Framework\v4.0.30319)

4. Next, in the command prompt enter:
InstallUtil.exe “C:\Program Files\MyInstallationFolder\MyInstall.exe”

Your application should now install.

Tuesday, October 9, 2012

Windows 7: Customize Your Windows Theme

The default location for pre-installed Windows 7 themes are located at :

c:\windows\resources\themes 

Locations for other wallpaper theme files :

c:\windows\web\wallpaper

For themes that you have downloaded yourself :

C:\Users\{username}\AppData\Local\Microsoft\Windows\Themes

To add a wallpaper to a theme:  copy your own wallpaper image files to the folder that has the same theme name you would like to use.  Then, enable the wallpaper in "Personalize --> Desktop Background."