- Mar 13, 2013
- 2
- 0
- 0
VB script is to install a task..
ISSUES
1. should print "SUCCESSFULLY INSTALLED", if its being installed for the first time..
2. if the installation is already done and the script is run again on the same machine it should prompt that "already installed"..
I am new to vbscript, and looking for some assistance....
Please suggest....
Set args = Wscript.Arguments
Dim task_user
Dim action
Dim triggerduration
Dim password
Dim xmlpath
Dim prevarg
task_name = "dautoscheduler"
'task_path = "%ABC_TOOLS%\advapps\dautoscheduler\dautoscheduler.xml"
For Each arg In args
Select Case prevarg
Case "-u"
task_user = "ABCNET\" & arg
Case "-a"
action = arg
Case "-t"
triggerduration = arg
Case "-p"
password = arg
Case "-n"
task_name = arg
Case "-x"
xmlpath = arg
Case else
End Select
prevarg = arg
Next
Set service = CreateObject("Schedule.Service") ' create atask service object.
call service.Connect("localhost")
Set folder = service.GetFolder("\") ' get a folder to create a task definition.
Set TaskDefinition = service.NewTask(0) ' task definition variable is the task definition object
Dim fso,stream,strg
If Not IsBlank(xmlpath) Then
Set fso = CreateObject("Scripting.FileSystemObject") ' create object of the file system object.
Set stream = fs
penTextFile(xmlpath,1,False,-1) ' open file(xmlpath) to read
strg = stream.ReadAll() ' read the file(xmlpath)
stream.Close ' close the file.
Set stream = Nothing
TaskDefinition.XmlText = strg
End If
Dim Actionobj
Dim regInfo
' set the registration info for task by creating the RegistrationInfo object.
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Author = "ABC"
regInfo.Description = "This task is used to schedule dautosetup periodically. dautosetup will launch dautomon and nmsd which will make the machine available to run regression test through dautoc."
if Not IsBlank(triggerduration) Then
Dim triggers
Set triggers = taskDefinition.Triggers
Set trigger = triggers.Create(TASK_TRIGGER_DAILY)
trigger.StartBoundary = triggerduration
trigger.Enabled = True
End If
If Not IsBlank(action) Then
taskDefinition.Actions.Clear()
Set Actionobj = taskDefinition.Actions.Create( 0 )
Actionobj.Path = action
End If
If IsBlank(task_user) and IsBlank(password) Then
call folder.RegisterTaskDefinition(task_name, TaskDefinition,TASK_CREATE_OR_UPDATE, , , TASK_LOGON_NONE)
ElseIf Not IsBlank(task_user) and IsBlank(password) Then
call folder.RegisterTaskDefinition(task_name, TaskDefinition,TASK_CREATE_OR_UPDATE, task_user, , TASK_LOGON_SERVICE_ACCOUNT)
Else
call folder.RegisterTaskDefinition(task_name, TaskDefinition,TASK_CREATE_OR_UPDATE, task_user, password, TASK_LOGON_SERVICE_ACCOUNT)
End If
Function IsBlank(Value)
'returns True if Empty or NULL or Zero
If IsEmpty(Value) or IsNull(Value) Then
IsBlank = True
Exit Function
ElseIf VarType(Value) = vbString Then
If Value = "" Then
IsBlank = True
Exit Function
End If
ElseIf IsObject(Value) Then
If Value Is Nothing Then
IsBlank = True
Exit Function
End If
ElseIf IsNumeric(Value) Then
If Value = 0 Then
IsBlank = True
Exit Function
End If
Else
IsBlank = False
End If
End Function
Function XmlTime(t)
Dim cSecond, cMinute, CHour, cDay, cMonth, cYear
Dim tTime, tDate
cSecond = "0" & Second(t)
cMinute = "0" & Minute(t)
cHour = "0" & Hour(t)
cDay = "0" & Day(t)
cMonth = "0" & Month(t)
cYear = Year(t)
tTime = Right(cHour, 2) & ":" & Right(cMinute, 2) & _
":" & Right(cSecond, 2)
tDate = cYear & "-" & Right(cMonth, 2) & "-" & Right(cDay, 2)
XmlTime = tDate & "T" & tTime
End Function
ISSUES
1. should print "SUCCESSFULLY INSTALLED", if its being installed for the first time..
2. if the installation is already done and the script is run again on the same machine it should prompt that "already installed"..
I am new to vbscript, and looking for some assistance....
Please suggest....
Set args = Wscript.Arguments
Dim task_user
Dim action
Dim triggerduration
Dim password
Dim xmlpath
Dim prevarg
task_name = "dautoscheduler"
'task_path = "%ABC_TOOLS%\advapps\dautoscheduler\dautoscheduler.xml"
For Each arg In args
Select Case prevarg
Case "-u"
task_user = "ABCNET\" & arg
Case "-a"
action = arg
Case "-t"
triggerduration = arg
Case "-p"
password = arg
Case "-n"
task_name = arg
Case "-x"
xmlpath = arg
Case else
End Select
prevarg = arg
Next
Set service = CreateObject("Schedule.Service") ' create atask service object.
call service.Connect("localhost")
Set folder = service.GetFolder("\") ' get a folder to create a task definition.
Set TaskDefinition = service.NewTask(0) ' task definition variable is the task definition object
Dim fso,stream,strg
If Not IsBlank(xmlpath) Then
Set fso = CreateObject("Scripting.FileSystemObject") ' create object of the file system object.
Set stream = fs
strg = stream.ReadAll() ' read the file(xmlpath)
stream.Close ' close the file.
Set stream = Nothing
TaskDefinition.XmlText = strg
End If
Dim Actionobj
Dim regInfo
' set the registration info for task by creating the RegistrationInfo object.
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Author = "ABC"
regInfo.Description = "This task is used to schedule dautosetup periodically. dautosetup will launch dautomon and nmsd which will make the machine available to run regression test through dautoc."
if Not IsBlank(triggerduration) Then
Dim triggers
Set triggers = taskDefinition.Triggers
Set trigger = triggers.Create(TASK_TRIGGER_DAILY)
trigger.StartBoundary = triggerduration
trigger.Enabled = True
End If
If Not IsBlank(action) Then
taskDefinition.Actions.Clear()
Set Actionobj = taskDefinition.Actions.Create( 0 )
Actionobj.Path = action
End If
If IsBlank(task_user) and IsBlank(password) Then
call folder.RegisterTaskDefinition(task_name, TaskDefinition,TASK_CREATE_OR_UPDATE, , , TASK_LOGON_NONE)
ElseIf Not IsBlank(task_user) and IsBlank(password) Then
call folder.RegisterTaskDefinition(task_name, TaskDefinition,TASK_CREATE_OR_UPDATE, task_user, , TASK_LOGON_SERVICE_ACCOUNT)
Else
call folder.RegisterTaskDefinition(task_name, TaskDefinition,TASK_CREATE_OR_UPDATE, task_user, password, TASK_LOGON_SERVICE_ACCOUNT)
End If
Function IsBlank(Value)
'returns True if Empty or NULL or Zero
If IsEmpty(Value) or IsNull(Value) Then
IsBlank = True
Exit Function
ElseIf VarType(Value) = vbString Then
If Value = "" Then
IsBlank = True
Exit Function
End If
ElseIf IsObject(Value) Then
If Value Is Nothing Then
IsBlank = True
Exit Function
End If
ElseIf IsNumeric(Value) Then
If Value = 0 Then
IsBlank = True
Exit Function
End If
Else
IsBlank = False
End If
End Function
Function XmlTime(t)
Dim cSecond, cMinute, CHour, cDay, cMonth, cYear
Dim tTime, tDate
cSecond = "0" & Second(t)
cMinute = "0" & Minute(t)
cHour = "0" & Hour(t)
cDay = "0" & Day(t)
cMonth = "0" & Month(t)
cYear = Year(t)
tTime = Right(cHour, 2) & ":" & Right(cMinute, 2) & _
":" & Right(cSecond, 2)
tDate = cYear & "-" & Right(cMonth, 2) & "-" & Right(cDay, 2)
XmlTime = tDate & "T" & tTime
End Function
Last edited: