Calling x64 CLI Tools in x86 Scripting Tools and Processes

Every now and then I get the same question from people who only recently decided to make the switch to x64 bit Windows operating systems. I’ve been running on x64 since Vista RTM and I’m very happy with it. When those people start scripting with their tools, which are 32 bit, calling some CLI tool in %windir%System32 they can run into an annoying issue that express itself in the correct yet somewhat misleading “WshShell.Exec: The system cannot find the file specified.”. But you know it’s there in %windir%System32, you checked and double checked!

When your scripting tool is 32 bit and you run your script it usually launches an 32 bit version of the CLI tool you’re calling. This behavior is a result of file redirection. This is a transparent process that’s part of the Windows-on-Windows 64-bit (WOW64) subsystem that is used to run 32 bit apps. When a 32 bit applications calls a CLI tool in the %windir%system32 directory it silently redirects this to the %windir%SysWOW64 where 32 bit apps can happily run without a worry on an x64 bit operating system. Yes, indeed %windir%system32 is for x64 code only and %windir%SysWOW64 is for 32 bit code.

What’s in a name 🙂 Some people argue they should have use system32 for 32 bit and system64 for x64 bit but I’m sure they had their reasons for what they did (i.e. it would have been hell for some reason I guess). Other suggestions have also been made by people who are far better qualified than I am. For example by Mark Russinovich, a hard core systems developer, in http://blogs.technet.com/b/markrussinovich/archive/2005/05/07/running-everyday-on-64-bit-windows.aspx.

Now all this can happen transparently for the user if the tools used have both an x64 and a x86 version. Cmd.exe and ping.exe are fine examples. If you run some VBScript in my favorite scripting tool for example (Sapiens PrimalScript) which is 32 bit it will launch a 32 bit cmd.exe, that launches the cscript.exe 32 bit version and which will launch ping.exe (using WScript.Shell) in %windir%SysWOW64 by silently redirecting your %windir%system32 path. No worries, you don’t know any better and the result is the same. So it’s usually not a problem if there is both a x64 and a x86 version to the CLI tool as you have seen in the ping.exe example. When a 32 bit process calls a tool in %windir%system32 it’s redirected to %windir%SysWOW64 and uses the 32 bit version. No harm done.

The proverbial shit hits the fan when you call a CLI tool that only has a x64 bit version. As the scripting tool is x86 it’s call is redirected to the WOW64 and the script fails miserably as the CLI tool can’t be found. This can be pretty annoying when writing and testing scripts. The CLI backup tool of Windows Backup is a prime example. It does not have a 32 bit version. Consider this little script for example:

Option Explicit

Dim oShell
Dim oExecShell
Dim sBackupCommandString
Dim sText

Set oShell = CreateObject("WScript.Shell")
'sBackupCommandString = "%windir%sysnativewbadmin get disks"
sBackupCommandString = "%windir%system32wbadmin get disks"

Set  oExecShell = oShell.Exec(sBackupCommandString)

Do While oExecShell.Status = 0
    Do While Not oExecShell.StdOut.AtEndOfStream
        sText = oExecShell.StdOut.ReadLine()
        Wscript.Echo sText 
    Loop    
Loop

Set oShell = Nothing
Set oExecShell = Nothing

There is a lot of File Redirection going on here to %windir%SysWOW64 when running this code in the 32 bit scripting tool. That tool launches the 32 bit cmd.exe and thus the 32 bit cscript.exe which then launches a 32 bit shell and tries to run "%windir%system32wbadmin get disks" which is also redirected to %windir%SysWOW64 where wbadmin cannot be found throwing the error: “WshShell.Exec: The system cannot find the file specified.”. If you don’t have a 32 bit code editor just launch the script manually from an 32 bit command prompt to see the error.

The solution as demonstrated here is to use as in “%windir%Sysnativewbadmin.exe get disks”. Uncomment that line and put the line with sBackupCommandString = "%windir%system32wbadmin get disks" in comment. Do the same test again and voila. It runs. So there you have it, you can easily test your script now. Just make sure that when the time comes to put it out in the wild you replace it with the real path if the calling process is x64 bit, which for example wscript.exe and cscript.exe are when you launch the form a x64 bit shell (explorer.exe or cmd.exe), which is the default on a x64 operating system. The x86 version runs when you launch them from a x86 shell. But remember the default on x64 bit operating systems is x64 bit and sysnative only functions when called from a 32 bit process (it’s a virtual directory that doesn’t really exists).

Sysnative was introduced in Vista/Windows2008 x64 bit. Not only 32 bit script editor users a affected by this, all 32 bit processes launching tools in "%windir%system32 are. See more on MSDN via this link http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx.  For the folks running XP or Windows 2003 x64 bit it is perhaps time you consider upgrading to Windows 2008 R2 or v7 x64 bit? If you can’t, no need to worry, you’re in luck. Microsoft did create a hot fix for you (http://support.microsoft.com/?scid=kb;en-us;942589) that introduces sysnative on those platforms. So welcome to the x64 bit universe, beware of file redirection in WOW64 and happy scripting 🙂

The SP1 Béta Wave – E2K10 & W2K8R2

News from Tech Ed 2010 North America rolls in and we have the announcements of Windows 2008 R2 SP1 Béta for July 2010. Exchange 2010 SP1 Béta became available today! I’m grabbing it 🙂

I wouldn’t be surprised to see the the final releases of the products be announced at Tech Ed 2010 EMEA. Now I also wouldn’t mind if they came sooner due to the new and improved feature set both service packs offer, but I’m not really counting on that.

Bob Muglia’s live streamed keynote @ Tech Ed 2010 North America is nearing it’s end by now and he’s pretty up beat about lots of subjects Visual Studio 2010, Azure, System Center, Cloud, Exchange, OCS 14, Windows Phone 7, SQL Server 2008 R2, Office 2010, SharePoint 2010, Bing Maps & SDK, Avatar as a cloud case study & collaboration with Microsoft etc.

Cloud is omnipresent but they talk about hybrid. Making sure Hybrid is cost effective is important to me. I don’t need more work and costs but less.

Why I Find Value In A Conference

For those of you who are attending a high quality conference I’m going to share some tips. It’s great to be able to attend a conference. Not because it’s in a great city and you’ll get to dine out at night, but because of the opportunities it provides us to learn and grow.

So what is the value of such a conference? Well, it is about the communication with peers and guru’s. The conversations you’ll have and the exchange of taught and ideas. The technical information you’ll gather, the products and techniques you’ll see. All of this will help you to direct and focus the way in which you approach your job, run your projects, plan and realize your visions and ideas. A conference, if done well, is nothing more or less than a technical education in the business of ICT and how to do things and make it work, results versus efforts wise. On top of that you get to interact and share ideas with your peers. You can’t ask for anything more.

Conferences cost a lot of money, time and energy. After all when you’re attending you have no income or the boss pays you while you’re not in the office creating value. On top of that you have to pay for the hotel, flight, daily expenses and the conference fee.  So why would we do this? There’s a global crisis, there’s a European crisis, there’s an XYZ crisis and there is economic doom and gloom all over the place. Not to mention all the results of that downturn … cutbacks, redundancy, foreclosures, failing businesses, unemployment, etc. The conference scene is not immune to a recession. Conferences are canceled, scaled down, attendance drops.  The competition from blogs, on line, free or subscription based content, pre views, beta’s, web casts, computer based training can be felt as well, as has been the case for many years. Conferences need to fight to maintain high standards of technical content for an ever more demanding and skilled public in a very rapidly changing world and IT scene. But still, a conference done right is an investment worth making. It is an investment in knowledge. In return we get all of the above mentioned in the previous paragraph and that is why I attend them. They make me a better “Technical Architect”. That is try I really put in the effort to get the funds, create the opportunity and reserve the time to go. The benefits of a conference, if done right, cannot be denied.

What is the right way?  Well first here’s the wrong way. Don’t go there or learn how to use delegates in .NET or to build a Linq to Wmi query. It’s not just an ordinary classroom. Do not go there to nag about some issues you had or have because you’re too lazy to do research and read help files, readme texts, TechNet or MSDN. Do not go to complain about how hard it is to find information and study.  Do not go because of the great location, you will see nothing of it 🙂 unless you use it as a vacation. Maybe some USA people deserve to do this but heck I’m from Europe and I get my fair share of holidays. Also, take any frustration, denial or ignorance about the lies of instant gratification and careers success you might have had when you bought product X and it didn’t just improve your live after clicking “Next” somewhere else. Results and successes come from an enduring effort, which is a fancy word for hard work. They are not a right, a perk or let alone guaranteed (yeah some vendors and people lied to you, get over it). If you cannot search study and learn on your own get out of ICT now. If you need support for every issue or new item and expect someone to be there to help every step of the way you’re in trouble. It takes time, dedication and a great deal of effort to become and stay proficient in IT. Even then you’ll know about failure, setbacks, troubles and mistakes. Life & work is not a commercial.

Go to a conference for the big picture, the architecture, the networking with peers, the possibilities and the dreams. Expand your knowledge and views on how to make the pieces work and interact. The focus of the conference is on tying it all together, learning new and better ways, discovering possibilities which all equals to yet more stuff to learn and more work to do. At the booths manned by industry experts or representatives do give feedback about the product and offer to send some more details about certain real problems you might have come across. But be nice and polite, don’t be a jerk. Would you feel compelled to help a jerk? Techies are people, really!

Don’t run to sessions like a mad man without a plan.  Know why you are there and how to get what you’re after. If this is your first conference, everything will be new and fabulous (I hope). You can’t attend enough sessions. You are torn between the choice of sessions and tracks. You’re full of new ideas immediately and overwhelmed with even more just after that. So for all you newbie’s, get your act together and prepare a bit or it will turn into chaos. Write down ideas, insights and possibilities to pursue. What about you conference veterans? Have you’ve been there, done that?  Have you have seen it all before? Not really, and we all know it.  It’s all about lifelong learning. Conferences are about being in a stimulating environment where you “marinate” in the professional IT community for a week. Learn from and with the people attending. Not only during sessions. Lunch with them, have a coffee with them. Immerse yourself in this explosion of IT and business. Think about the new stuff, use your imagination, and write down ideas. Cross check your plans. Calibrate you insights.

The role of the conference is get you thinking about stuff and gives you a chance to talk to each other about that stuff. Interact! It is the essence of a conference. Ask questions both in public and in private. Talk to attendees, to experts, to vendors. See what they are in to, need, tried, where they succeeded and failed. Find out what they have to offer. Talk shop, talk IT life, and make that connection with the others attending in whatever role. There is a wide world out there much bigger, larger and perhaps tougher than your own little world that is driven by results and built on efforts. Those folks have professional and business experience in all of the subjects being discussed. Pick their brains! Get some new insights and ideas. Yes I know some vendors act like 2nd hand car dealers and yes I’ve met people who don’t know their own products. But that doesn’t rule out the need for and benefits of communication and interaction, those where just the wrong people, just move along. Oh and don’t forget to get a bunch of extra business cards you got out of the drawer. Also keep in touch with people you meet. Send a follow up mail, a tweet, a blog mention. That’s how you expand your knowledge network. If you get to go to a conference, enjoy it and make sure you arrive early and leave late. There is no value in missing a part of the experience to save some time or some €/$ bills.

I don’t implement all the ideas I return home with from conferences. But I have them written down in mails, scraps of paper, txt files, One Note scribbles etc. I tend to pour them into a word document during and after the conference. Form that I distill my plans, my vision and my roadmap.  I will present those to management, colleagues, partners and customers and offer them solutions based on my perception of what business needs we can satisfy with technology. The stuff I’m working on now was born as ideas 12 to 18 months ago. Those ideas are tested and checked over time, they ripe and then they become plans. I find a conference a great place to do that.

Tech Ed 2010 Europe – Just registered

As a heads up people, I’m attending Tech Ed 2010 Europe from November 8th to November 12th in Berlin, Germany. Join me and thousands of hard core IT Professionals in learning, exchanging ideas, networking and preparing to design, plan and shape the future of ICT in the Microsoft space.

I’m looking forward to some 300/400 Level sessions on OCS14, System Center vNext, Exchange 2010 SP1, Windows 2008 R2 SP1, … etc. It’s always great an fun to meet up with old and new people from the IT community on line and off line. Engage in discussions with colleagues and Microsoft Employees, go out for dinner with fellow IT Pro’s & Devs.

Looking forward to it. Tech Ed is what you make of it. I might blog about that later. It takes some work & preparation to get the most out of it. Hope to see you there!

If you read my blog, follow me on twitter or know me and you’re going, sound of and we’ll arrange a meet & greet.