I am having some troubles running some simple vb-scripts that do not appear to run from Task Scheduler.
The scheduled task is using the same currently logged-in account, which is a local administrator.
When I tried to run the task from Task Scheduler the status keeps on just running only....but no actions seems to be happen
Here is the code...
Option Explicit
Const ForAppending = 8
Dim objWMIService, objProcess, colProcess, strComputer, strList,strFinalList
Dim strLogFile, strDate, objFSO,objLogFile, strTime, logfile
Dim strUsername,strUserDomain,colProperties,objShell
strDate = Year(Date) & "_" & Month(Date) & "_" & Day(Date)
strTime = Hour(Time) & "_" & Minute(Time) & "_" & Second(Time)
strComputer = "."
strLogFile = "Logs\ExcelLogOff_" & strDate & "_" & strTime & ".log"
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProcess in colProcess
if Trim(objProcess.Name) = "EXCEL.EXE" Then
If objFSO.FileExists(strLogFile) Then
colProperties = objProcess.GetOwner(strUsername,strUserDomain)
Set logfile = objFSO.OpenTextFile(strLogFile, ForAppending)
logfile.WriteLine "User " & strUsername & " is holding Excel File at " & strTime & "."
'logfile.WriteLine "User " & strUsername & " is holding Excel File at " & strTime & "."
Else
colProperties = objProcess.GetOwner(strUsername,strUserDomain)
Set logfile = objFSO.CreateTextFile(strLogFile, True)
logfile.WriteLine "User " & strUsername & " is holding Excel File at " & strTime & "."
End If
logfile.Close
objShell.Run "TASKKILL /F /T /IM " & objProcess.Name, 0, False
objProcess.Terminate()
'logfile.WriteLine "User " & strUsername & " is holding Excel File at " & strTime & "."
WSCript.Echo strUsername
'WSCript.Echo strUserDomain
End If
Next
Set objShell = Nothing
Set objFSO = Nothing
Set objWMIService = Nothing
Set colProcess = Nothing
Set logfile = Nothing
WScript.Quit
Thanks in advance!!!
Regards,
Rohan