2

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
Root Loop
  • 3,004
  • 9
  • 46
  • 72
  • Issue fixed. must setup [use the following account to run task] as user or user group, I used admin account, it only worked on admin login. – Root Loop Jul 04 '14 at 12:26

1 Answers1

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

Sean W.
  • 863
  • 5
  • 14
  • tried all combo of `cscript` and `wscript` with argument/start in options, error or running without message box....I guess maybe has to setup something for poping up vbs msgbox.... – Root Loop Jul 04 '14 at 02:16
  • Hmm.. maybe right-click on the .vbs file see if it has a maximum execution time set. If it is try and uncheck it if that is even an issue. It is possible. – Sean W. Jul 04 '14 at 02:22
  • 1
    did some search. some ppl say: "You can't use msgbox in a scheduled task. You'll never see it, and there's no timeout on them so the task is probably running with a hidden msgbox on your system." I want to know why.... – Root Loop Jul 04 '14 at 02:28
  • Good point and i see that you are doing x=msgbox but your not actually using x anywhere. since x doesn't really need to be assigned to anything try doing `wscript.echo` instead of x=msgbox see if that helps. – Sean W. Jul 04 '14 at 02:32
  • TASK_LOGON_INTERACTIVE_TOKEN User must already be logged on. The task will be run only in an existing interactive session. in `Principal.LogonType` – Noodles Jul 04 '14 at 02:42
  • @Noodles that has been setup as `run only user log on` in task schedurler, the issue is task running but msbbox wont pop up. – Root Loop Jul 04 '14 at 02:44
  • hmm... last ditch effort answer is maybe try writing to either the standard out or standard error stream as suggested in the least voted answer in this post http://stackoverflow.com/questions/4388879/vbscript-output-to-console – Sean W. Jul 04 '14 at 02:52
  • 1
    @SeanW. use bat file to call vbs it was working only under admin login. I modified my code `x=msgbox ()` became `msgbox xxxx` and setup [run task as user or user group] instead of admin, the vbs now works with task scheduler well for users. the whole point was the account that runs the task. – Root Loop Jul 04 '14 at 12:30