System Process is Locking .exe Files that Visual Studio Builds

October 23, 2013

This has been happening for a while not and I decided to get to the bottom of this very annoying problem.

Problem

I build a solution in Visual Studio, then I rebuild that same solution and get the very familiar error message:

Error 1 Unable to copy file “obj\x86\Debug\MainApplication.exe” to “..\bin\MainApplication.exe”. Access to the path ‘..\bin\MainApplication.exe’ is denied. MainApplication

Root Cause

After many, many of these dumb messages I wanted to see what process would be so aggressive as to want to lock my newly compiled file.

So I fired up Process Explorer (procexp.exe).

First thing you must do is Show Details for All Processes. This action is on the File menu.

The use the Find menu, select Find Handle or DLL…. 

In the Process Explorer Search, enter the full name (no path) of the .exe reported in your above Visual Studio build error message. 

Why Is This Happening

So my questions is, why is the System process PID:4, locking my .exe file?

Currently I have to wait several minutes until the file is no longer locked.  I have noticed that if I have an instance of Windows Explorer open in the build output folder that files get locked more often.

Hint:  Don’t kill System PID:4, your computer will lock up. 

SystemLockingBuiltFiles

Solution

I started thinking about what could be doing this:  Virus, Search Indexer?  Bingo!

I searched for how to throttle the search indexer.  Turns out someone already figure this out.

http://www.sevenforums.com/tutorials/194374-indexer-backoff-enable-disable-windows-7-a.html

One last step may be required.  After performing the above steps, you may need to reboot your computer. 

(Windows team, please provide a setting on the Indexer UI to set throttling, needing a registry entry is not a good solution to this problem.)

So far, this has solved my problem by enabling Indexer Backoff as explained in the above tutorial.

Close

Hopes this helps someone and have a great day,

Just a grain of sand on the worlds beaches.


Coding Signing Internal Applications and a Gotcha

April 16, 2012

This blog post explains one way to code sign your internal applications along with their installers. Code signing your applications and installers provide a UAC friendly user experience during installation, uninstall, and when your legacy applications may need to run with administrative privileges (more about admin privileges below).

UAC Friendly Installation Experience

The below image pictures a user friendly UAC dialog, complete with Program name, Verified publisher. If you internal applications are not code signed, the user will get a warning dialog, with a bizarre program name, and Verified publisher set to unknown.

I don’t know about you, but I would rather condition my users to see UAC friendly dialogs, rather than the warning dialog. Next thing you know, they have “accidently” approved a UAC warning that could cause you a big problem.

InstallationUAC

If you are signing applications that are not internal to your organization, the content surrounding certificates and the guidance surrounding signtool.exe may violate your organizations code signing rules or procedures.

This blog post is about code signing internal applications that will be used within your organization.

Code Signing Certificate

The first order of business is to get a code signing certificate installed on machines that will build your internal applications. You can see from the below image, that my certificate server gmcx-Security-CA has issued a code signing certificate and that I have imported that certificate into the “Personal” Store under the “Certificates” folder.

To be honest, creating a code signing certificate that did not have my name on it, instead had our organization’s name is was bit of a PIA and required creating a certificate template on the certificate server that allowed me to do this. I found this TechNet article very helpful:

http://technet.microsoft.com/en-us/library/cc731705(v=ws.10).aspx

Certificate Manager

After you create the certificate, export it and import it on all machines under the users “Personal” store as above.

For example, I have this certificate installed on our two developer machines and on the build server.

Configuring the Solution (executable projects)

There are several ways to configure actions that take place during MSBuilds. I have chosen the “batch file” method because it is very easy to implement and debug. You could leverage one of two out-of-the-box build Tasks or create your own build task, but I chose “batch files” for the above reasons.

Notice that I have checked these batch files into source control. This ensures that all machines can build the solution correctly.

ProjectBatchFiles

AfterBuildTasksDebug.bat

If your scenario requires code signing the debug build, the below batch file uses the signtool.exe program to code sign the .exe program. You “could” also pass in command line parameters to the batch file that would include the folder name of the target along with the target name.  I’ve kept this simple to make it easier to understand all the pieces.

Notice that I didn’t have to specify a certificate, password, etc.  This is because I only have one code signing certificate installed on my machine.  The “/a” switch instructs signtool to automatically pick the code signing certificate from my “Personal” store.

@echo on

call “C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat”

call signtool sign /a “C:\Projects\GMC\Src\GMC\bin\Debug\GMC.exe”

AfterBuildTasksRelease.bat and the Gotcha

Now time for a nasty gotcha. This little beast cost me about 2 hours trying to figure out why, every time I did a Release build using the Setup project to build and create the install package that the .exe the installer installed was not longer signed.

Read this thread on the Windows Dev Center for full details:

Setup project strips digital signature from exe target

Now that you have read the above thread, you’ll fully understand why when creating a release build, you must code sign the .exe under the \obj and \bin folders.

The signtool… commands sign my .exe. Let me call out one additional signtool switch you need to mind when signing your .exe.

You should also specify the “/t” switch. This will time stamp your .exe so the user knows when the .exe was built.

@echo on

call “C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat”

call signtool sign /a /t http://timestamp.comodoca.com/authenticode
   “C:\Projects\GMC\Src\GMC\obj\Release\GMC.exe”

call signtool sign /a /t http://timestamp.comodoca.com/authenticode
   “C:\Projects\GMC\Src\GMC\bin\Release\GMC.exe”


Configuring Visual Studio 2010 to Use the above Batch Files During a Build

BuildEvents

  • Open the Build Events dialog from the .exe project’s properties tab.
  • Change the “Run the post-build event” option to “When the build updates the project output.”
  • Enter the above text in the “Post-build event command line” text box.

This will run one of the two batch files based on the configuration, Debug or Release.

Building the Solution

Like many of you, I don’t build my Release builds within Visual Studio.  Some use a build server, others build them from the command line to allow other tasks to be accomplished.

Below is a fragment of a batch file that I use when building a release build.  The devenv… command rebuilds my solution. Notice the “/rebuild” switch instead of the “/build” switch.

The signtool… command signs my .msi installer that the Setup project built. Let me call out two additional signtool switches you need to mind.

It is important that you specify the “/d” switch for your .msi installers. If you scroll back up to the top of this blog post and view the UAC image, you’ll notice the Program name matches the text in the below “/d” switch. If you don’t specify this, your user will see some bizarre text.

You should also specify the “/t” switch. This will time stamp your installer so the user knows when the installer was built.

@echo on

call “C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat”

devenv /rebuild Release /project GMC_Setup C:\Projects\GMC\Gmc.sln

echo .
echo .
pause

signtool sign /a /d “GMC for Office 2010 Setup” /t http://timestamp.comodoca.com/authenticode
   C:\Projects\GMC\Src\GMC_Setup\Release\GMCForOffice2010_Setup.msi

… additional tasks

Legacy Applications Running on Windows 7 and Above

My company has a legacy Windows Forms application that was written during the days of Windows XP.  My company like many other enterprises never installed Windows Vista.  Recently we installed Windows 7 on our enterprise desktops.

Well the legacy enterprise applications I’ve inherited do things are are not UAC friendly.  For example, writing to the \Program Files folder and other tasks that are now under Windows 7 considered taboo.

Being a good Enterprise Administrator and Developer, I want all my clients running Windows 7 with UAC set to the Default setting and for my users to learn about the UAC feature and its benefits; this will provide them a safer computing environment here at work and at home.

Microsoft has documented UAC here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa511445.aspx  

Microsoft and bloggers have documented a number of strategies for dealing with UAC and legacy applications.  Turning UAC off or limiting its capabilities should not be considered a good option.

I was not willing to take on the risk of modifying our legacy applications, so I run my few enterprise applications with an embedded application manifest that tells the operating system this application requires administrator privileges to execute. All of our users are administrators on their local computer.

Example Application Manifest

Notice the the below application manifest that the “requestExecutionLevel” is “requireAdministrator.”

<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>
<assembly xmlns=”urn:schemas-microsoft-com:asm.v1″ manifestVersion=”1.0″>
  <assemblyIdentity version=”1.0.0.0″ processorArchitecture=”X86″ name=”GMC” type=”win32″/>
  <trustInfo xmlns=”urn:schemas-microsoft-com:asm.v3″>
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level=”requireAdministrator”/>
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

To embed the above application manifest you need to use the mt.exe program. I placed the below command at the top of my two batch files, AfterBuildTasksDebug.bat and AfterBuildTasksRelease.bat.

You’ll need to edit the paths and .exe name as well as the manifest name.

call “C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\mt.exe” -manifest
   “C:\Projects\GMC\Src\GMC\GMC.exe.manifest”
   -outputresource:”C:\Projects\GMC\Src\GMC\bin\Debug\GMC.exe;#1″

Close

For those of you that have the need or desire to code sign your internal enterprise applications, I hope this blog post will help you avoid the long learning curve.

Have a great day,

Just a grain of sand on the worlds beaches.


Schedule for the Redmond WPF for LOB & Windows 7 and .NET 4 Event

April 20, 2010

Jaime Rodriguez, myself, Cider Team Members along with some key WPF Team members are very excited about the upcoming WPF for LOB, MVVM, Windows 7 and .NET 4 event.  We are only a week away.

Schedule

Each day runs from 8:30am – 5:30pm. Doors open at 8:00am.

  • Wednesday, 28 April 2010 (breakfast & lunch provided)
    • Lap Around WPF
    • WPF Architecture
    • XAML
    • Layout
    • Element Trees
    • Resources
    • Dependency Properties
    • Routed Events
    • Controls, Templates and Styles
    • Threading Model
  • Thursday, 29 April 2010 (breakfast, lunch & dinner provided)
    • Data Binding
    • Commands
    • Intro to MVVM
    • Tips from the MVVM Trenches
    • Data Validation in MVVM
    • Modal Dialogs, Error Handling, Logging
    • Views, Navigation and Transitions
    • Integration & Unit Testing in MVVM
    • Thinking in WPF…
    • Optional Special Event: Thursday, 5:30pm, Dinner with the Cider Team  (see details below)
  • Friday, 30 April 2010 (breakfast & lunch provided)
    • Lap Around WPF 4.0
    • Blend 4.0
    • Visual Studio 2010 WPF & Silverlight Designer
    • Multi-Touch Deep Dive
    • Shell & Taskbar
    • Surface Control Toolkit
    • Graphics & Text Improvements
    • Understanding the Client Profile
    • Controls & Data Improvements
    • Q & A
  • Saturday, 1 May 2010
    • Pair programming, applying the last 3 days at your pace with your code.  Experts on-hand to assist you as you spread your wings with WPF & MVVM.
    • You’ll need to bring your own laptop for this evolution.

Dinner with the Cider Team (Thursday)

Based on your own experience and this training course, you probably have a feel for what the Visual Studio 2010 WPF and Silverlight Designer tooling can do to help you build your applications.

The team that built that designer would love to get the chance to spend some time with you to get a feel for the kinds of development problems you’re facing with your WPF and Silverlight projects, and understand the sort of capabilities that you’d like to see in future versions of Visual Studio.

Come and share a delicious hot BBQ dinner from premier local outlet “Dixies” (vegetarian and Kosher options will be available on request), speak your mind and hear our plans, and take your opportunity to help us choose wisely when we pick the features we build.

A Few Seats Still Open

We had a few folks give up their seats so registration is still open.

Date

Event

Location

Registration Links

4/28–4/29

WPF for LOB

Microsoft Redmond Campus, Building 20

WPF for LOB Registration

4/30

Windows 7 and .NET 4

Microsoft Redmond Campus, Building 20

Windows 7 and .NET 4 Registration

5/1

Pair Programming

TBD – announced during training

None required

Close

We are looking forward to spending this quality time together with you.  I’ve been working hard on completely new demonstration applications for this event.

Have a great day,

Just a grain of sand on the worlds beaches.


Announcing events WPF for LOB & Windows 7 and .NET 4

March 14, 2010

Jaime Rodriguez and Karl Shifflett have created their best offering to-date; three days packed with WPF, optimized for building business applications and a tour of WPF for Windows 7 and .NET 4.

Event

This event is actually two events running back-to-back, "WPF for LOB" and "Windows 7 and .NET 4".

You can register for one or both events. If you want to attend both, you must register for both.

For this event we are adding an optional fourth day for those who want to spend a day programming, applying the information learned over the three days with your own code. We will have Microsoft Experts and MVP’s on hand to assist and pair program with you. This extra day provides you time to work at your own pace and ensure that you understand how to take advantage of the material presented over the previous three days.

Overview – WPF for LOB Event

This two day training is designed to teach developers how to create Line of Business (LOB) applications using Windows Presentation Foundation (WPF).

  • Day One Topics: WPF graphics subsystem, layout, element trees, resources, dependency properties, routed events, custom controls, templates and threading.
  • Day Two Topics: Data binding, commands, building applications using the Model-View-ViewModel pattern, creating testable applications, implementing data validation, and error handling and notification, view navigation and transitions.

After completion, attendees will have a solid understanding of WPF, its advantages and how to use the M-V-VM pattern to create great WPF LOB applications.

Overview – Windows 7 and .NET 4 Day Event

We will spend all day recapping the new WPF features in .NET4 and showing you how to take advantage of some of these new features:

  • Tooling Improvements
  • Graphics & Platform Improvements
  • Deployment Improvements
  • New features that light-up on Windows 7

Dates, Location, Registration

All events run from 8:30am – 5:30pm. Doors open at 8:00am.

Remember, to attend both events you must register for each event.

Registration Tip

If you have never filled out an MSDN event profile before, you’ll do so the first time you register.

If asked about being a partner, if you are not a partner or don’t know if you are:

  • When asked "are you registered" select No. 
  • Select "Visiting partner" under Partner Level.
  • Get creative on the Partner Type;  if in doubt, we are all "System builders"

Date

Event

Location

Registration Links

4/28–4/29

WPF for LOB

Microsoft Redmond Campus, Building 20

WPF for LOB Registration

4/30

Windows 7 and .NET 4

Microsoft Redmond Campus, Building 20

Windows 7 and .NET 4 Registration

5/1

Pair Programming

TBD – announced during training

None required

Detail Agenda

We will post the detailed agenda for the three training days around the 4/22/2010.

Logistics

Format
Instructor-led training from 8:30am – 5:30pm. 15 minute breaks every couple hours. 45 minutes lunch around mid-day.

Food
Breakfast, lunch and afternoon snacks are provided.

Cost
The training is FREE. You do need to register prior to the event, but there is no cost.

Registration is first-come-first serve, sign-up as early as possible to reserve your spot!

Cancellation
If you register and then learn you cannot attend the event, please take steps to cancel your reservations. Not cancelling could prevent another developer for attending the training. Thank you for your professionalism.

Instructors

About the instructors
Karl Shifflett is a software architect, former Microsoft MVP from Bellevue, Washington. He is currently working for Microsoft on the Cider Team as a Program Manager. He has been designing & developing business applications since 1989 and transitioned to .NET in March of 2003. In April of 2007 he joined the list of WPF and Microsoft Expression fanatics & evangelists. He is a member of Team Mole that delivered Mole Visualizer For Visual Studio to the world. He is the author to XAML Power Toys and loves WPF LOB. 

Karl’s blog is at https://karlshifflett.wordpress.com

Jaime Rodriguez is a Principal Technical Evangelist at Microsoft. He focuses on WPF and Silverlight.   For the last four years, he has helped a lot of enterprises and ISVs adopt WPF in large scale, mission critical, projects.

Jaime has been doing software development for fifteen years. Prior to Microsoft, he worked at Xerox, HP, Cerner and GeoAccess.  He joined Microsoft 9 years ago, he spent the first four years as an Enterprise Architect Consultant in Microsoft Services, and the last five he has been a client evangelist covering Windows Forms, WPF and Silverlight. 

Jaime’s blog is at http://blogs.msdn.com/jaimer

Have a great day,

Just a grain of sand on the worlds beaches.


Developers – Must Learn – Booting Windows 7 from a VHD

October 9, 2009

For the past few months I’ve been sharpening my Windows 7 skills and discovered what many systems people already know; “you can easily setup and boot Windows 7 or Server 2008 R2 VHD.”

Someone may already be thinking, why do I need to boot a VHD?

It’s no secret that Microsoft will be shipping Visual Studio 2010 Beta2.  If you want to be notified when Beta2 ships you can sign up here:  http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx

Some developers prefer to install beta software on a non-production machine or set up a multi-boot box.

This is where VHD’s come into play.  You can setup a VHD on your desktop or laptop, then from the boot menu, select to boot that VHD or boot the operating system.  I’ve been doing this at home and work for awhile now and love it.

VHD’s also enable you to have a x32 O/S boot and a x64 O/S boot on the same machine.   Possibilities are endless.

When you’re done with the VHD, just delete it and make a new one.

VHD’s sport great performance.  If you use the fixed size VHD, the total performance cost is 3%.  When I boot a VHD on my laptop I don’t see any drop in performance from booting the original O/S.

VHD’s do not require Hyper-V to boot them.  Server 2008 R2 does have a Hyper-V feature that allows you to log onto a VHD.  But what I’m explaining here does not require Hyper-V.  This is why I love this feature, it just works.

Recommendations

Before creating a new VHD, defrag the volume you want to add the VHD to.

I always create a fixed size VHD to ensure maximum performance.  Dynamic sized VHD’s offer flexibility with respect to size but pay a performance hit.

I’ve been allocating 45GB for all my VHDs.  This leaves plenty of room for Windows 7, Visual Studio, Microsoft Office and other applications and data on the VHD.  After you have created and configured a few of these, you’ll determine what works best for you.

I created a c:\vhd folder and locate all my VHD files here.

Possible Configuration Scenarios

Computer has Windows 7 or Server 2008 R2 installed and one or more Windows 7 or Server 2008 R2 VHD’s.

Computer does not have any O/S installed, but has one or more VHD’s that can be booted.  How cool is this?

Possible VHD Installation Options

Create a new VHD and install Windows 7 from a DVD or network location.

Create a new VHD and use imagex.exe to restore a .wim file to the VHD.  This is my favorite.  This saves so much time.  You install an O/S, configure it and install all the other software you need (except Visual Studio).  Then use imagex.exe to save a copy of the O/S and software to a .wim file.  You can then use imagex.exe to restore that .wim file to a VHD or if you need to a boot partition.  I do this at work every 1-2 weeks.  Takes a few minutes to pave my box.  Awesome software imagex.exe is!

On my laptop and desktop systems, I keep an extra VHD file that is all ready to go.  It’s configured and has all the software I need except Visual Studio.  Then when I want to load up another version of Visual Studio, I copy the files I need, delete the old VHD, copy the standby VHD to another new VHD, boot the new one and install Visual Studio.  Even on my laptop with the 45GB file copy and installing a new Visual Studio I’m up and running quickly.

Imagex.exe

What is imagex.exe?  Read this: http://technet.microsoft.com/en-us/library/cc507842.aspx

Where can I get imagex.exe?  Here: http://www.microsoft.com/downloads/details.aspx?familyid=696DD665-9F76-4177-A811-39C26D3B3B34&displaylang=en.  

Read how Scott Hanselman uses imagex.exe.  Great blog post!  Step-By-Step: Turning a Windows 7 DVD or ISO into a Bootable VHD Virtual Machine

Links

Rather that create a new blog post with pictures, etc, I’m going to provide the links that I’ve used to be successful with VHD’s.

Scott Hanselman: Step-By-Step: Turning a Windows 7 DVD or ISO into a Bootable VHD Virtual Machine

Microsoft TechNet: Windows 7 Boot from VHD.  This is actually the home page for a 3 part series on VHD files.  Very well written and covers the scenarios I’ve listed above. 

Microsoft Evangelist Keith Combs: 

Video:  Dual Boot from VHD with Windows 7 and Windows Sever 2008 R2
Article:  Dual Boot from VHD Using Windows 7 and Windows Server 2008 R2

Close

I hope you find this information informative and useful. 

Have a great day,

Just a grain of sand on the worlds beaches.


Follow

Get every new post delivered to your Inbox.

Join 241 other followers