Kaseya Community

VBScript will run if logged on locally , but not via an Agent procedure

  • Guys , I'm stumped on this one

    I have a real simple script that writes to a file the current CPU % time

    But if I run it from an Agent procedure it doesn't work. The Machine is a Windows 2003 Server SP2

    I've checked the kworking Folder Permissions ( set them to "everyone" )

    Tried running as User , System etc etc

    It just fails

    The odd thing is it does run on some 2003 Servers , not all.

    So any suggestions ?

    The script I'm using to test is as beow

    **************

    On Error Resume Next

    Dim PreviousCPU, CPUAvg, CPUAverage

    Set ArgObj = Wscript.Arguments
    fileName = ArgObj(0)
    PreviousCPU = ArgObj(1)

    set objFSO=CreateObject("Scripting.FileSystemObject")


    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    strComputer = "."

    Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/CIMV2" )
    Set colInstances = objWMIService.ExecQuery( "SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly )
    For Each objInstance In colInstances
    If ObjInstance.Name = "_Total" Then
    CPUTime = objInstance.PercentProcessorTime
    End If
    Next

    set objFile = objFSO.CreateTextFile(fileName,True)
    CPUAvg = Round((CPUTime / 2 + PreviousCPU / 2),2)
    objFile.Writeline CPUAvg
    objFile.Close

  • I had the same issues with some scripts, that for some reason need admin rights to run.

    Solved it with VBSEdit as a script editor and then convert it into an executable and run the exe instead in the Shell.

    Hope this helps;  btw VBSEdit is from AderSoft ,  you can download a trial