Has anyone out there been able to submit a job from VBScript and get that job to run? The jobs I submit this way are set to run under NTAuthoritySystem but they fail with the error user does not have authority to run the job. The script checks for a program running (datawise.exe) and if it is it submits the job to run 1 hour later as this script can't run while datawise is running.
Program Follows:
Option Explicit
Dim ObjSendMail Dim WSHShell Dim locator Dim service Dim props Dim num
dim dtmvalue dim objNewJob dim objWMIService dim strComputer dim JobId dim errJobCreate dim HR dim MN dim SC
'Get the files in the polling folder
Set ObjSendMail = CreateObject("CDO.Message") 'Config for SMTP remote mail server section ObjSendMail.Configuration.Fields.Item ("
http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send
the message using the network (SMTP over network) ObjSendMail.Configuration.Fields.Item ("
http://schemas.microsoft.com/cdo/configuration/smtpserver") =
"mail.markettransport.com" ObjSendMail.Configuration.Fields.Item ("
http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 ObjSendMail.Configuration.Fields.Item ("
http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Use SSL for connection (True/False) ObjSendMail.Configuration.Fields.Item ("
http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")
= 60 ObjSendMail.Configuration.Fields.Update
'**** check if datawise is already running ********************************************************** Set WshShell = WScript.CreateObject("WScript.Shell")
Set locator = CreateObject("WbemScripting.SWbemLocator") Set service = locator.ConnectServer() Set props = service.ExecQuery("select name, description from Win32_Process where name = 'datawise.exe'") num = props.Count
If num > 0 Then 'Program is running we can't run now ObjSendMail.TO = "
chestnuttr@sammonstrucking.com" ObjSendMail.Subject = "ERROR--Datawise is already running ST.VBS script can't run now!" ObjSendMail.From = "
Sammons@sammonstrucking.com" ObjSendMail.Send 'Set ObjSendMail = Nothin
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\" _ & strComputer & "rootcimv2")
'************************************* dtmvalue = Now() If Hour(dtmvalue) > 9 Then HR = CStr(Hour(dtmvalue)) Else HR = "0" + CStr(Hour(dtmvalue)) End IF If Minute(dtmvalue) > 9 Then MN = CStr(Minute(dtmvalue)) Else MN = "0" + CStr(Minute(dtmvalue)) End IF If Second(dtmvalue) > 9 Then SC = CStr(Second(dtmvalue)) Else SC = "0" + CStr(Second(dtmvalue)) End IF JobID = "Settlement Process" Set objNewJob = objWMIService.Get("Win32_ScheduledJob") errJobCreate = objNewJob.Create _ ("V:DataDocsPaperWiseSettlementsST.vbs", "********" &HR &MN &SC& + ".000000-480", _ True , 0 , ,True, JobId) If errJobCreate = 0 Then 'Job created successfully! ObjSendMail.TO = "
chestnuttr@sammonstrucking.com" ObjSendMail.Subject = "Settlement Job ST.VBS has been submitted 1 hour from now!" ObjSendMail.From = "
Sammons@sammonstrucking.com" ObjSendMail.Send 'Set ObjSendMail = Nothin End If
'********************************** 'End the current job at this point!!!! wscript.quit Else 'Program is not running we can go ahead now ObjSendMail.TO = "
chestnuttr@sammonstrucking.com" ObjSendMail.Subject = "Datawise is ok to proceed now!" ObjSendMail.From = "
Sammons@sammonstrucking.com" ObjSendMail.Send 'Set ObjSendMail = Nothin End If
Set WSHShell = Nothing
'*************** end check for Datawise running *****************************************************
Software/Hardware used:
WinXP WSScript