Solved

visual basic script

Posted on 2014-10-30
8
407 Views
Last Modified: 2014-10-30
I am about as new to scripting as you can get, however, I am encouraged that I think I can follow pretty well what a script is trying to do. So I found the follow script which is supposed to get the version of IE it reads as follows.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & _
    "\root\cimv2\Applications\MicrosoftIE")

Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_Summary")

For Each strIESetting in colIESettings
    Wscript.Echo strIESetting.Version
Next

So I think what is happening is, the first line sets the variable strComputer, then objWMIService is set using the command GetObject from the path \\computername\root\cim2\Application\MicrosoftIE
Then colIESettings is set to everything gathered from MicroSoftIE_Summary
lastly each thing is displayed from StrIESetting.Version

If that is correct, I don't understand why when I run the script on my PC I get a Windows Script Host error at
line 2, Char 1 error 0x8004100E code 8004100E Source (null)
Any ideas what I am doing wrong?
0
Comment
Question by:JeffBeall
  • 3
  • 3
  • 2
8 Comments
 
LVL 28

Assisted Solution

by:omgang
omgang earned 250 total points
ID: 40413321
Apparently the namespace \root\cimv2\applications\microsoftie_summary was removed in Windows Vista and later.  That's why it's not working on your Windows 7 machine.
OM Gang
0
 
LVL 28

Expert Comment

by:omgang
ID: 40413333
See this PAQ for a sample of a script that you can use to get IE version.
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26761987.html

OM Gang
0
 
LVL 32

Accepted Solution

by:
it_saige earned 250 total points
ID: 40413341
You are getting this error because Microsoft removed the MicrosoftIE namespace from the WMI namespaces starting with Windows Vista.

So instead we have to settle for querying the registry:
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Internet Explorer"
strValueName = "Version"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
Wscript.Echo "Installed IE Version: " & strValue & VBCRLF & "IE Version: " & Left(strValue,1)

Open in new window


-saige-
0
 
LVL 1

Author Comment

by:JeffBeall
ID: 40413657
a-ha, so that's want is going on! I have two more questions then, first, because this happened, I was wondering, is there a way to list what is in the WMI namespace?
and 2nd does strComputer= "." mean it is looking on the computer that the script is running on? if so, would I be able to have this run on a remote computer using something like
strComputer="remotecomputername"
also - just to be sure I'm on the right page, strComputer is just a variable, correct? I could use
bob="."
if I wanted to. Not that I would, just making sure I have this correct.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 28

Expert Comment

by:omgang
ID: 40413713
Not sure about enumerating the WMI namespace.

Yes, strComputer="." means the local machine.

Yes, it's possible to run the script against another machine by changing the value assigned to strComputer.

Yes, strComputer is variable and could be replaced by almost anything.  By convention, many choose to preface variables with the intended data type, e.g. strComputer for a String data type variable, intCounter for an integer type variable, etc.  It helps when reading code.  In vbscript, however, all variables are actually Variant data types so it's possible for strComputer to get assigned a value of 297.

OM Gang
0
 
LVL 32

Expert Comment

by:it_saige
ID: 40413715
Yes you can list what is in the WMI namespace.
' List All WMI Namespaces

strComputer = "."
Call EnumNameSpaces("root")
 
Sub EnumNameSpaces(strNameSpace)
    WScript.Echo strNameSpace
    Set objWMIService=GetObject _
        ("winmgmts:{impersonationLevel=impersonate}\\" & _ 
            strComputer & "\" & strNameSpace)

    Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")

    For Each objNameSpace In colNameSpaces
        Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
    Next
End Sub

Open in new window


Yes, strComputer is a variable (you could use bob).
Yes, the value for strComputer, ".", refers to the local computer.  It's the same as using:
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2\Applications\MicrosoftIE")

Open in new window


For running on a remote computer you would have to use the remote computer name as you indicated.

-saige-
0
 
LVL 32

Expert Comment

by:it_saige
ID: 40413772
Ofcourse a better version of the above script does not use seperate echo's for each namespace:
' List All WMI Namespaces


strComputer = "."
strNamespaces = EnumNameSpaces("root")
wscript.echo strNamespaces
 
Function EnumNameSpaces(strNameSpace)
	EnumNameSpaces = EnumNameSpaces & strNamespace & VBCRLF
	Set objWMIService=GetObject _
		("winmgmts:{impersonationLevel=impersonate}\\" & _ 
		strComputer & "\" & strNameSpace)

	Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")

	For Each objNameSpace In colNameSpaces
		EnumNameSpaces = EnumNameSpaces & EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
	Next
End Function

Open in new window


-saige-
0
 
LVL 1

Author Closing Comment

by:JeffBeall
ID: 40414011
awsome, thanks for the namespace thing. you must really know scripting. some day i hope to be able to write my own scripts.
now I just have to try and have the script that shows the IE version output the versions of IE from a list of computers. but I think that's outside this question.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of the features I've come to appreciate about Windows 7 and Windows Server 2008 R2 is the ability to pin applications to the task bar. As useful a feature as I've found this, it does have some quirks.  For example, have you ever tried pinning an…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now