Haw can I execute my VB script in every 5 minutes automatically











up vote
0
down vote

favorite












I write a VB script and I need to run this script as a trigger in every 5 minutes



My code is as follows:



Sub Write_data_record_into_a_table()
'////////////////////////////////////////////////////////////////
' en: The script wirtes the indicated data record into a table
'////////////////////////////////////////////////////////////////



'Declaration of local tags - Deklaration von lokalen Variablen
Dim conn, rst, SQL_Table



On Error Resume Next



Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")



'Open data source - Datenquelle öffnen
conn.Open "Provider=MSDASQL;Initial Catalog=" & SmartTags("szDatabase") & _
";DSN=Database_1"



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



'Select data record of the table - Datensatz der Tabelle auswählen
SQL_Table = "SELECT * FROM "& SmartTags("szTableName") & " WHERE Nr = "& SmartTags("nDat_No") '* = Alle Daten '* = all data



'Writes a data record into a table
Set rst = conn.Execute(SQL_Table)



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



If Not (rst.EOF And rst.BOF) Then
'Compare if "End of File" or "Begin of File" exists, if not the pointer will be reset to the first entry
'Vergleich ob "End of File" oder "Begin of File" ist, wenn nicht wird der Zeiger auf den Ersten Eintrag zurueckgesetzt
ShowSystemAlarm "Dat No. exists already!"
rst.close
Else
'Definition of data record - Definition des Datensatzes
SQL_Table = "INSERT INTO "& SmartTags("szTableName") & " VALUES ('" & SmartTags("nDat_No") & _
"' , '" & SmartTags("cur_Date") & "' , '" & SmartTags("Cur_time") & _
"' , '" & SmartTags("nValue_1") & "' , '" & SmartTags("nValue_2") & _
"' , '" & SmartTags("nValue_3") & "' , '" & SmartTags("nValue_4") & _
"' , '" & SmartTags("nValue_5") & "')"
'Insert the data reacord of the table - Datensatz in die Tabelle hinzufügen
Set rst = conn.Execute(SQL_Table)
End If



'Close data source - Datenquelle schließen
conn.close



Set rst = Nothing
Set conn = Nothing
End Sub










share|improve this question




















  • 2




    Have you tried looking at schtasks.exe: docs.microsoft.com/en-us/windows/desktop/TaskSchd/schtasks
    – Mark
    Nov 29 at 12:50










  • @Mark - Write up an answer for that... tht's the correct way of doing this.
    – Kinnectus
    Nov 29 at 12:53










  • Thank you @Kinnectus . This is a duplicate of superuser.com/questions/80291/…
    – Mark
    Nov 29 at 12:55






  • 2




    Possible duplicate of Run script on Windows every n minutes
    – Mark
    Nov 29 at 12:56















up vote
0
down vote

favorite












I write a VB script and I need to run this script as a trigger in every 5 minutes



My code is as follows:



Sub Write_data_record_into_a_table()
'////////////////////////////////////////////////////////////////
' en: The script wirtes the indicated data record into a table
'////////////////////////////////////////////////////////////////



'Declaration of local tags - Deklaration von lokalen Variablen
Dim conn, rst, SQL_Table



On Error Resume Next



Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")



'Open data source - Datenquelle öffnen
conn.Open "Provider=MSDASQL;Initial Catalog=" & SmartTags("szDatabase") & _
";DSN=Database_1"



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



'Select data record of the table - Datensatz der Tabelle auswählen
SQL_Table = "SELECT * FROM "& SmartTags("szTableName") & " WHERE Nr = "& SmartTags("nDat_No") '* = Alle Daten '* = all data



'Writes a data record into a table
Set rst = conn.Execute(SQL_Table)



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



If Not (rst.EOF And rst.BOF) Then
'Compare if "End of File" or "Begin of File" exists, if not the pointer will be reset to the first entry
'Vergleich ob "End of File" oder "Begin of File" ist, wenn nicht wird der Zeiger auf den Ersten Eintrag zurueckgesetzt
ShowSystemAlarm "Dat No. exists already!"
rst.close
Else
'Definition of data record - Definition des Datensatzes
SQL_Table = "INSERT INTO "& SmartTags("szTableName") & " VALUES ('" & SmartTags("nDat_No") & _
"' , '" & SmartTags("cur_Date") & "' , '" & SmartTags("Cur_time") & _
"' , '" & SmartTags("nValue_1") & "' , '" & SmartTags("nValue_2") & _
"' , '" & SmartTags("nValue_3") & "' , '" & SmartTags("nValue_4") & _
"' , '" & SmartTags("nValue_5") & "')"
'Insert the data reacord of the table - Datensatz in die Tabelle hinzufügen
Set rst = conn.Execute(SQL_Table)
End If



'Close data source - Datenquelle schließen
conn.close



Set rst = Nothing
Set conn = Nothing
End Sub










share|improve this question




















  • 2




    Have you tried looking at schtasks.exe: docs.microsoft.com/en-us/windows/desktop/TaskSchd/schtasks
    – Mark
    Nov 29 at 12:50










  • @Mark - Write up an answer for that... tht's the correct way of doing this.
    – Kinnectus
    Nov 29 at 12:53










  • Thank you @Kinnectus . This is a duplicate of superuser.com/questions/80291/…
    – Mark
    Nov 29 at 12:55






  • 2




    Possible duplicate of Run script on Windows every n minutes
    – Mark
    Nov 29 at 12:56













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I write a VB script and I need to run this script as a trigger in every 5 minutes



My code is as follows:



Sub Write_data_record_into_a_table()
'////////////////////////////////////////////////////////////////
' en: The script wirtes the indicated data record into a table
'////////////////////////////////////////////////////////////////



'Declaration of local tags - Deklaration von lokalen Variablen
Dim conn, rst, SQL_Table



On Error Resume Next



Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")



'Open data source - Datenquelle öffnen
conn.Open "Provider=MSDASQL;Initial Catalog=" & SmartTags("szDatabase") & _
";DSN=Database_1"



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



'Select data record of the table - Datensatz der Tabelle auswählen
SQL_Table = "SELECT * FROM "& SmartTags("szTableName") & " WHERE Nr = "& SmartTags("nDat_No") '* = Alle Daten '* = all data



'Writes a data record into a table
Set rst = conn.Execute(SQL_Table)



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



If Not (rst.EOF And rst.BOF) Then
'Compare if "End of File" or "Begin of File" exists, if not the pointer will be reset to the first entry
'Vergleich ob "End of File" oder "Begin of File" ist, wenn nicht wird der Zeiger auf den Ersten Eintrag zurueckgesetzt
ShowSystemAlarm "Dat No. exists already!"
rst.close
Else
'Definition of data record - Definition des Datensatzes
SQL_Table = "INSERT INTO "& SmartTags("szTableName") & " VALUES ('" & SmartTags("nDat_No") & _
"' , '" & SmartTags("cur_Date") & "' , '" & SmartTags("Cur_time") & _
"' , '" & SmartTags("nValue_1") & "' , '" & SmartTags("nValue_2") & _
"' , '" & SmartTags("nValue_3") & "' , '" & SmartTags("nValue_4") & _
"' , '" & SmartTags("nValue_5") & "')"
'Insert the data reacord of the table - Datensatz in die Tabelle hinzufügen
Set rst = conn.Execute(SQL_Table)
End If



'Close data source - Datenquelle schließen
conn.close



Set rst = Nothing
Set conn = Nothing
End Sub










share|improve this question















I write a VB script and I need to run this script as a trigger in every 5 minutes



My code is as follows:



Sub Write_data_record_into_a_table()
'////////////////////////////////////////////////////////////////
' en: The script wirtes the indicated data record into a table
'////////////////////////////////////////////////////////////////



'Declaration of local tags - Deklaration von lokalen Variablen
Dim conn, rst, SQL_Table



On Error Resume Next



Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")



'Open data source - Datenquelle öffnen
conn.Open "Provider=MSDASQL;Initial Catalog=" & SmartTags("szDatabase") & _
";DSN=Database_1"



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



'Select data record of the table - Datensatz der Tabelle auswählen
SQL_Table = "SELECT * FROM "& SmartTags("szTableName") & " WHERE Nr = "& SmartTags("nDat_No") '* = Alle Daten '* = all data



'Writes a data record into a table
Set rst = conn.Execute(SQL_Table)



'Error routine - Fehler Routine
If Err.Number <> 0 Then
ShowSystemAlarm "Error #" & Err.Number & " " & Err.Description
Err.Clear
Exit Sub
End If



If Not (rst.EOF And rst.BOF) Then
'Compare if "End of File" or "Begin of File" exists, if not the pointer will be reset to the first entry
'Vergleich ob "End of File" oder "Begin of File" ist, wenn nicht wird der Zeiger auf den Ersten Eintrag zurueckgesetzt
ShowSystemAlarm "Dat No. exists already!"
rst.close
Else
'Definition of data record - Definition des Datensatzes
SQL_Table = "INSERT INTO "& SmartTags("szTableName") & " VALUES ('" & SmartTags("nDat_No") & _
"' , '" & SmartTags("cur_Date") & "' , '" & SmartTags("Cur_time") & _
"' , '" & SmartTags("nValue_1") & "' , '" & SmartTags("nValue_2") & _
"' , '" & SmartTags("nValue_3") & "' , '" & SmartTags("nValue_4") & _
"' , '" & SmartTags("nValue_5") & "')"
'Insert the data reacord of the table - Datensatz in die Tabelle hinzufügen
Set rst = conn.Execute(SQL_Table)
End If



'Close data source - Datenquelle schließen
conn.close



Set rst = Nothing
Set conn = Nothing
End Sub







script sql vbscript sql-server-2012






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 29 at 12:51









Dave M

12.7k92838




12.7k92838










asked Nov 29 at 12:43









Trivendra Rajput

1




1








  • 2




    Have you tried looking at schtasks.exe: docs.microsoft.com/en-us/windows/desktop/TaskSchd/schtasks
    – Mark
    Nov 29 at 12:50










  • @Mark - Write up an answer for that... tht's the correct way of doing this.
    – Kinnectus
    Nov 29 at 12:53










  • Thank you @Kinnectus . This is a duplicate of superuser.com/questions/80291/…
    – Mark
    Nov 29 at 12:55






  • 2




    Possible duplicate of Run script on Windows every n minutes
    – Mark
    Nov 29 at 12:56














  • 2




    Have you tried looking at schtasks.exe: docs.microsoft.com/en-us/windows/desktop/TaskSchd/schtasks
    – Mark
    Nov 29 at 12:50










  • @Mark - Write up an answer for that... tht's the correct way of doing this.
    – Kinnectus
    Nov 29 at 12:53










  • Thank you @Kinnectus . This is a duplicate of superuser.com/questions/80291/…
    – Mark
    Nov 29 at 12:55






  • 2




    Possible duplicate of Run script on Windows every n minutes
    – Mark
    Nov 29 at 12:56








2




2




Have you tried looking at schtasks.exe: docs.microsoft.com/en-us/windows/desktop/TaskSchd/schtasks
– Mark
Nov 29 at 12:50




Have you tried looking at schtasks.exe: docs.microsoft.com/en-us/windows/desktop/TaskSchd/schtasks
– Mark
Nov 29 at 12:50












@Mark - Write up an answer for that... tht's the correct way of doing this.
– Kinnectus
Nov 29 at 12:53




@Mark - Write up an answer for that... tht's the correct way of doing this.
– Kinnectus
Nov 29 at 12:53












Thank you @Kinnectus . This is a duplicate of superuser.com/questions/80291/…
– Mark
Nov 29 at 12:55




Thank you @Kinnectus . This is a duplicate of superuser.com/questions/80291/…
– Mark
Nov 29 at 12:55




2




2




Possible duplicate of Run script on Windows every n minutes
– Mark
Nov 29 at 12:56




Possible duplicate of Run script on Windows every n minutes
– Mark
Nov 29 at 12:56















active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1379405%2fhaw-can-i-execute-my-vb-script-in-every-5-minutes-automatically%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1379405%2fhaw-can-i-execute-my-vb-script-in-every-5-minutes-automatically%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Plaza Victoria

In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...