?
Solved

visual basic script

Posted on 2014-10-30
8
Medium Priority
?
475 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 28

Assisted Solution

by:omgang
omgang earned 1000 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 34

Accepted Solution

by:
it_saige earned 1000 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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
 
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 34

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 34

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
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…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 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