VBScript extension attribute help...

bentoms
Release Candidate Programs Tester

Hi guys,

I'm trying to use the below VBScript to read the state of the windows firewall, yet it's returning that the output is not in the correct <result>output</result> format... even though it seems to be...

Const FOR_READING = 1
const HKEY_LOCAL_MACHINE = &H80000002
const strKeyPath = "SYSTEMCurrentControlSetServicesSharedAccessParametersFirewallPolicyDomainProfile"
const strValueName = "EnableFirewall"

strComputer = "localhost"

On Error Resume Next
Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!" & strComputer & " ootdefault:StdRegProv") oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

if dwValue <> 0 then

WScript.Echo "<result>" & "On" & "</result>" else

WScript.Echo "<result>" & "Off" & "</result>"

end if

However, this one that read the bigfix version works fine...

Dim verNum

Set objFSO = CreateObject("Scripting.FileSystemObject")

besClient = "C:Program FilesBigFix EnterpriseBES ClientBESClient.exe"

if objFSO.FileExists (besClient) then

verNum= objFSO.GetFileVersion (besClient)

WScript.Echo "<result>" & verNum & "</result>"
else vernum= "Not Installed"

WScript.Echo "<result>" & verNum & "</result>"

end if Any ideas?
Ben Toms
IT Support Analyst GREY Group
The Johnson Building, 77 Hatton Garden, London, EC1N 8JS
T: +44 (0) 20-3037-3819 |
Main: +44 (0) 20 3037 3000 | IT Helpdesk: +44 (0) 20 3037 3883

Grey Communications Group Limited
Registered No. 1795794, Registered in England
Registered Office The Johnson Building, 77 Hatton Garden, London, EC1N 8JS
VAT Number GB 404 6245 78

10 REPLIES 10

Not applicable

Stop using Windows????????? : )

I'm sorry, I couldn't resist the temptation.

- JD

talkingmoose
Moderator
Moderator

LOL! I read the message a couple of times and could only assume it was
On 9/8/10 3:59 PM, "James Palmer" <jamespalmer at smsd.org> wrote:
sent to the wrong list.

--

William Smith
Technical Analyst
Merrill Communications LLC
(651) 632-1492

Not applicable

Ok, just cause I feel bad about joking, I'll ask the VBscript guy here
if he knows the answer. I'll post back later with anything helpful he
may have to offer.

- JD

Not applicable

I got this back from our Windows genius. I can't help explain it though.
: )

The code itself looks ok to me and would run ok as long as the registry
key is present. One thing I noticed though is by checking the <> value
of dwValue, it can return an incorrect "Off" state. This can happen if
the key returns unexpected data because the script is simply checking
for one condition. A better method might be to check for a specific on
condition and off condition

(ex:

If dwValue = 1 Then 'or whatever the on value would be

Wscript.echo "<result>" & "On" & "</result>"

Else If dwValue = 0

Wscript.echo "<result> & "Off" & </result>"

Else

Wscript.echo "<result>" & "Unknown Condition" & "</result>"

End If

).

I would suggest checking the service itself as this value would be more
accurate than the registry key. Another thing is WMI sometimes gets
corrupted and doesn't run correctly. In this case you can use a Shell
object to check a registry value instead. I added both examples below:

A possible different way you might recommend is to just check the
service itself:

'This will check the service itself

strComputer = "."

Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!" _

& strComputer & " ootcimv2")

Set GetServices = oWMI.ExecQuery("SELECT * FROM Win32_Service WHERE
Name='SharedAccess'")

For Each Service In GetServices

WScript.Echo "<result>" & Service.State & "</result>"

' Values returned are: "Stopped", "Start Pending", "Stop Pending",

' "Running", "Continue Pending", "Pause
Pending",

' "Paused", "Unknown"

Next

Another way to check Registry key without using WMI as WMI can get
corrupted on some computers:

'This will read registry key without WMI

Set oShell = CreateObject("WScript.Shell")

dwValue = oShell.RegRead("HKLMSYSTEMCurrentControlSetServices" _

& "SharedAccessParametersFirewallPolicy" _

& "DomainProfileEnableFirewall")

if dwValue <> 0 then

WScript.Echo "<result>" & "On" & "</result>"

else

WScript.Echo "<result>" & "Off" & "</result>"

end if

Hope that helps,

I hope that helps too!

- JD

Not applicable

I don’t have any clue about this one either, I don’t know anything about VB. If, and when you get and answer to this, please post it to the Google group (link below) for others to find if needed.

Sean

http://groups.google.com/group/casper-extension-attributes?hl=en

tlarkin
Honored Contributor

power shell is a lot like Unix, but is a separate installer for any non
Windows 7 machine. I have dabbled in it, but never really used it all
that much.

Not applicable

power shell is a lot like Unix, but is a separate installer for any non Windows 7 machine. I have dabbled in it, but never really used it all that much.

We disable PowerShell from running on our machines. There was some security issue where if you allow it to run you couldn’t keep users from running it too or something like that. Might be worth looking into.

- JD

bentoms
Release Candidate Programs Tester

many thanks!

I'l give that a go..

i do feel somewhat dirty playing around with this stuff....

donmontalvo
Esteemed Contributor III

Hi Ben,

I feel for you. :)

http://www.visualbasicscript.com/

Don

--
https://donmontalvo.com

bentoms
Release Candidate Programs Tester

getting there!

No error & works as a VBS, but it doesn't update the JSS either... hmm.. might have to give support a bell..

Dim verNum

Const FOR_READING = 1
const HKEY_LOCAL_MACHINE = &H80000002
const strKeyPath = "SYSTEMCurrentControlSetServicesSharedAccessParametersFirewallPolicyDomainProfile"
const strValueName = "EnableFirewall"

strComputer = "localhost"

Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!" & strComputer & " ootdefault:StdRegProv")

oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

if dwValue = 1 then WScript.Echo "<result>" & "On" & "</result>" else if dwValue = 0 then WScript.Echo "<result>" & "Off" & "</result>" else WScript.Echo "<result>" & "Error" & "</result>" end if

end if