Life of a Geek Admin

The Daily adventures of a true geek administrator

Life of a Geek Admin - The Daily adventures of a true geek administrator

Can’t find script engine “VBScript” for script error on Windows 7 and Windows 2008

We had recently received an error when upgrading a product and the script used for the upgrades was VBScript. When running the script there was a few systems that displayed the following error.

“Can’t find script engine “VBScript” for script “<path to script>”

vbscripterr

Upon doing a bit of digging I found that most times this error is resolved by re-registering the vbscript.dll. We ran the following commands.

  1. Click on start button, type cmd. In the search result right-click on cmd and selectRun as administrator.
  2. Type cd %windir%\system32 and press enter.
  3. Type regsvr32 vbscript.dll in command prompt and press enter.

If the registration was successful, you should now see the following message:
DllRegisterServer in vbscript.dll succeeded.

On some of the servers this fixed the issue and scripts ran again. On the systems that still didn’t work did a bit more digging and found that a recent McAfee upgrade changed a registry key for vbscript. Here’s how to correct it.

  1. On the problem machine, log in as an administrator.
  2. Open the registry editor (regedit.exe) and navigate to the following registry key.[HKEY_CLASSES_ROOT\CLSID\{B54F3741-5B07-11cf-A4B0-00AA004A55E8}\InprocServer32]
  3. check the path of the Default registry key, it will most likely point to the path of your Anti-Virus Product.
  4. Right click on InprocServer32 and select permissions. Give the Administrators group full access.
  5. Then Modify the Default registry key and change the path to C:\Windows\system32\vbscript.dll
  6. Change the permission back.

vbscripterr3

After making the change vbscript’s started running again!!

 

Perform In-Place file edit with VBScript

Recently had the need to search and replace a configuration file on a system. This was part of an installation of an older program that required a variable to be replace with the computername. Being that the systems were Windows of several different releases (2000, 2003 and 2008) I could not use Powershell to complete the task and went with vbscript as the tool of choice.

Here is what the script looks like. In this example I am editing the config.ini file and looking for WIN01 and replacing it with the computername.

Const ForReading = 1
Const ForWriting = 2
Const FileIn = "c:\oldasdirt\bin\config.ini"
Const FileOut = "c:\oldasdirt\bin\config.ini" 

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileIn, ForReading)
Set wshShell = WScript.CreateObject( "WScript.Shell" )

strComputer =wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "WIN01", strComputer)

Set objFile = objFSO.OpenTextFile(FileOut, ForWriting)
objFile.WriteLine strNewText
objFile.Close

The script can be broken done into several sections.

  • define constants
  • set objects
  • set variables
  • do the work
  • close it up

For define constants we need to define the file for Reading and Writing and also define the input and output file.

Const ForReading = 1
Const ForWriting = 2
Const FileIn = "path to input file"
Const FileOut = "path to output file"

There are three File input / output constants available as shown in the table below.

Constant Value Description
ForReading 1 Open a file for reading only. No writing to this file can take place.
ForWriting 2 Open a file for writing. If a file with the same name exists, its previous contents are overwritten.
ForAppending 8 Open a file and write to the end of the file.

For FileIn and FileOut we just need to put the location and name of the file we want to edit.

Next we need to set the file system object , set the File object and set the shell environment.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(FileIn, ForReading)
Set wshShell = WScript.CreateObject( "WScript.Shell" )

Now we want to create a variable called strComputer and get the Environment variable for %COMPUTERNAME%.

strComputer =wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )

Next we need to open the file we want to edit into memory and then create a variable for finding and replacing the replacement text.

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "WIN01", strComputer)

And finally, lets write the changes to the file.

Set objFile = objFSO.OpenTextFile(FileOut, ForWriting)
objFile.WriteLine strNewText
objFile.Close

And that’s all there is to editing a file in place with vbscript. Hope you find this useful to your situation.

 

Disable NetBIOS over TCPIP with vbscript

Part of building new servers I have been creating a script to configure add and remove features added to the Windows 2008 R2 servers. The process is being handled by powershell, command scripts and vbscripts.

Ran into a step to disable the WINS setting for  Disable NetBIOS over TCP/IP.  As with any step in the build process automation is the key to consistent builds and reduce human error. For this part I turned to vbscript and used the following script to execute the step on all the NIC’s defined on the system.

This script will work on Windows 2003 / 2008 servers.

‘ Disable NetBIOS over TCPIP
‘ Author: Mark Harris
‘ disablenetbios.vbs
‘ run as cscript /nologo disablenetbios.vbs

strComputer = “.”
‘ set to HKEY_LOCAL_MACHINE registry Hive
HKLM = 2147483650

‘ Set keyword value to open
valuename = “NetBIOSOptions”
subkey = “System\CurrentControlSet\Services\NetBT\Parameters\Interfaces\”

‘Get registry provider from WMI
set registry = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

‘Get subkeys of Interfaces key … these will be random GUIDs
registry.EnumKey HKLM, subkey, subkeys

for i = 0 to ubound(subkeys)
‘Set hex value of registry value to 0×2. We have to use the built-in VBscript hex function to convert from decimal to hex data type
registry.SetDWORDValue HKLM, subkey & subkeys(i), valuename, hex(2)
next

Search and Delete Files less than 1 hour old with vbscript

Ran into a situation where temporary created files were filling the drives of a Windows 2003 server. So I turned to vbscript and creating a scheduled task to keep the space issue at bay. Here is the script.

' VBscript to delete files older than 1 hour
' directory to delete
' cleanoldfiles.vbs

' change dir variable to directory to target files
sdir="d:\my dir"
dim dt, fso, odir, f
dt=now
set fso=createobject("scripting.filesystemobject")
if fso.folderexists(sdir) then
set odir=fso.getfolder(sdir)
for each f in odir.files
'"n" for minutes, "h" for hours etc, also change "zip" to file extension to look for
if (strcomp(fso.getextensionname(f.name),"zip",1)=0) and (datediff("n",f.datelastmodified,dt)>30) then
f.delete true 'forced
end if
next
set odir=nothing
else
wscript.echo "directory: " & sdir & " not found." & vbcrlf & "operation aborted."
end if
set fso=nothing

The script is pretty simple and can be changed to handles hours and minutes by changing the h and N variables. For under 1 hour times you need to make sure h = 0, this variable is set right after the file extention. Comments are listed in the code example above.

Hope this little script can be as much use for you as it is me.

There is no script engine for file extension “.vbs” error

Being the typical geek I installed software and started seeing There is no script engine for file extension “.vbs” errors. The program installed was NotePad++ on my Windows XP workstation and is an awesome tool for programming and editing in general and not to mention it is free.

Anyway, when the program was installed it took the .vbs extension and vbscripts stopped working and started throwing the error. There is an easy fix.

  • Locate the file %windir%\inf\wsh.inf (inf is a hidden
    folder) so you will have to un-hide it.
  • Right click and select “Install”.

Switch to our mobile site