Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduling a task through vbscript; getting error 2 (user access)

Status
Not open for further replies.

Stick1337

Programmer
Dec 3, 2008
8
US
This is probably so trivial it's embarrassing, but I'm not sure what to do.

I'll candidly admit I'm worse than a neophyte when it comes to VBScript or any Windows scripting; that said, I've managed to hack my way through some stuff, and it's _mostly_ working like I want: with the following exception:

The script writes a couple of files (including a batch file). These work. Trying to schedule the batch file for repeat execution every day (morning) at 2 a.m. is proving difficult. Here's what I'm working from:

Code:
Sub SheduleTask
Const MONDAY=1, TUESDAY=2, WEDNESDAY=4, THURSDAY=8, FRIDAY=16
strGMTOffset="-000"
Set objNewJob=objWMIService.Get("Win32_ScheduledJob")
objNewJob.Name="copy2docs"
errJobCreated=objNewJob.Create(strCurrentDir & "\c2d.bat", "********020000.000000" & strGMTOffset, _
				True, MONDAY OR TUESDAY OR WEDNESDAY OR THURSDAY OR FRIDAY, , , JobID)
MsgBox errJobCreated
End Sub

When I run my script, the MsgBox spits back "2", which I know means there's a user access problem, but I'm not sure a) where or b) how to solve it.

I'm running things through an HTA file, so I don't know if that could cause the problem or not...

I'd appreciate any help! Thanks!

Also, things like objWMIService, strCurrentDir, etc., are Dim'd elsewhere. Incidentally, strCurrentDir, in this case, equals something like "F:\Users\Username\Blah\
 
Forget it. I just wrote a routine that uses schtasks.exe instead. Seems to be working for the moment!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top