FIM ScriptBox Read Me First
About the FIM / ILM ScriptBox Scripts are an excellent way to make your daily work with a computer less painful or even more fun. The objective of the FIM ScriptBox and the ILM Scriptbox is to implement a community driven Resource Kit that enables everybody to contribute new ideas and to customize existing ideas the way you like and need it.For example, if a script generates a report and you need additional information, just modify the script code that retrieves the data. If you don't like the look and feel of a report, modify the XSLT that is in charge of rendering the data. There is no need to file a bug and way for a new release - you can just do it... About HTAs When looking at the ScriptBox, some of you may have noticed that Im a HUGE fan HTAs. To me, HTAs, which is a shortcut for HTML Applications, are the greatest thing since sliced bread since they give you an easy to implement and nice looking way to add a GUI to your script based on simple HTML code. This is in a nutshell all what a HTA is from the coding perspective - a HTML file with one special tag.Here is an example for this: You can find a reference that explains the available attributes / properties here.HTAs represent full-fledged application without the need for developing source code in Visual Studio.You can easily modify an existing HTA with - if don't have anything better - for example notepad. So, if you dont like the look and feel of a UI, it is very simple to modify it as well. It is not my intention to explain, how HTAs work in greater detail. The Scripting Guys have already done a great job in conjunction with this. Next to trying to get you motivated to build your own HTAs, I thought it might be helpful to share some tips with you. Jumpstarting HTAs Like so often in life, you might run into some hurdles at the beginning. Fortunately, there is not a lot you need to know. A script can die and usually, I configure my HTAs to be single instance applications. When you double-click a "lost" HTA, you can easily identitfy when you are dealing with a dead process - the UI does not show up.If this happens to you, you should open Task Manager and check, whether you have "hanging" mshta processes. If so, just end them: At this point, you should be at least able to get your HTA UI up and running. Connecting the dots You might be able to get the UI to show up - but when you click a button in your HTA UI, nothing happens although, it should - now what?A nice UI without any kind of functionality is a bit lame. To put some live into your HTA, you need to add script code. The simplest implementation consists of some VBScript code that does the magic.While this is already cool, the real power of HTAs is the possibility to combine your VBScript code with other processes.One example here are command-line applications. In the ILM world, CSExport and SvrExport are prominent examples of command-line apps you can run from a HTA. To start another process from your HTA script code, you can use the Run method of the Windows Script Host.This method enables you to pause the HTA code until the external process has completed. In addition to that, you can specify the window style for the external process.One option here is to completely hide the window of the new process. I tend to use the setting to hide the window of the external process relatively often.However, if you do this, you should also know how you can get to the error messages of your external process! An external process is not necessarily an application - it can also be a script.This is how you can integrate PowerShell into your HTA framework - by calling PowerShell scripts.Scripting with Visual Basic was already cool; however, PowerShell represents an amazing revolutionary step regarding scripting. There is hardly anything you can't do with PowerShell - it is amazing!However, as a lazy person, I found myself often in situations where I missed a nice GUI when I worked with PowerShell. Yes, you can also create GUIs with PowerShell scripts; however, I found it a bit too complicated - at least, not as simple as creating the UI with HTAs.So, wouldn't it be cool to bring HTAs and PowerShell together?The following script code sequence shows the simplest way to call a PowerShell script from your HTA script code: Dim oShell, scriptPath, appCmd Set oShell = CreateObject("WScript.Shell") scriptPath = oShell.CurrentDirectory & "\Res\Hello.ps1" appCmd = "powershell -noexit &'" & scriptPath & "'" oShell.Run appCmd, 4, true To run a PowerShell script from your HTA this way, you need to configure your execution policy to allow this."I have already set the execution policy and the script still doesn't work".Have you also set the execution policy on the right PowerShell version?The following screenshot shows what happens when your try to run a PowerShell script from your HTA in an environment that doesn't allow doing this: If you look at the path of PowerShell, you will notice that it includes "SysWOW64", which indicates the 32 bit version of PowerShell.Since we are talking talking about hurdles, there are two things you need to do to determine whether the execution policy is blocking you from running PowerShell scripts from your HTA: Locate the script code string, that starts PowerShell and add "-noexit" to it Locate the run command and make sure that it doesn't hide the PowerShell window by setting the window style accordingly. If you run into the error message above, type "set-executionpolicy unrestricted" in your PowerShell window.Unfortunately, there is one more thing that can prevent a downloaded ScriptBox script from running in your environment - Alternate Data Streams (ADS).Even, when you have set the execution policy correctly, you might get the following message: To check, whether ADS is blocking your PowerShell script from running automatically, use the following command: notepad <Name of your PowerShell script>.ps1:Zone.Identifier If an ADS is assigned to your PowerShell script, entering the command above will result in something like this: To get rid of the ADS, just delete the content of the notepad file and save it.This was the last hurdle; your HTA script should now work as expected. If your HTA doesn't work as expected, check the following: Do you have a hanging mshta process? If so, end it Is the execution policy blocking your PowerShell script from being invoked? If so, set the execution policy accordingly on the right PowerShell implementation Is an ADS blocking your PowerShell script from being invoked? If so, delete the ADS data Next Steps At this point, you can hopefully not wait to start scripting!I have uploaded with FIM Hello Scriptbox a HTA template that includes tests for the "hurdles" that are outlined in this post.You can use this template to make the already posted scripts work if you had trouble and also as a template for your own scripts. As outlined in the introduction, the idea of the ScriptBox is to implement a community driven Resource Kit.Your participation is key to make this idea work.Please taka advantage of the option to discuss the content of the ScriptBox by responding to related posts. Your feedback is paramount to make improvements and to determine gaps.Do you like the viewers, are documenters good enough, is a HTA usefull, is a PowerShell only implementation good enough, etc.. Please use the voting feature if you find ScriptBox related post helpful. Please feel free to post your scripts.We will take care of updating the FIM Scriptbox roadmap and the ILM Scriptbox roadmap to make sure that everybody in the community can find them. Last but not least, happy scripting!
August 5th, 2009 4:55pm

On a 64bit Windows, you have many 32bit components; this is also true for the HTA engine - mshta.exe.Out of the box, HTA files are opened with the 32bit HTA engine, which is located in the "%windir%\syswow64" folder.To open your HTA files as 64bit versions, you should associate them with the 64bit HTA engine located in the "%windir%\system32" folder.Cheers,MarkusMarkus Vilcinskas, Technical Content Developer, Microsoft Corporation
Free Windows Admin Tool Kit Click here and download it now
August 10th, 2009 10:18am

To make the deletion of the ADS a bit simpler, I wrote the following script: '------------------------------------------------------------------------------------ Option Explicit '------------------------------------------------------------------------------------ Sub Traverse(oFolder) Dim oFso, curFolder Set oFso = CreateObject("Scripting.FileSystemObject") For Each curFolder In oFolder.SubFolders Traverse curFolder Next Dim curFile, fileName For Each curFile In oFolder.Files If(LCase(Right(curFile.Path, 3)) = "ps1") Then fileName = curFile.Path & ":Zone.Identifier" If(oFso.FileExists(fileName)) Then Dim oShell Set oShell = CreateObject("WScript.Shell") "notepad.exe " & fileName 'Set oFile = oFso.OpenTextFile(fileName, 2, True) 'oFile.Close 'Set oFile = Nothing End If End If Next End Sub '------------------------------------------------------------------------------------ Dim oShell, oFso, oFolder, curFile, appCmd, oFile Set oShell = CreateObject("WScript.Shell") Set oFso = CreateObject("Scripting.FileSystemObject") Set oFolder = oFso.GetFolder(oShell.CurrentDirectory) Traverse oFolder '------------------------------------------------------------------------------------ MsgBox "Command completed successfully", 64, Replace(WScript.ScriptName, ".vbs", "") '------------------------------------------------------------------------------------ You need to run this script in the folder where your PowerShell script is stored. Markus Vilcinskas, Technical Content Developer, Microsoft Corporation
October 2nd, 2009 7:04pm

Hi Markus,great stuff though when reading through your original post, I see blank spaces between paragraps. I assume they are there for some sort of screen shot or bitmap? Is there something wrong with my browser?Thanks,Peter
Free Windows Admin Tool Kit Click here and download it now
February 16th, 2010 6:05pm

Peter,make sure that you are signed into the forum when reading this post.That way, you should see the pictures that are included.Cheers,MarkusMarkus Vilcinskas, Knowledge Engineer, Microsoft Corporation
February 16th, 2010 9:45pm

Hi Markus, You mention to open the 64bit mshta.exe we should change the association on the computer so that .HTA files are opened with the 64bit HTA engine ... Whilst this works for 1 computer, we have hundreds where we want to use the .HTA ... So can we: a) Force the computer to use the 64 HTA engine at run time? or b) Change the file association automatically? Though I have to say, I prefer the first option, as I don't know what other .HTA's the user may try and run that require the 32bit HTA Engine. Thanks in advance, Paul
Free Windows Admin Tool Kit Click here and download it now
March 9th, 2010 3:27pm

I'm sure there is a way to automate the file association.Alternatively, you can also use this script : Option Explicit Dim oShell, appCmd, htaPath, htaEngine Set oShell = CreateObject("WScript.Shell") htaPath = oShell.CurrentDirectory & "\FIM Object Visualizer.hta" htaEngine = oShell.ExpandEnvironmentStrings("%WinDir%") & "\system32\mshta.exe " appCmd = htaEngine & Chr(34) & htaPath & Chr(34) msgbox appCmd oShell.Run appCmd, 4, false Cheers,MarkusMarkus Vilcinskas, Knowledge Engineer, Microsoft Corporation
March 9th, 2010 4:24pm

MarkusI have Verified all the powersheel execution settings and the 64 bit associations. I'm trying to tun the MV scheam exporter with no luck. If I run the script manualy I get the following errorsAdd-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.At C:\FIM ScriptBox\FIM_MV_Schema_Documenter\FIM MV Schema Documenter\FIMMVSchemaDocumenter.ps1:9 char:93+ if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin <<<< FIMAutomation} + CategoryInfo : InvalidArgument: (FIMAutomation:String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand Error: The term 'export-fimconfig' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.Also when running the FIM Object Visulizer It complains about 32bit mode for HT and closes. The Hello HTA works fine as well as the FIMMAAttributeFlowDocumenterThe Schema scripts all seam to erro out with thisError: A parameter cannot be found that matches parameter name 'onlyBaseResources'.Any ideas ohh and I'm running RTM
Free Windows Admin Tool Kit Click here and download it now
March 9th, 2010 11:44pm

Outch - this doesn't sound good...All HTAs that are using the FIM cmdlets have to run in 64bit mode.Hello HTA doesn't use the cmdlets, which is why there is no need to run them 64bit mode.You can get around the 32bit mode warning by using the VBScript above.However, your real problem is not HTA related.It looks like that for some reason the FIM PowerShell cmdlets are not installed on your FIM server.If you try to run any of the "Using PowerShell to" scripts, they won't run either.I haven't seen this case yet.Cheers,MarkusMarkus Vilcinskas, Knowledge Engineer, Microsoft Corporation
March 10th, 2010 4:29am

MarkusI have the visualizer working in 64bit now but recieve the following errorError: A parameter cannot be found that matches parameter name 'onlyBaseResources'.if this is related to the powershell commandlets how can I verify that they are installed ?
Free Windows Admin Tool Kit Click here and download it now
March 10th, 2010 4:36pm

If you get to this point, the cmdlets are installed.I verified this - there is no way to manually (de-) install them.If they don't work, there something with your installation broken. In general, the best way to check this is to run one of the "Using PowerShell to" scripts that is based on the cmdlets.The parameter -onlyBaseResource was introduced in Update 3.The error indicates that your system beliefs that is is older than Update 3.Are you sure, you are running the RTM bits?What is the build number of your FIM installation?Cheers,Markus Markus Vilcinskas, Knowledge Engineer, Microsoft Corporation
March 10th, 2010 4:54pm

MarkusSorry I wasn't clear. I'm actualy trying to pull the MV and Prtal schema from our test box, that I believe is RC1 update 1 Version 4.0.2570. So I can rebuild on a new RTM installation. I was plaining on updating it to RC3 and runing your scripts to do the export. It appears that I need update 2 prior to installing update 3. I cant find it anywhere. Can I go from RC1 update 1 straight to RTM ? It appears I have to uninistall the sync service as well as the portal. I do not want to lose all the customizatios. Sorry this probabaly isn't the best stop for this post
Free Windows Admin Tool Kit Click here and download it now
March 11th, 2010 6:23pm

MarkusI successfully upgraded the RC1 to RTM all is good. Sorry for the may questions and any confusionThanks
March 11th, 2010 7:22pm

I had a problem assigning HTA files with the 64-bit mshta engine on Windows 7 computers. For some reason, the operating system has ignored my assignment. While there are probably better ways for doing this, I found a workaround that did at lest the trick for me. The workaround consists of the following registry key: HKEY_CLASSES_ROOT\htafile\Shell\Open\Command Pointing the (Default) value of this key to the 64-bit mshta engine forced Windows to open my HTAs the right way. On my computer, I had to use the following value: C:\Windows\System32\mshta.exe "%1" %* Cheers, MarkusMarkus Vilcinskas, Knowledge Engineer, Microsoft Corporation
Free Windows Admin Tool Kit Click here and download it now
June 2nd, 2010 3:12am

Here is a quick way to check all of your powershell scripts to see if they have the ADS problem: Run this command at the root of where you have downloaded all of the FIM Scriptbox tools dir *.ps1 /r /s The /r will show the ADS files. If they have 0 bytes you are all set if not then you need to run Markus script or try this simple command line for /r %a IN ('dir *.ps1 /b') do type n0n3x1stFile > %a:Zone.Identifier the /r tells the for command to recurse the sub dirs and execute the IN for each subdir and feed that to the do. So run the command after do for each file that matched the IN command for each subdir Using the Type command to redirect a non-existent file to the :ZoneIdentifier file makes it a zero byte file and clears out the data in it If you but this in a batch file or command file replace the %a with %%a in both places. David Lundell
June 22nd, 2010 7:25pm

Thanks, David, this is very cool! It is probably about time to rewrite this article - your solution is much smarter than my lame VBSrcipt... Cheers, Markus Markus Vilcinskas, Knowledge Engineer, Microsoft Corporation
Free Windows Admin Tool Kit Click here and download it now
June 22nd, 2010 8:12pm

Markus- The easiest way to unblock the PowerShell files (because of the ADS) is to fix the zip file before you extract it. After downloading the zip, right click and go to Properties. Towards teh lower right of the property page is an "Unblock" button. Click this and it will zap the ADS. You can then extract it and everything extracted will inherit this.My Book - Active Directory, 4th Edition My Blog -
October 25th, 2010 9:37pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics