I have written a .vbs script which presently is run manually by users. How can I make this script schedule itself in Task Scheduler (to run at a fixed time each day automatically) on Windows XP and Windows 7 the first time it is executed manually?
EDIT
Option Explicit
Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
Dim FSO : set FSO = CreateObject("Scripting.FileSystemObject")
Dim StartTime,Elapsed
'msgBox(oShell.CurrentDirectory)
'MsgBox(FSO.GetFile(Wscript.ScriptFullName).ParentFolder )
oShell.CurrentDirectory = FSO.GetFile(Wscript.ScriptFullName).ParentFolder
StartTime = Timer
oShell.run "ParentChildLinkFinal.vbs", 1, True
oShell.run "Parent_Child_Merge_final.vbs", 1, True
oShell.run "CycleTime.vbs", 1, True
oShell.run "Baddata.vbs", 1, True
oShell.run "Matrixrefresh.vbs", 1, True
Elapsed = Timer - StartTime
MsgBox("Total time taken to finish this task:" & Elapsed & "in Seconds")
Thanks,
Create a scheduled task to run the following command:
c:\windows\system32\cscript.exe PATH_TO_YOUR_VBS
You can certainly make a vbs file a scheduled task.
The caveat, though, is you want NOTHING to prompt the user...no inputs, no message boxes, nothing. Make sure you've handled and logged your exceptions or you could find yourself with a task that never completes (or worse, operations angrily calling you because a message box popped up at 3am and halted a production process)
on Windows 8: windows tasks that are triggering VBScripts having message boxes will only display the message boxes if the windows task is run under the same user who really is logged on the machine and the if the windows task is configured to "run only if the user is logged on"
I think this changed on windows 8, as on windows 7 I did not had to configure the task in that way
try this
X=MsgBox("Take the Quiz!")
name=inputbox("Name")
q1=inputbox("Question 1 - How many days are there in a leap Year?")
q2=inputbox("Question 2 - How many Suns does Neptune have?")
q3=inputbox("Question 3 - What is your name?")
q4=inputbox("Question 4 - What did one computer say to the other?")
q5=inputbox("Question 5 - Why did the chicken cross the road?")
msgbox("Answers!")
msgbox("Q1 - How many days are there in a leap Year?, you answered ") + q1 + (" ,the correct answer is 366")
msgbox("Q2 - How many Suns does Neptune have?, you answered ") + q2 + (" ,the correct answere is one, our sun.")
msgbox("Q3 - What is your name?, you answered ") + q3 + (", the correct answer is ") + name + (" or is it?")
msgbox("Q4 - What did one computer say to the other?, you answered ") + q4 + (", the correct answer is, 011100110111010101110000 (Binary code for sup)")
msgbox("Q5 - Why did the chicken cross the road?, you answered ") + q5 + (", the correct answer is To get to the other side")
msgbox("Well done, ") + name + (" you have completed the quiz")
Related
This question already has answers here:
How do you display a message using VBScript (VBS), without causing an error?
(2 answers)
Closed 5 months ago.
How do I check if I click on a button in a MsgBox?
x = msgbox("Test", 0+16, "Test")
I meant check, not how to make a message box!
Use:
x = msgbox("Test", 0+16, "Test")
if x = number then
msgbox("Hello, World!")
end if
instead of the "number" in the if statement, write the number corresponding with the button that you want to check if pressed. Here are the numbers that you can write:
1 - ok; 2 - cancel; 3 - abort; 4 - retry; 5 - ignore; 6 - yes; 7 - no
You should learn VBScript programming from the ground up.
VBScript Basics, Part 1 | Message Box - Numbers (MsgBox)
VBScript Basics, Part 2 | Message Box - Constants (MsgBox)
VBScript Basics, Part 3 | If - ElseIf - Else - Then Statements
All Vbscript Tutorial Playlist
Here is an example:
Dim AnswerQuestion, Msg, Title
Title = "Answer the question?"
Msg = "Do you like cookies??" & Vbcr &_
"If yes, then click the [YES] button " & Vbcr &_
"If not, then click the [NO] button"
AnswerQuestion = MsgBox(Msg, VbYesNo + VbQuestion, Title)
If AnswerQuestion = VbYes Then
MsgBox "You clicked on the OK button. Good, you're off the hook!", vbInformation, Title
Else
MsgBox "You clicked on the No button! and you're going to jail!", VbCritical, Title
End if
I have written a .vbs script which presently is run manually by users. How can I make this script schedule itself in Task Scheduler (to run at a fixed time each day automatically) on Windows XP and Windows 7 the first time it is executed manually?
EDIT
Option Explicit
Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
Dim FSO : set FSO = CreateObject("Scripting.FileSystemObject")
Dim StartTime,Elapsed
'msgBox(oShell.CurrentDirectory)
'MsgBox(FSO.GetFile(Wscript.ScriptFullName).ParentFolder )
oShell.CurrentDirectory = FSO.GetFile(Wscript.ScriptFullName).ParentFolder
StartTime = Timer
oShell.run "ParentChildLinkFinal.vbs", 1, True
oShell.run "Parent_Child_Merge_final.vbs", 1, True
oShell.run "CycleTime.vbs", 1, True
oShell.run "Baddata.vbs", 1, True
oShell.run "Matrixrefresh.vbs", 1, True
Elapsed = Timer - StartTime
MsgBox("Total time taken to finish this task:" & Elapsed & "in Seconds")
Thanks,
Create a scheduled task to run the following command:
c:\windows\system32\cscript.exe PATH_TO_YOUR_VBS
You can certainly make a vbs file a scheduled task.
The caveat, though, is you want NOTHING to prompt the user...no inputs, no message boxes, nothing. Make sure you've handled and logged your exceptions or you could find yourself with a task that never completes (or worse, operations angrily calling you because a message box popped up at 3am and halted a production process)
on Windows 8: windows tasks that are triggering VBScripts having message boxes will only display the message boxes if the windows task is run under the same user who really is logged on the machine and the if the windows task is configured to "run only if the user is logged on"
I think this changed on windows 8, as on windows 7 I did not had to configure the task in that way
try this
X=MsgBox("Take the Quiz!")
name=inputbox("Name")
q1=inputbox("Question 1 - How many days are there in a leap Year?")
q2=inputbox("Question 2 - How many Suns does Neptune have?")
q3=inputbox("Question 3 - What is your name?")
q4=inputbox("Question 4 - What did one computer say to the other?")
q5=inputbox("Question 5 - Why did the chicken cross the road?")
msgbox("Answers!")
msgbox("Q1 - How many days are there in a leap Year?, you answered ") + q1 + (" ,the correct answer is 366")
msgbox("Q2 - How many Suns does Neptune have?, you answered ") + q2 + (" ,the correct answere is one, our sun.")
msgbox("Q3 - What is your name?, you answered ") + q3 + (", the correct answer is ") + name + (" or is it?")
msgbox("Q4 - What did one computer say to the other?, you answered ") + q4 + (", the correct answer is, 011100110111010101110000 (Binary code for sup)")
msgbox("Q5 - Why did the chicken cross the road?, you answered ") + q5 + (", the correct answer is To get to the other side")
msgbox("Well done, ") + name + (" you have completed the quiz")
Currently I'm using IE 11, I have 4 displays opened. I want to toggle between the tabs for specific intervals of time. We want this setup for monitoring purpose. I need a script for this task.
Kindly refer the following code :
set shellApp = createobject("shell.application")
do
for each sTitle in Array("v9", "Google", "Gmail", "ETC")
ShowIEWindow sTitle, shellApp, 10 ' sec
next
loop ' forever
sub ShowIEWindow(sTitle, oShell, nWaitsec)
for each w in oShell.windows
with w
if lCase(.LocationName) = lcase(sTitle) and InStr(lCase(.FullName),"iexplore") > 0then
w.Refresh
'w.visible = true ' show
wsh.sleep nWaitsec * 1000 ' milliseconds
' w.visible = false ' hide
end if
end with
next
end sub
Above code will refresh tabs that specified in the array if they are opened in internet explorer.
Now, instead of Refreshing the window, you need to find method that switches between different tabs.
I also tested the above code and working for me. Hope this will helps !! :)
I am new to vb express and looking for a way to read two lines in a text file get the difference between then and loop it till the end its a simple clock in clock out system which store each persons clock on and off time in a text file like so
03/11/2014 09:55:02
03/11/2014 14:55:02
03/11/2014 16:55:02
03/11/2014 19:55:02
04/11/2014 09:00:02
04/11/2014 13:00:00
I know I use the DateDiff to get the time but I only want them to work out the difference between line 1 and 2 then 3 and 4 and add them all up is it possible to do that without over complicating things?
I guys I have worked it out I have done this by reading the text filed line by line in a loop at the moment I have not put any validation in to show people who have forgot but the basics are there
Dim FILE_NAME As String = "times\08.txt"
Dim start As DateTime
Dim finish As DateTime
Dim total
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Do While objReader.Peek() <> -1
start = objReader.ReadLine() & vbNewLine
finish = objReader.ReadLine() & vbNewLine
duration = DateDiff(DateInterval.Minute, start, finish)
total = duration + total
Loop
Label2.Text = total
Ok, so I have been given the task to create a script that can increase or decrease the volume. My problem is when I run it, and type in "Decrease" then type in "29" it goes down to 0 then starts to loop. Can you please tell me where the loop is and how to fix it?
set Keys = CreateObject("WScript.Shell") 'So The Script Can Simulate Key Presses
set oShell = CreateObject("WScript.Shell") 'So The Script Can Control The Master Volume
'Asks The User If They Wish To Increase Or Decrease The Volume
Answer = InputBox("Increase Or Decrease Volume?", "Increase/Decrease Volume:")
If Answer = "Increase" Then 'If The User Types In Increase The Following Happens
'Runs The Master Volume App.
oShell.run"%SystemRoot%\System32\SndVol.exe"
'Stops The Program For # Milliseconds
WScript.Sleep 1500
'Asks How Much To Increase The Volume By
Amount = InputBox("How Much Do You Want To Turn The Volume Up?", "Increment:")
'Pushes the Up Arrow Key The Amount Of Which The User Entered
For X = 0 To Amount Step 1
'Simulates The Pushing Of The Up Arrow
Keys.SendKeys("{Up}")
X =+ 1 'Counter Increment
Next
ElseIf Answer = "Decrease" Then 'If The User Types In Decrease The Following Happens
'Runs The Master Volume App.
oShell.run"%SystemRoot%\System32\SndVol.exe"
'Stops The Program For # Milliseconds
WScript.Sleep 1500
'Asks How Much To Decrease The Volume By
Amount = InputBox("How Much Do You Want To Turn The Volume Down?", "Decrement:")
'Pushes the Down Arrow Key The Amount Of Which The User Entered
For X = 0 To Amount Step 1
'Simulates The Pushing Of The Down Arrow
Keys.SendKeys("{Down}")
X =+ 1 'Counter Increment
Next
ElseIf Answer = "" Then 'If The User Pushes Cancel The Following Happens
Question = MsgBox("Do You Wish To Quit?",vbYesNo,"Quit:")
'If The User Pushes Yes Then The Script Will End
If Question = vbYes Then
WScript.Quit 0 'Stops The Script
End if
Else
MsgBox("The Values Allowed Are:" & vbNewLine & "Increase" & vbNewLine & "Decrease")
End If
Does VBScript have Increment Operators
X = X + 1 is the proper way of achieving what you're trying to do with X =+ 1 (which may just be setting X to 1 over and over again). In your usage however, you can take those lines out completely since the For X = 0 To Amount Step 1 should already be handling the increment for you.
There is no =+ (add and assign) operator in VBScript. Your
X =+ 1 'Counter Increment
is seen as
X = +1 ' assign +1 to X
Evidence:
>> X = 10
>> X =+ 1
>> WScript.Echo X
>>
1
You should delete those lines as the loop variable in a For To statement updates automagically.