[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

repeat script

Posted on 2008-10-09
12
Medium Priority
?
573 Views
Last Modified: 2010-08-05
what code i should add to my vbs file so that after clicking once, it automatically run the complete script after every  1 min.
0
Comment
Question by:ankur3020
[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
  • 6
  • 6
12 Comments
 
LVL 8

Assisted Solution

by:MatthiasVance
MatthiasVance earned 200 total points
ID: 22676456
I provided some sample code, hope it helps you out!

Kind regards,

Matthias Vance
' Timed repeat.vbs
while true
	' Your code here
	WScript.Sleep 60000
loop

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22676519
i tried ur , but giving syntax error. do the required changes in code attached and send back,pls

 
 
Dim oShela, valu
 
Private Function KeyExists (keyName)
	Dim bKey
		
	On Error Resume Next
 
	bKey = oShela.RegRead(keyName)
 
	If TypeName (bKey) = "Empty" Then
		KeyExists = False
	Else
		KeyExists = True
	End If
End Function
 
 
 
Set oShela = CreateObject("Wscript.Shell")
 
If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407") Then
	wscript.echo "Value exists"
 valu = oshela.RegRead( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407" )
	if value <> 1 Then 
	oshela.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407", 0, "REG_DWORD"
			wscript.echo "The value have been changed."
	End If 
Else
	oshell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407", 0, "REG_DWORD" 
			 
 
 
End If

Open in new window

0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22676539
Sorry, it is while..wend. The following code should work.

Kind regards,

Matthias Vance
Dim oShela, valu
 
Private Function KeyExists (keyName)
        Dim bKey
                
        On Error Resume Next
 
        bKey = oShela.RegRead(keyName)
 
        If TypeName (bKey) = "Empty" Then
                KeyExists = False
        Else
                KeyExists = True
        End If
End Function
 
 
Set oShela = CreateObject("Wscript.Shell")
 
while true 
	If keyExists("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407") Then
        wscript.echo "Value exists"
		value = oshela.RegRead( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407" )
        if value <> 1 Then 
			oshela.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407", 0, "REG_DWORD"
			wscript.echo "The value have been changed."
        End If 
	Else
        oshell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1407", 0, "REG_DWORD" 
    End If
wend

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22676549
I posted too quickly, you also need to add 'WScript.Sleep 60000' just before the 'wend'.
0
 

Author Comment

by:ankur3020
ID: 22676654
it worked.

now note in my script there are so many function running one after other then should i place this code in all functions or at the beginning and end of complete script after end statement. so that full script run

ALSO IN CASE I WANT TO STOP RUNNING SCRIPT WHAT SHOULD I DO OTHER THAN LOG OFF.
0
 
LVL 8

Accepted Solution

by:
MatthiasVance earned 200 total points
ID: 22676901
You should only place that part of your code inside it that you want to loop. No functions or subs need to be in it, and no initialization needs to be done there. Only the code that defines what the program *really* does. I attached a commented example.

Also, there are multiple ways of exiting the endless loop. One is to use 'exit do' if a certain condition is met, as you can see in the example. Or if you just want to end it, you could kill the wscript.exe process.

Kind regards,

Matthias Vance
' Methods go here
sub test()
	' test method
end sub
 
' initialization goes here
i = 0
obj = CreateObject("null")
 
' Code that should be looped should go here
do while true
	MsgBox i
	i = i + 1
	if i = 2 then
		exit do ' Exit the loop, and end the script
	end if
	WScript.Sleep 1000
loop

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22679773
dear pls note the want to repeat complete script. from top to last line. i try to add while true and top and wscript sleep command at bottom followed by wend, it is giving syntax error. what should i do.
0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22680497
I thought you got the code in my second post working? If not, please reply with a copy of your code attached, and I will correct it.

Kind regards,

Matthias Vance
0
 

Author Comment

by:ankur3020
ID: 22691995
sample code given below.  as per attached layout pls guide. i want the complete code should run in loop.from top to bottom.

i tried to make new sub at begining and trying to end it at end but this is giving error with sub that i have created in between.
dim f,d,
create object
select statement start
case 1:
code here
case 2:
declaration of variables
code for verifying different conditions using if 
sub d
code
end sub
code to add registry as per out put of if statement.
private sub declaration
if statement
end select

Open in new window

0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22693406
Could you please post your full code instead of this sample code, because it's rather hard to see what belongs where.
Kind regards,
Matthias Vance
0
 

Author Comment

by:ankur3020
ID: 22738728
i tried and got the way to run loop as per ur guidance. thanks
0
 

Author Closing Comment

by:ankur3020
ID: 31504568
thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

649 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