Windows task scheduler "run whether user is logged in or not" not working

Viewed 77

I want to send out meeting invites automatically at 00.02 every weekday, so i can book meeting rooms 1 week in advance.

I have made both vbs and powershell scripts that does the job. Only problem is running them automatically. Im trying to use windows scheduler since it got an option for running schedules when im not logged in. But as soon as i enable the "run wether user is logged in or not" option, the scripts dont work anymore and the schedule runs for a verry long time (The scripts does not work if im logged in either, when this option is enabled)

So i got scripts that can do the job, but cant get them to run automatically without beeing logged in on my pc 24/7.

Some of the things i have tried:

  • Give my user “log on as batch job” permission.
  • Create empty desktop folders under System32- and SysWOW64 \config\systemprofile
  • Run as admin
  • Using a vbs script (through the scheduler)
  • Using a powershell script (through the scheduler)
  • Using a c++ windowless program (through the scheduler)
  • Running all 3 of those above throug a .cmd file
  • and a thousand more things i dont even remember anymore

I have read the other posts on here about the same issues, but their solution does not seem to work for me.

The only thing that has worked slightly, was to set task scheduler to run a .cmd file that contained cscript "". When the cscript command is empty, it seems like the task scheduler actualy runs. But as soon as i put a script in the cscript command, its back to square one.

Powershell code

switch((Get-Date).DayOfWeek)
{
    "Monday" { 
        $start = 8, 12
      }

    "Tuesday" { 
        $start = 8
      }

    "Wednesday" { 
        $start = 08, 10, 14
      }

    "Thursday" { 
        $start = 8, 14
      }

    "Friday" { 
        $start = 8, 10
      }

    default{exit}
}

#for loop som sender ut alle møtene for dagen
for ($i = 0; $i -lt $start.Count; $i ++)
{
    $ol = New-Object -ComObject Outlook.Application
    $meeting = $ol.CreateItem('olAppointmentItem')
    $meeting.Subject = 'Grupperom'
    $meeting.Body = 'Ludo'
    $meeting.Location = 'Teknologibygget 1.024 Kollokvierom'
    $meeting.ReminderSet = $true
    $meeting.Importance = 1
    $meeting.MeetingStatus = [Microsoft.Office.Interop.Outlook.OlMeetingStatus]::olMeeting
    $meeting.Recipients.Add('mail@one.com')
    $meeting.ReminderMinutesBeforeStart = 15
    $meeting.Start = [datetime]::Today.Adddays(7).AddHours($start[$i])
    $meeting.Duration = 120
    $meeting.Send()
}
exit

vbs script

Sub SendMeetingRequest()
    Dim objOL   'As Outlook.Application
    Dim objAppt 'As Outlook.AppointmentItem
    Dim MeetingDate

    MeetingDate = DateAdd("d", 7, Date)
    MeetingDate = CDate(MeetingDate & " 08:00:00 AM")

    Set objOL = CreateObject("Outlook.Application")
    Set objAppt = objOL.CreateItem(1)
    With objAppt
        .Subject = "Grupperom auto"
        .Start = MeetingDate
        .End = DateAdd("h", 2, .Start)
         
        ' make it a meeting request
        .MeetingStatus = 1
        .RequiredAttendees = "mail@one.com" 'indicate the email address of the resource mailbox for this
        .Send
    End With
     
    Set objAppt = Nothing
    Set objOL = Nothing
End Sub
SendMeetingRequest
0 Answers
Related