Scott Hanselman

Running PowerShell Scripts from the Command Line in a Hidden Window

February 28, '07 Comments [1] Posted in PowerShell | Tools
Sponsored By

Dave P. said the comments of a previous post "...but it's ugly b/c it actually opens a command window to do it. Batch files don't have this issue. Now if you can figure out a way to run powershell scripts in a hidden window, then you'd be onto something."

Running PowerShell Scripts from the command line is obscure and yucky to be clear, mostly because of escaping of quotes and such.

If you want to run a hidden powershell script, you can use HStart from the awesomeness that is NTWind Software. (Just go over there and download all of his utilities and save yourself some time).

Here's how to run a hidden powershell script:

hstart /nowindow "powershell.exe -command ""&" 'c:\DOCUME~1\Scott\desktop\foo.ps1'""

If you're going to start running hidden scripts like this, or any script, make sure that you've got PowerShell transcripts started with start-transcript and stop-transcript.

**********************
Windows PowerShell Transcript Start
Start time: 20070228113605
Username : MYDOMAIN\Scott
Machine : SUPERDUPERWONDERFUL-T60P (Microsoft Windows NT 5.1.2600 Service Pack 2)
**********************
Transcript started, output file is C:\Documents and Settings\Scott\My Docume
nts\WindowsPowerShell\Transcripts\20070228.113605.3196.txt

GAC Version Location
--- ------- --------
False v1.1.4322 C:\Documents and Settings\Scott\My Documents\Window...
Setting environment for using Microsoft Visual Studio 2005 x86 tools.

True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0....

Hey! I'm in powershell (this is my script running)
**********************
Windows PowerShell Transcript End
End time: 20070228113605
**********************

You can make your scripts run faster by turning off the profile with the -noprofile switch, but be aware you'll have no profile and might not have some helper functions you've previously setup.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Office 2007 Foxit PDF Previewer/Handler

February 28, '07 Comments [18] Posted in Reviews | Tools
Sponsored By

Tim Heuer gives to the community and don't let anyone tell you otherwise. 

Everyone's been waiting ((and waiting) and waiting) for a PDF Previewer for Outlook 2007. I'm shocked that Adobe didn't get their act together in time and release one at the time of the launch. It would have been a compelling enough reason to actually put the crapware software on my system.

Well, of course you know I love Foxit Software because their tiny and glorious little PDF Reader (and PDF Creator) software keeps my computer moving fast and Adobe-(Reader) free.

Update for clarity - I'm complaining about how slow Acrobat 7 is, especially with regard to all it's plugins that it starts up during the splash screen. It's true that Foxit has crashed on larger PDFs and there's some quirky rendering sometimes, but I currently still prefer it for "casual PDF'ing." As for Adobe the company, I love PhotoShop, so I'm not impugning the whole building.

Now, Tim has combined the Foxit ActiveX SDK and an MSDN sample on how to create an Office Preview Handler and just called Foxit up. (The MSDN one uses Acrobat if you like.)

Bam. It was done.

WARNING: The PDF Previewer only works on Vista right now. Tim says via email:

"The problem with XP is that the preview handler model is slightly different.

In Vista, the preview handler is provided through a managed preview surrogate (you can see it running when you do a preview) called prevhost.exe.  In XP, this doesn’t exist and the preview must be handled by a COM surrogate."

Last year Tim wrote a Code Preview Handler (not sure if this works in XP?) so I guess I'll be collecting the best of these, methinks!

Let's all go over and crush Tim's blog with comments of encouragement. And convince him to make XP versions. He says:

"So, the next step for this project for me is to create the managed COM host for this code-base.  I have some stuff researched…but anyone interested in providing that host is appreciated. Time is not on my side for that one."

If you have the expertise and can write the unmanaged COM code, give him a shout.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Blat - Command Line Emailer saves me time

February 28, '07 Comments [14] Posted in Tools
Sponsored By

I was reading my boss's blog today, as he's a hard core GTD practitioner - more than I - and I'm trying to get better at it.

He recently went on an automation rampage kick around his home IT and wrote a pile of scripts. He also tends to email him self quick little reminders that are filed as todos, as do I, except he can just type

todo "Write a blog post on foo"

And it'll be mailed to him with an appropriate subject and tagged in his Gmail account.

He's using BLAT under Windows (using sendEmail under Linux). BLAT is a command-line util for sending email under Windows. It'll also post to USENET via NNTP if you like.

You can include all the settings on the command-line, or just "install" them in the registry, once, like this:

blat -install localhost whatever@yourdomain.com - - FromScott

Where "FromScott" is the name of a profile we'll use later. Then I can create a TODO.BAT (or TODO.PS1) and put this in it:

@echo off
blat -p FromScott -to
whatever@yourdomain.com -subject %1 -body %1 > NUL

I like running BLAT with -debug, because I'm all about -verbose, don't you know.

NOTE: I'm using Vista and when I ran blat for the first time I was warned by the loader I didn't have MSVCR71.dll, so I ended up getting it and putting it in the same folder as BLAT then it was cool.

I ended up making todo.bat, worktodo.bat and hometodo.bat and they look like this:

start "TODO-ING" /MIN c:\pathto\blat.exe -p FromScott -to me@noneofyourcheese.com -subject %1 -body %1 -debug

So now,

c:>todo "Write a blog post about how my Home IT is automated"

Enjoy.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

You Can't Teach Height - Measuring Programmer Competence via FizzBuzz

February 27, '07 Comments [48] Posted in Learning .NET | Programming
Sponsored By

The comments are abuzz over at Jeff's blog as he's aggreblogged the current discussion on the FizzBuzz problem. It started when Imran said that he has found so few programmers who can code that he, as Raganwald put it, "set the bar ridiculously low."

A FizzBuzz-style question is:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

And for the sake of your immortal soul and your webutation, don't post the solution in the comments. You'll only die a little inside if you do.

Speaking of comments, there's some pretty choice comments on the various blogs that are worth looking at:

It's just performance anxiety.
Most people are terrified/stressed out during interviews.
Not "Can you X?" -
"Can you X whilst terrified?"

This is, to a point, reasonably valid, but I think that if you're hiring someone to sing, it's reasonable to have them sing at the interview. If you're being paid to write code for the better part of your week, and you're offended by being asked to write code at the interview, I say you're hypersensitive. If the interviewer pulls out a laptop and says, "let's write some code" at an interview, as the interviewee, I'd be happy to see that they mean business. I mean, we ARE writing code to solve business problems, right?  Seems like not having someone write any code until you've worked somewhere two or three weeks, gone through orientation and company training, could be a dangerous gamble.

Here's another:

However, I have never *once* used - or had call to use - recursion to solve a problem, since I learned about it at university.

Statements like this are kind of dodgy as well. I don't know this individual, but based solely on this one sentence I would surmise they are either, rather young (i.e. recently out of school, maybe the last 5 years) or they've been writing the same general kind of code in their career. Saying that I have never used X since school either means you haven't been out of school long, or that X is a totally useless thing.

What's really important isn't whether a person has used recursion since school, but:

  • Could they use recursion if they had to?
  • Would they recognize the opportunity to use it when it arose?

This can of course be make generic:

  • Could they use [insert well-known computer science dogma here] if they had to?
  • Would they recognize the opportunity to use it when it arose?

A few years back I kind of got some flack for posting on "What Great .NET Developers Ought to Know." I just wrote that post on a plane, brainstorming the general kinds of things I thought that someone who worked for me should be able to answer. It wasn't an exercise in trivia, I was literally writing it up to prepare to hire someone.

Some - very fervent - folks thought it was a manifesto, dictating that one had to know these things to be successful. Certainly this isn't the case.

But what can we ask folks who are being hired to code? What do you think they'll say if we ask:

  • Say, can you code?
  • Bug free, izzit?
  • Lots of Unit Tests?
  • You love Continuous Integration? Cool.
  • Work well with others? Easy going? Charming.
  • Drugs on the side? No. Good. Come to work on time?
  • You're not evil are you? One of Satan's minions? Good...
  • Got a degree of some kind? Yes, good.
    • Or: No? Being doing this a while though? Got good references?
  • Here solve this simply programming problem. Don't worry, it's not obscure or a trick. I just want to see how you think.

Surely these are all reasonable questions...I could go on. Here's the deal, when I hire someone, I'm looking for them to be tall. A boss told me once that he just wanted his programmers to be tall, because when you're putting together a basketball team, you have to remember that you can't teach height.

We're looking for folks who are excited about computers, who are lifelong learners, who are easy to get along with but willing to fight for what they know to be right. We want folks who will raise the quality of their own code with experience, and also raise the teams level of quality through a process of ongoing improvement and introspection. Seems reasonable to me.

One other thing that's amazing to me about this blogversation (look at me coining B.S. Web 2.0 words left and right!) is that some of the programmers who read these blogs feel the need to actually solve the FizzBuzz problem.

They've completely - no, I need a work with more oomph - utterly? missed the point.

The FizzBuzz exercise is an interesting one, but it certainly should only be considered as a single arrow in one's interviewing quiver. But, Imran ends his post with this, and I shall as well: "This sort of question won’t identify great programmers, but it will identify the weak ones."

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Enabling Aero Glass on Windows Vista with a Toshiba M200/M205

February 26, '07 Comments [22] Posted in Bugs | Gaming | Musings | Reviews | Tools
Sponsored By

I've been really disappointed that the lovely Toshiba M200/M205 series of notebooks has been so poorly supported by Toshiba. While these little workhorses will run Vanilla Vista just fine, none of the useful craplets will work and Toshiba seems to have abandoned this TabletPC for the sexier M400.

I've googled all over for this and found Microsoft blogs where the guy said "it's working great on internal drivers" but I can't get a straight answer from anyone. I figured it was time to solve it once and for all.

The NVidia Vista Drivers announcement says:

GeForce Go GPUs in notebooks are currently not supported in drivers from NVIDIA.com.
At this time, the drivers available on NVIDIA.com do not support notebook GPUs. Many NVIDIA notebook GPUs have Windows Vista drivers already built into the operating system and install the first time you run Windows Vista.

However, I refuse to give up on the Little Tablet That Could.

Even though the M205 isn't listed as supported, I threw caution to the wind and downloaded and installed the:

I also demand Vista Aero Transparent Glass on this laptop. So what that it has a crappy NVidia Fx5200 GX video card with 32megs of RAM? That was state of the art three years ago. Runs (some) 3D games just fine thank you, and Google Earth, too. Surely this POS can run some transparent windows, right? I mean, it did under XP running Windows Blinds. ;) (Yes, I know how the new desktop compositor works under Vista, no letters, please.)

There's a real Gold Mine over at LaptopVideo2Go.com. While NVidia seems not to care much about existing Laptop GPUs with their driver releases, the community at LaptopVideo2Go forces them to care by editing their INF files.

WARNING: You're on your own if you do this...don't come to me with problems. YMMV.

There's excellent step by step screen-shotted instructions on how to download the right drivers for your laptop and use a Modified INF driver file to fool/force/coerce the drivers to supporting your hardware, even when the manufacturer would really rather that you not.

I quaked in fear as Windows reported that this driver was not digitally signed. But, some how I worked past it.

This thread over at LaptopVideo2Go offers this great graphical table explaning the drivers vs. GPU chipset relationships. It's a little out of date, but it helps one get the idea.

 

I downloaded the NVidia 9802 driver for use on this Toshiba but 9719 and a few others. The 9708 driver seemed pretty snappy as well. This was actually a driver released for ASUS laptops. The modified INF is what gets it working for other GPUs. I've actually tried about 10 different versions.

You can poke around and make an educated decision. Many folks feel the 60xx series of drivers is a better choice for the 5200 GO Chipset, others say not to use any lower than 70xx. I went with a newer one based on comments in the forums.

I downloaded the modified INF, copied it over the existing one, and did the old "Update Driver | Have Disk" trick. Again, see the instructions.

After the driver installation, I saw this in my Properties Dialog...check out that Shared System Memory Value. Yikes. I've got 1.5Gigs on this laptop. If you're going to get this working you'll likely need at LEAST that much memory. 

But I loves my Glass. I'll charge onward and see if I can get this to work...

After rebooting, I didn't see any Aero Glass and was totally bummed. Then I went to the Start Menu and typed in "Performance" and ran Performance Information and Tools. I had originally a 1.0 for Graphics Perf, since I was using the out of the box, auto-detected Standard VGA driver.

I ran it again, and got some error that the Video Driver had some trouble and got restarted, but now my Gaming Graphics experience went from a 1.0 (horrific) to a 2.4 (marginally horrific.)

Hm...that's something, I guess, but I still haven't got Glass. Most times I run the Windows Experience Index tolol (by pressing Update my Score) I get this error:

So, there's actually no happy ending (yet) to this post...folks in the Forums insist they've gotten Aero to work on an M205, but I've tried literally 10 different driver versions and modded INF files and while my 3D score has increased, I'm still Glassless.

I'll update this post as information comes in or one of you M200/5 owners tries this and finds a success that you'll share with the rest of us.

  • UPDATE: I got a flash of Aero, then this message in the Event Viewer:
    The Desktop Window Manager did not start because an analysis of the hardware and configuration indicated that it would perform poorly. The Desktop Window Manager has encountered a fatal error (0x8876017c)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.