Why vbs msgbox wont work with task scheduler for normal users?

末鹿安然 提交于 2021-02-05 06:35:26

问题


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?

enter image description here


enter image description here


enter image description here


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

回答1:


Try your program/script to be c:\windows\syswow64\cscript.exe or even c:\windows\system32\cscript.exe and then have the argument be c:\path_to_your_vbs\your.vbs



来源:https://stackoverflow.com/questions/24565750/why-vbs-msgbox-wont-work-with-task-scheduler-for-normal-users

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!