R
Rob Oldfield
I have a pretty straightforward app that's designed to take entries from a
database and create a Word template containing AutoText entries using those
entries. A basic outline of the code is below.
If I run it manually then everything works fine. But the idea is that it
runs overnight and....
If I set it up as a scheduled task (Win 2K server, running as a user that
has full domain admin rights) then it works the first time, but second and
later I get a "Task could not start" error and the following in the task
scheduler log.
"The attempt to log on to the account associated with the task failed,
therefore, the task did not run.
The specific error is:
0x80070569: Logon failure: the user has not been granted the requested logon
type at this computer.
Verify that the task's Run-as name and password are valid and try again."
If I then set the job up again (i.e. reinput the path to the exe and enter
the user name and password), then the same thing happens. First time fine,
next time clunk. I figure that the rights issue error message must be wrong
otherwise how could it run successfully the first time.
To try and separate what exactly was going wrong I also took all of my code
and put it into a subroutine, changed the load code to just enable a timer,
and called my main subroutine from the timer elapsed event. Same thing
happens.
I appreciate that this may not be the best newsgroup for this question, but
nobody on win2000.general had a clue.
Any ideas?
.....and the code which is in the load event of my one form (simplified
version, but containing everything that I'm doing)....
Dim Pth As String
AddressEventLog.WriteEntry("Starting") 'when it fails, nothing is written
to the log
Pth =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssem
bly.Location) + "\"
'OrigTemplate is just a dot with a bookmark named bmark in it
FileCopy(Pth + "OrigTemplate.dot", Pth + "NewTemplate.dot")
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTemp As Word.Template
Dim oRange As Word.Range
Dim addr As String
oWord = CreateObject("Word.Application")
oWord.Visible = False
oDoc = oWord.Documents.Add(Pth + "NewTemplate.dot")
oTemp = oWord.ActiveDocument.AttachedTemplate
oRange = oDoc.Bookmarks.Item("bmark").Range
Dim i As Integer, cd As String, dr as datarow
PortAddDA.Fill(PortAddDS1)
For Each dr In PortAddDS1.Tables("Addresses").Rows
addr = ""
cd = dr.Item("Code"))
oTemp.AutoTextEntries.Add(cd, oRange)
addr += dr.Item("Client") + vbCrLf + dr.Item("Address")
oTemp.AutoTextEntries.Item(cd).Value = addr
Next
oRange = Nothing
oTemp = Nothing
CType(oDoc, Word._Document).Close()
oDoc = Nothing
CType(oWord, Word._Application).Quit()
oWord = Nothing
FileCopy(Pth + "NewTemplate.dot",<Target location(s) on network>)
GC.Collect()
Me.Close()
database and create a Word template containing AutoText entries using those
entries. A basic outline of the code is below.
If I run it manually then everything works fine. But the idea is that it
runs overnight and....
If I set it up as a scheduled task (Win 2K server, running as a user that
has full domain admin rights) then it works the first time, but second and
later I get a "Task could not start" error and the following in the task
scheduler log.
"The attempt to log on to the account associated with the task failed,
therefore, the task did not run.
The specific error is:
0x80070569: Logon failure: the user has not been granted the requested logon
type at this computer.
Verify that the task's Run-as name and password are valid and try again."
If I then set the job up again (i.e. reinput the path to the exe and enter
the user name and password), then the same thing happens. First time fine,
next time clunk. I figure that the rights issue error message must be wrong
otherwise how could it run successfully the first time.
To try and separate what exactly was going wrong I also took all of my code
and put it into a subroutine, changed the load code to just enable a timer,
and called my main subroutine from the timer elapsed event. Same thing
happens.
I appreciate that this may not be the best newsgroup for this question, but
nobody on win2000.general had a clue.
Any ideas?
.....and the code which is in the load event of my one form (simplified
version, but containing everything that I'm doing)....
Dim Pth As String
AddressEventLog.WriteEntry("Starting") 'when it fails, nothing is written
to the log
Pth =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssem
bly.Location) + "\"
'OrigTemplate is just a dot with a bookmark named bmark in it
FileCopy(Pth + "OrigTemplate.dot", Pth + "NewTemplate.dot")
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTemp As Word.Template
Dim oRange As Word.Range
Dim addr As String
oWord = CreateObject("Word.Application")
oWord.Visible = False
oDoc = oWord.Documents.Add(Pth + "NewTemplate.dot")
oTemp = oWord.ActiveDocument.AttachedTemplate
oRange = oDoc.Bookmarks.Item("bmark").Range
Dim i As Integer, cd As String, dr as datarow
PortAddDA.Fill(PortAddDS1)
For Each dr In PortAddDS1.Tables("Addresses").Rows
addr = ""
cd = dr.Item("Code"))
oTemp.AutoTextEntries.Add(cd, oRange)
addr += dr.Item("Client") + vbCrLf + dr.Item("Address")
oTemp.AutoTextEntries.Item(cd).Value = addr
Next
oRange = Nothing
oTemp = Nothing
CType(oDoc, Word._Document).Close()
oDoc = Nothing
CType(oWord, Word._Application).Quit()
oWord = Nothing
FileCopy(Pth + "NewTemplate.dot",<Target location(s) on network>)
GC.Collect()
Me.Close()