I have a simple vbscript that count the number of files/subfolders in a folder, if the number greater than 5, it will pop up a message to user. I can run this script manually under admin or normal user account, but after I scheduled it in task scheduler as admin, it shows task running, [task started] [action started] [created task process] but it never ends and I never see the message box pops up under user accounts. Is there anything wrong?
Code:
Set filesys = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("Shell.Application")
Set RTMFolder = filesys.GetFolder("C:\work\RTM")
Set PMFolder = filesys.GetFolder("C:\work\Powermill")
Set RTMFiles = RTMFolder.Files
Set PMFiles = PMFolder.SubFolders
NumberOfRTM = RTMFiles.Count
NumberofPM = PMFiles.Count
'Wscript.echo NumberOfRTM
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
If NumberOfRTM >= 5 Then
msgbox "Dear user on " & strComputerName & vbcrlf & " " & vbcrlf & "There are more than 5 RTM files saved on C:\WORK\RTM folder, Please move them to K drive.", &h51000, "Clean up C:\work\RTM"
shell.Open "C:\WORK\RTM"
End If
If NumberofPM >= 5 Then
msgbox "Dear user on " & strComputerName & vbcrlf & " " & vbcrlf & "There are more than 5 Powermill files saved on C:\WORK\Powermill folder, Please Clean it up.", &h51000, "Clean up C:\work\Powermill"
shell.Open "C:\WORK\Powermill"
End If
'Release memory
Set RTMFolder = Nothing
Set PMFolder = Nothing
Set RTMFiles = Nothing
Set PMFiles = Nothing