WMI refresh

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
boomer
Newbie
Posts: 5
Joined: Tue May 01, 2007 12:16 am

WMI refresh

Post by boomer » Sat Aug 11, 2007 3:31 pm

I could use a little help here. I am still new to the MS and not quit sure why when I use wmi code to get status of a service and output to a dialog in macro scheduler it seems to output the function 1 time. After that it can't do it again unless the script is closed and open again. The service I am trying to get is Blackice Firewall service. The refresh button also works great for regular registry reads and updates, just the service status doesn't seem right.

Any help would be appreciated.
Thanks


DA CODE

Dialog>Dialog1
Caption=CheckServices
Width=445
Height=250
Top=CENTER
Left=CENTER
Max=0
Min=0
Close=1
Resize=0
Edit=in01,16,40,119,filein01
Edit=in02,165,40,121,filein02
Edit=in03,146,104,97,folderin01
Button=Proxy OFF,248,72,81,25,5
Button=Proxy ON,336,72,81,25,6
Button=Start BlackICE,248,104,81,25,7
Button=Stop BlackICE,336,104,81,25,8
Button=Refresh Settings,75,168,89,25,10
Button=Launch Access SSL,304,168,113,25,9
Button=Close,184,168,89,25,2
Label=This Script must be run using administrative priveledges!!!!,62,10,true
Label=Current Domain Setting,21,24
Label=Proxy Status Is currently :,16,75
Label=Black ICE is Currently,18,106
Label=Will be changed to :,170,24
Edit=ProxyStatus,146,73,97,Proxy
EndDialog>Dialog1



let>filein01=
let>filein02=DS
let>folderin01=

////Get all the settings before we start
Srt>getstartpoint1
VBSTART
Function getproxy
Dim proxyon,proxyprompt,wshshell
Set wshShell = CreateObject("WScript.Shell")
proxyregpath = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\"
Proxyset = wshShell.Regread (proxyregpath & "Internet Settings\ProxyEnable")
If Proxyset = 1 then proxyprompt = "ON"
If Proxyset = 0 then Proxyprompt = "OFF"
getproxy = proxyprompt
end Function
VBEND
vbeval>getproxy,proxyprompt
wait>.2
Let>proxy=%proxyprompt%
End>getstartpoint1

srt>getstartpoint2
vbstart
Function Getdomain
Dim wshShell,Domain
Set Wshshell = CreateObject("WScript.Shell")
Domainregpath = "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\"
Domain = wshShell.Regread (Domainregpath & "Winlogon\DefaultDomainName")
Getdomain = domain
End Function
vbend
vbeval>getdomain,getdomain
wait>.2
let>filein01=%getdomain%
end>getstartpoint2

srt>getstartpoint3
vbstart
Function Blackice
Dim wshShell,objservice,objWMIService,colServices
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * From Win32_Service Where Name = 'Blackice'")

For Each objService in colServices
intProcessID = objService.State
Blackice = intprocessID
Next
End Function
VBEND
VBEval>blackice,blackice
Wait>.2
let>folderin01=%blackice%
end>getstartpoint3

Wait>.5
Gosub>getstartpoint1
GoSub>getstartpoint2
GoSUB>getstartpoint3


show>dialog1
Label>actionloop
GetDialogAction>Dialog1,r
if>r=2,exit
if>r=5,button1
if>r=6,button2
if>r=7,button3
if>r=8,button4
if>r=9,button6
if>r=10,button6

Wait>.5

////kill proxy, Working
srt>button1
VBSTART
sub Proxykill
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
proxyregpath = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\"
wshShell.RegWrite proxyregpath & "Internet Settings\ProxyEnable",0, "REG_DWORD"
MSGBOX "Proxy turned off. Please refresh screen reflect change",64,"Proxy OFF"
End sub
VBEND
vbrun>Proxykill
Wait>.2
ResetDialogAction>Dialog1
end>button1

////Start proxy,working
srt>button2
VBSTART
sub Proxyenable
Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
proxyregpath = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\"
wshShell.RegWrite proxyregpath & "Internet Settings\ProxyEnable",1, "REG_DWORD"
MSGBOX "Proxy Enabled. Please refresh screen reflect change",64,"Proxy Enabled"
End sub
VBEND
vbrun>Proxyenable
Wait>.2
ResetDialogAction>Dialog1
end>button2

////Start Blackice Service, Working
srt>button3
VBSTART
sub Startblackice
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='Blackice'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='blackice'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
objService.StartService()
Next
end sub
Vbend
Vbrun>startblackice
Wait>3
ResetDialogAction>Dialog1
end>button3

////Kill Blackice service, working
srt>button4
VBSTART
sub killblackice
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='blackice'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For each objService in colServiceList
objService.StopService()
Next
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='blackice'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
end Sub
VBEND
VBrun>Killblackice
Wait>3
ResetDialogAction>Dialog1
end>button4
////not working all the time
Srt>button6

VBSTART
Function getproxy
Dim proxyon,proxyprompt,wshshell
Set wshShell = CreateObject("WScript.Shell")
proxyregpath = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\"
Proxyset = wshShell.Regread (proxyregpath & "Internet Settings\ProxyEnable")
If Proxyset = 1 then proxyprompt = "ON"
If Proxyset = 0 then Proxyprompt = "OFF"
getproxy = proxyprompt
end Function

Function BlackiceR
Dim wshShell,objservice,objWMIService,colServices
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
("Select * From Win32_Service Where Name = 'Blackice'")

For Each objService in colServices
BlackiceR = objService.State
Next
End Function
VBEND
vbeval>getproxy,proxyprompt
vbeval>blackiceR,blackiceR
wait>.2
Let>Dialog1.ProxyStatus=%proxyprompt%
let>Dialog1.in03=%blackiceR%
ResetDialogAction>Dialog1
End>button6
Goto>actionloop
Label>exit

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Aug 11, 2007 4:51 pm

You should declare VBScript functions only ONCE. Call them as many times as you like, but declare them only once.

I always put ONE VBSTART/VBEND block at the VERY TOP of my script. Put the VBScript functions in that, ONCE. Then you can call them as many times as you like.

I'm not sure this is the cause of your issue, but you've got VBScript code declared multiple times which could get redeclared multiple times as you have the VBScript declarations inside subroutines. Therefore you could end up with duplicate functions with the same name.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

boomer
Newbie
Posts: 5
Joined: Tue May 01, 2007 12:16 am

Post by boomer » Sat Aug 11, 2007 5:15 pm

Thanks. I will give it a try.

Would it be better to place the VBcode within the dialog loop at the beginning. Or before I even put in the dialog info?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Aug 11, 2007 5:32 pm

Put the vbscript code right at the very beginning OUTSIDE of ANY loops. The vbscript code is a *declaration*. Functions should be declared ONCE and ONLY once.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

boomer
Newbie
Posts: 5
Joined: Tue May 01, 2007 12:16 am

Post by boomer » Sat Aug 11, 2007 5:52 pm

That did it. Everything is working perfectly.

Thanks

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts