UAC shield icon in WPF

By Robert Ellison. Updated on Sunday, May 2, 2021.

WPF: When it's good it’s very, very good and when it’s bad it’s like sautéing your own eyeballs.

When you’re about to launch a process that will trigger an elevation prompt it’s polite to decorate it with the little UAC shield so the user knows what to expect. Of course there’s no such capability in WPF, and WPF controls have no handles so you can’t use SendMessage / BCM_SETSHIELD as with Windows Forms.

System.Drawing.SystemIcons.Shield seems promising, but it returns the wrong icon on Windows 7 (at least in .NET 4).

SHGetStockIconInfo will allow you to get the correct icon, but isn’t supported on Windows XP. I’ve just added the necessary interop signatures for SHGetStockIconInfo to pinvoke.net so I won’t duplicate that code here. Once you have the interop you can get the correct icon as a BitmapSource using the following code:

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: UAC shield icon in WPF #code #.net #c# #wpf #uac #pinvoke How to add the correct UAC shield icon for each Windows version in .NET WPF using Win32 interop. )

Geotagging posts in BlogEngine.NET

By Robert Ellison. Updated on Sunday, September 30, 2018.

Geotagging posts in BlogEngine.NET

I've written an extension for BlogEngine.NET that automatically adds several different geographical tags to blog posts. I knocked this up for my Hikes blog. It might be useful for any blog where some of the posts are related to a real world location.

To get started download GeotagFromKML.zip (2.24 kb) and copy GeotagFromKML.cs to the App_Code\Extensions folder in your BlogEngine.NET instance.

The extension does two things. Firstly it looks for a link to a KML file when post is added or updated (it does this because each of my hike posts includes a Google Earth KML file for the hike). If a KML link is found then a paragraph is added to the post containing the longitude and latitude of the first coordinate in the KML file. The paragraph uses the Geo microformat. You can customize the text in settings for the extension. You can also regenerate by deleting the paragraph and saving the post. 

The second function is to add ICBM and Geo Tag META tags when serving a post that contains the geotagged coordinates. You can take advantage of this without linking to a KML file, just include a location like this in your post:

Once you have geotagging up and running you might also want to add GeoURL to the list of ping services for your site.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Geotagging posts in BlogEngine.NET #code #blogengine.net #.net #c# #metadata #kml #geo #icbm #geourl #geotag A customer extension that supports geotagging posts in BlogEngine.NET. )

Twin Peaks

By Robert Ellison. Updated on Sunday, May 3, 2020.

Twin Peaks

Not much of a hike, but Twin Peaks is about as high as you can get in San Francisco and offers wonderful views on a clear day or night. Park here and then escape the throngs by walking up one or both of the peaks.

Rob and Kate at the top of Twin Peaks in San Francisco
We often take guests from out of town up Twin Peaks. The occasion today was a first visit for a new native San Franciscan – Katherine Harper Ellison – seven days old on her first trip up to the top of Noe Peak.

Red-tailed Hawk above Twin Peaks in San Francisco 
A Red-tailed Hawk hunting over Twin Peaks.

(.49 miles, total elevation gain 201 feet, 25 minutes, average 1.17 mph, view in Google Earth.)

Hike starts at: 37.754849, -122.446607.

Add your comment...

Related Posts

(Hike Map)

(Published to the Fediverse as: Twin Peaks #hike #twinpeaks #sanfrancisco Short hike up Twin Peaks in San Francisco, California. )

Reboot computer in C# / .NET

By Robert Ellison. Updated on Monday, May 2, 2022.

Reboot computer in C# / .NET

.NET doesn’t support rebooting, logging off or shutting down your computer though a managed API. Searching for the best way to do this brings up three options: WMI, shutdown.exe and ExitWindowsEx.

I regard WMI as the last resort of the desperate. Weakly typed magic string juju.

Calling Process.Start(“shutdown.exe /r /t 0”) might work, but how would you know? And you’ve got the overheard of starting a new process just to accomplish a reboot. Lazy.

The best way to reboot is P/Invoke to ExitWindowsEx. Unfortunately there’s some really awful sample code out there which will either fail to do anything or mask any errors. I’ve included a drop-in class below that fixes these problems.

If you read all the way through the documentation for ExitWindowsEx you’ll find this:

To shut down or restart the system, the calling process must use the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME privilege. For more information, see Running with Special Privileges.

So just calling ExitWindowsEx won’t do anything. The sample code below adjusts the process token and then reboots (change the flags passed to ExitWindowsEx to shutdown instead, or to pass in a different reason). You’ll also get a Win32Exception if a failure occurs. Catch this, and you can tell the user that they need to reboot manually.

Add your comment...

Related Posts

(All Code Posts)

(Published to the Fediverse as: Reboot computer in C# / .NET #code #reboot #wmi #shutdown.exe #exitwindowsex #openprocesstoken #lookupprivilegevalue How to call ExitWindowsEx correctly to reboot a computer in C# / .NET including error handline in case you need to tell the user to reboot manually. )

Reviews and links for August 2010

By Robert Ellison. Updated on Friday, February 24, 2017.

Packing for Mars: The Curious Science of Life in the Void by Mary Roach

4/5

It's Mary Roach, so no surprise that her book on space focused on how hard it is to take a crap (in space), how much engineering goes into disposing of crap (in space), and practical uses for crap on a Mars mission (including making it into radiation shielding tiles and reprocessing it into crap burgers). You'd think this book would be NASA's worst nightmare, but it's actually humanizing as well as fascinating. If you're a Roach fan you'll love it. If you haven't had the pleasure then this is a great place to start.

 

The Lion by Nelson DeMille

2/5

This sequel to The Lion's Game is disappointingly flat - Corey and Assad are fated to meet for a final confrontation and they do but after an initial sky diving sequence nothing really happens. There's very little tension, no plot, no struggles or setbacks for the hero or villain. DeMille really phoned this one in.

 

The Girl Who Kicked the Hornet's Nest (Millennium, #3) by Stieg Larsson

3/5

The second and third books could be just one (very) long book. Nest kicks off where Fire ended and slows the tempo down a bit, although not to the glacial pace of Tattoo. It's a fitting ending to the tale of Salandar, if a bit drawn out in the final sequence. Of course, a must read if you've ploughed through the first two.

 

Links

- What do new passports say about the UK? from BBC News - Home (At least it still "requires" other countries to let us pass without let or hindrance, unlike the less forceful US passport...).

- General Motors in huge share sale from BBC News - Home (It really doesn't seem quite right to call it an 'initial' public offering.).

- Record broken for number of 'pirates' in one place from BBC News - Home (Um, is that just because the Guinness people are afraid of going to Somalia?).

- Sandwich Monday: 'The Breakfast Club' Edition from NPR Blogs: Wait Wait ... Don't Tell Me! (Sandwich Monday is now funnier than the actual show.).

Add your comment...

Related Posts

(All Reviews)

How to fix software patents

By Robert Ellison. Updated on Thursday, November 12, 2015.

In 1790 Thomas Jefferson became the first patent examiner and issued a grand total of three patents. 220 years later the US Patent Office has a backlog of over 1.2 million applications. Internet and software industries are created and destroyed in the time it takes the average patent to issue.

Here's how a startup can easily turn to the dark side:

  1. Investors pressure a startup to file patents in an attempt to make the business defensible.
  2. Tens of thousands of dollars of billable hours result in ‘System and method for displaying a text based colloquial greeting to the populace of a planetary body’.
  3. Startup fails but notices that other companies have implemented their ‘Hello, World’ IP and a patent troll is born.

Software patents are especially frustrating as it's the idea — usually the easiest part of the business — that gets patented. Because patent law doesn't require actual implementation, let alone success, it's as if you could patent “cancer drug” and then sue pharmaceutical companies each time a new treatment rolled out.

It's tempting to call for an outright ban on software patents, as Vivek Wadhwa did recently. This doesn't work because so much technology is software based and because somewhere in that 1.2 million backlog there probably are a few genuinely novel ideas. 

The first part of the fix is to stop examining the patents at all.

This may sound crazy, but think about copyright. You don't need to pay a bunch of lawyers to represent you before the copyright office and prove that this really is the first time a particular novel has been written, or that you were in fact holding the camera when you snapped that photo. Copyright is automatic.

A patentable invention isn't a specific work of art and so some registration system is required. My suggestion is that you upload a PDF and pay a registration fee of around $1,000. It's small enough not to discourage startups and large enough to prevent abuse. USPTO would timestamp the PDF, store it for eighteen months and then publish it.

The obvious flaw would seem to be opening the floodgates to even more patent trolls. That's where the second part of the fix comes in — shift the burden of proof of validity to the company that owns the patent. You can still sue, but the first step is a rigorous and expensive exam process. 

This system makes it easy to obtain a patent but changes the nature of the patent to an insurance policy in case your idea really is as clever as you think it is. It also makes it much harder to use a patent offensively. Resources are more efficiently used to evaluate the novelty of a patent when it is enforced, rather than to do the impossible task of evaluating millions of ideas that never will be.

Full disclosure: I'm co-inventor of several software patents that I hope will never be used against you. I also recently lost a product (Cucku Backup) as a result of settling a patent infringement lawsuit and I hope that never happens to you either!

Add your comment...

Related Posts

(All Politics Posts)

(Published to the Fediverse as: How to fix software patents #politics #patents #jefferson #uspto #trolls #copyright A fix for the patent system - scrap up front examination and remove the assumption that any patent is valid. Easier to get a patent, harder to use if offensively. )

AT&T MicroCell Woes

By Robert Ellison. Updated on Thursday, November 12, 2015.

AT&T's MicroCell extends their famously inept network into your home or office. It does a tragically good job — you can use your broadband connection to not make calls rather than not making calls through an AT&T tower.

It's actually worse, because at least on the actual network you know when your signal sucks. With the MicroCell my phone shows five bars but will often refuse to make or receive a call. The first clue is often leaving the coverage of the device and finding out what you've missed. In fact, I think it might even be illegal under the Communications Act of 1934 as it's effectively a jammer. 

Even if I can make a voice call the wretched thing screws up geolocation. In order to comply with E911 the device is registered to a specific address AND requires a GPS lock to function at all. Despite this it tells my phone that it's in Berkeley. Switch the MicroCell off and I instantly get the correct location in San Francisco. Switch it on and I'm teleported to Telegraph Avenue. My Google Latitude history has whiplash every time I leave the house. 

Reading the AT&T forums I'm lucky. Other users are located in the wrong state, and have choppy voice when they can make a call at all. 

Add your comment...

Related Posts

(All Etc Posts)

(Published to the Fediverse as: AT&T MicroCell Woes #etc #at&t #microcell #geolocation How AT&T's MicroCell cure is worse than the disease (the disease in this case being AT&T's regular network). )

Reviews and links for July 2010

By Robert Ellison. Updated on Friday, February 24, 2017.

Imperial Bedrooms by Bret Easton Ellis

4/5

Returns to the characters of Less Than Zero twenty five years later. I don't think it's a plot spoiler to say that they're not happy and well adjusted people. I found Glamorama to be pretty tedious and Lunar Park only marginally better. It was a huge relief that Imperial Bedrooms just flows. It's a welcome return to his earlier narrative style. Dread and paranoia are visceral presences from the start and then layers of fear and horror build until it can't get any worse and then somehow does. Brilliant.

 

Blue Ocean Strategy: How to Create Uncontested Market Space and Make Competition Irrelevant by W. Chan Kim

2/5

Given its pedigree it's missing two segments - the yellow ocean (no competition, no customers) and the purple ocean (high competition, no customers). They must be saving those for a sequel. I read this because a few people had recommended it and if you think the ideal market to play in is one with no differentiation and high competition then it's a must read. Otherwise the only real value is being conversant with the buzz word. Evaluating past successes with 20/20 hindsight and talking about their 'blue ocean strategy' is a classic business book selection bias. If you learn anything from the case studies it should be that breakout innovation doesn't come from your ocean, hedgehog principle or current cheese location.

 

61 Hours (Jack Reacher Series, #14) by Lee Child

3/5

Well constructed if average plot. This is the Empire Strikes Back of Reacher novels and ends on a bit of a cliffhanger - the next in the series is out later this year and hopefully picks up the pace a bit.

 

Professional C# 4 and .NET 4 by Christian Nagel

4/5

I own the 2005 and 2008 flavors of this book as well. It's the best overall C# reference I've found and this 2010 version is a welcome update. As with the 2008 book it could use a better guide to new features, but still very highly recommended.

 

Ina May's Guide to Childbirth by Ina May Gaskin

3/5

It's a somewhat troublesome mix of advice and propaganda. The advice seems mostly solid, practical and grounded in a great deal of experience. The book ends with the most important - don't think that your body is a lemon, pregnancy isn't a disease, you can do it. Ina May's statistics from "The Farm" are compelling as well, but the birth stories are a bit far out. They typically sound like: 'Sunflower, hanging from the birthing gallows while member of the Farm suck her nipples and I bring her to repeated orgasm, didn't even notice that her baby had been born'. For most people there's probably a middle ground between technocratic doctors and hippie midwives. When the book veers into propaganda it seems there's no anecdotal story too weird to make the case for natural childbirth and no study rigorous enough to suggest that there might be nothing to this modern medicine fad. Some suggestions - like that obstetricians don't believe that nutrition has a role in healthy pregnancy - are just so ridiculous that they case doubt on the rest of the book. And yet, her statistics are so very good while US hospitals force you into a caesarean section to prevent lawsuits and not miss happy hour. I guess the only conclusion to reach is to give birth in The Netherlands and then move to Sweden to take advantage of their twenty year maternity leave...

 

Links

- Frogger from xkcd.com (don't miss the alt text).

- Say fat not obese, urges minister from BBC News - Home (also 'a bit poorly' rather than 'cancerous').

- MoD 'must not live beyond means' from BBC News - Home (Easy fix... bring troops home and send National Audit Office to scold Iraq and Afghanistan into submission.).

- Vatican mulls sex abuse of impaired adults from All Salon (Hint: if you don't know the number for your local police department 112 will work on most mobile phones.).

- Call for school rugby scrum ban from BBC News | News Front Page | World Edition (Where was Professor Pollock when I was at school?).

- Grandmothers link orcas to humans from BBC News | News Front Page | World Edition (Could it be that the mothers also have mothers? Like necessarily?).

Add your comment...

Related Posts

(All Reviews)

Time Zone Time Lapse

By Robert Ellison. Updated on Saturday, February 19, 2022.

The video below shows twenty-four hours from noon UTC to noon UTC on June 7, 2010 using webcams from the Catfood WebCamSaver database. It proves that I really will do anything to avoid finishing off the new Catfood web site.

You can probably figure out that the three blocks of cams are the US, Europe and Japan. The position doesn't reflect the latitude in this version, it's just a random selection of cams for the timezones represented in the database. As it's July and most of the cams are in the northern hemisphere you'll see long days and short nights. I'll try to remember to create an updated version around the autumnal equinox.

The program that generated the frames ended up being simpler than i thought. Because it's fetching images from a lot of different sources I had a timer creating and then saving a frame once a minute and lots of worker threads fetching the images. Each worker thread is assigned a frame number and once it's got the image it locks the main frame and tries to paints it's own area. If the frame number has moved on the image is abandoned. You can see some of the cams flickering on and off in the video — these went down while the frames were rendering or just took longer than a minute to respond.

Add your comment...

Related Posts

(More Timelapses)

(Published to the Fediverse as: Time Zone Time Lapse #timelapse #timezone #catfood #webcamsaver #video Time Zone time lapse showing twenty four hours around the world with webcam images from Catfood WebCamSaver. )

Reviews and links for June 2010

By Robert Ellison. Updated on Friday, February 24, 2017.

Tell-All by Chuck Palahniuk

2/5

A barely reheated Glamorama (celebrities and brands in bold face) about star-fucking in the form of a movie script. Enough Palahniukisms to make it worth finishing (for me), but only because it was mercifully short.

 

Links

- BP 'trusted partner' of Olympics from BBC News | News Front Page | World Edition (Appropriate given that much of the Olympic site is toxic sludge covered in a thin layer of plastic wrap...).

- Falls cost NHS millions each day from BBC News | News Front Page | World Edition (Are they falling on expensive scanners or something?).

- Should nuts be banned on commercial flights? from All Salon (Ban them? I can't remember the last time I was served anything as luxurious as a peanut on a US flight...).

- Call to regulate artificial life from BBC News | News Front Page | World Edition (Public should have studied harder at school then.).

- City of Smarty Pantses from Spots Unknown (Says more about cost of living maybe?).

- "A hundred mile oil lake at the bottom of the Gulf that's 500 feet deep." from jwz (Hopefully this guy doesn't know what he's talking about...).

- Dolphin uses iPad as way to communicate with humans from Boing Boing ("S_ l_*g *nd th*nks !or *ll the !ish" - but what can it mean?).

- Feds meet with film director Cameron on oil spill from SFGate: Top News Stories (They can get rid of it in post-production?).

Add your comment...

Related Posts

(All Reviews)