Hey, Scripting Guy! Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (2/19/10)

Bookmark and Share
In this post:


Should I Convert My VBScript Scripts to Windows PowerShell?

Hey, Scripting Guy! Question

Hey, Scripting Guy!

I have several scripts written in VBScript; however, I am wondering if I should begin making the move to Windows PowerShell. Should I?

— BC


Hey, Scripting Guy! Answer Hello BC,

Microsoft Scripting Guy Ed Wilson here. If I were you, I would begin writing all new scripts in Windows PowerShell because it is the future. VBScript is in maintenance mode, which means that we are only making bug fixes and security fixes to it. There have been no new features added to VBScript since Windows XP was introduced more than nine years ago.

In the meantime, Windows PowerShell has been introduced and has even come out with version 2.0. Version 3.0 of Windows PowerShell is currently in development. Nearly all of the product groups are creating new Windows PowerShell cmdlets to allow for easy administration and automation of their products. Windows Server 2008 R2 introduced Group Policy cmdlets, Active Directory cmdlets, IIS cmdlets, and other cmdlets that solve automation problems that have proved vexatious for years.

Doing a direct translation of a VBScript script to Windows PowerShell is not always a good idea because at times the approach taken in VBScript is not the same as in Windows PowerShell. For example, Windows PowerShell introduces the concept of the pipeline, which can at times speed development and offer streamlined processing of collections of objects. Another example is that Windows PowerShell passes objects, and VBScript passes text. Many times, you will wish to work with the entire object, rather than just a textual representation of the object. A good example of the difference, however, is seen when one talks about translating a VBScript script to Windows PowerShell.

A good example of a “translated VBScript” written in Windows PowerShell can be seen in the TechNet Script Center Script Repository. The reason I say it is “translated” is because it uses exactly the same approach to WMI that VBScript uses. You can compare the Windows PowerShell script with the original VBScript script, and you can see they are essentially the same script. The same information that is displayed by those 17 lines could have been displayed by this one line of code:

get-wmiobject -class “Win32_DeviceMemoryAddress” | Format-List *

If you were in a hurry, you could use aliases and reduce the typing even more:

gwmi win32_devicememoryaddress | fl *

Though there is nothing wrong with the “translated” script, it is inefficient and involved a terrible waste of time that could have been spent doing something more productive.

If you have a VBScript script that works, I recommend you continue to use it. In my time, I have written more than 4,000 VBScript scripts. I have translated fewer than 200 of them into Windows PowerShell. I continue to use some of these VBScript scripts every day, and I see no reason to migrate them to Windows PowerShell because the time can be better spent writing new Windows PowerShell scripts that give me new capabilities.

VBScript will continue to exist for quite some time because there is a huge installation base. However, you should begin learning Windows PowerShell because it offers features and solutions that cannot be easily duplicated with VBScript. If you wish to begin learning Windows PowerShell, use some of the resources we have on the TechNet Script Center. You will also want to check out the Getting Started series of Hey, Scripting Guy! posts I have written. They are most excellent, if I do say so myself!


How Can I Run My HTAs as an Administrator?

Hey, Scripting Guy! Question

Hey, Scripting Guy!

You are always talking about writing files and such to C:scripts as an example. Microsoft does not allow this anymore. All of my HTA and VBS scripts were rendered useless when I upgraded to Windows 7, and as if that was not torture enough, I also can’t run any of them as administrator because they have greyed out the option. Is scripting dead, or do you have a solution?

– CH


Hey, Scripting Guy! Answer Hello CH,

It is not a Windows 7 problem. We actually changed the security of the root folders back in Windows Vista. You can go into Windows Explorer and change the security of your folder, or use a folder inside your user profile.

To cause an HTA to run as an administrator, you will need to open a Command Prompt window as an administrator, and type the path to your HTA. I talked about this in a Quick-Hits Friday Hey, Scripting Guy! post in which I was discussing the Scriptomatic. It is near the bottom of the article.

Scripting is far from dead. In Windows 7 you have access to Windows PowerShell 2.0. Windows PowerShell is the future of scripting. VBScript and HTAs are in maintenance mode.

If you want to get started with Windows PowerShell, you should look at the Getting Started series of Hey, Scripting Guy! posts as well as the Windows PowerShell learning page on the TechNet Script Center.



Here’s a Script That Generates Code for the HTA Helpomatic
Hey, Scripting Guy! Question

Hey, Scripting Guy!

I liked your HTA Helpomatic script so much that I made a companion script that generates code for it, so users can add their own sample code to the Helpomatic. It is simple to usejust paste your code in the window and run Helpomatic. The second window generates the code that can be copied and pasted into the Helpomatic script.

To make best use of the code generator, you’ll also need to change the ShowExample subroutine on the Helpomatic; otherwise, the Run button will not appear in the sample area, unless the existing subroutine is manually edited for every new sample that is added.  I have uploaded the HTA to the TechNet Script Center Script Repository.

— KH


Hey, Scripting Guy! Answer Hello KH,

Awesome job. Thanks you so much for sharing this with us.



Help Me Interpret This Message About Task Scheduler 
Hey, Scripting Guy! Question

Hey, Scripting Guy!

“User_Feed_Synchronization-{59735BF7-2705-4F57-BECE-86000217C164}.job” (msfeedssync.exe) Finished 1/13/2010 6:43:41 PM Result: The task completed with an exit code of (0).

I’m seeing a continuous page over and over in my scheduled tasks. I am very green, so you experts have a good laugh but what is it? I also posted this on the Scripting Guys forum 

— SB


Hey, Scripting Guy! Answer Hello SB,

The msfeedssync.exe program is used for RSS feeds that allow you to subscribe to updates to various blogs, such as the Hey, Scripting Guy! Blog. When you subscribe to a blog via RSS, you are automatically notified when something new is posted. The notification includes a short paragraph that describes the update. This allows you to decide if you wish to go and read the blog that day.

With an RSS feed, Internet Explorer 7 and later versions have a tab in History that will display updates. You can also subscribe to RSS feeds in Outlook (which is where I prefer to have my updates sent). The msfeedssync.exe is the program that goes out and polls the RSS feed for updates.

The Task Scheduler service is used to schedule the polling for the updates. The fact that you are getting an exit code of 0 is a good thing. It means the job completed successfully (there were zero errors). The Task Scheduler in Windows 7 is seen in the following image.

Image of Task Scheduler in Windows 7

Even if you are not subscribed to any RSS feeds, the scheduled task will run each day, and the msfeedssync.exe program will run and look for updates to RSS feeds. If you are not subscribed to any RSS feeds, the task is really simple and easily completed, but it still runs. Therefore, you may as well go ahead and subscribe to the RSS feed for the Hey, Scripting Guy! Blog. While you are at it, you should also consider subscribing to the RSS feed we have set up on the Script Repository, so you will get a notification when new scripts are uploaded.

This concludes another edition of Quick-Hits Friday. It also concludes another exciting week on the Script Center. Join us tomorrow for our second weekend of the new Weekend Scripter series.

If you want to know exactly what we will be looking at tomorrow, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at scripter@microsoft.com or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.


Ed Wilson and Craig Liebendorfer, Scripting Guys



No Comment.