6 Replies Latest reply on Dec 2, 2008 3:21 AM by ahe

    VBS script doesn't work when started by LANDesk

    Rookie

      I have a VBS script which if a logged in users runs it, it works fine. But when I deploy and run it on a workstation with LANDesk it doesn't return any information (when run against the same workstation).

       

      I dont' really know LANDesk so there could be an obvious reason for this. The script runs as the local system account when deployed by LANDesk. The script search all local hard drives for a particular type of file, in this case NSF files.

       

      +++++++++++++++++++++++++++++++++++

      '*******************************
      'initialisation of script environment
      on error resume next
      Set WshNetwork = WScript.CreateObject("WScript.Network")
      set fso = createobject("scripting.filesystemobject")
      resultsfile="\\servername\nsf$\" & WshNetwork.ComputerName & "__" & WshNetwork.UserName & ".log"

      ' create variables for holding directory information and results
      dim checkdir()
      dim grandoutput

      yy=0
      Set objwmiservice = getobject("winmgmts:\\.\root\cimv2")
      set dis=objwmiservice.ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", &h10 + &h20)

      For Each objItem In dis
      if objItem.DriveType=3 then
      redim preserve checkdir(yy)
      checkdir(yy)=objItem.Name
      yy=yy+1
      end if
      Next

      'filter search to NSF files
      dim filtertype(0)
      filtertype(0)=".nsf"

      ' Search and create results
      for each a in checkdir
      if fso.folderexists(a)=true then
      set objfolder = fso.getfolder(a)
      set colfiles = objfolder.files
      cc=0
      for each objfile in colfiles
      if len(objfile.name) > 4 then
      if lcase(right(objfile.name,4))=filtertype(0) then
      grandoutput=grandoutput & a & vbtab & objfile.name & vbtab & objfile.size & vbtab & objfile.DateLastModified & vbtab & objfile.DateLastAccessed & vbtab & objfile.DateCreated & vbcrlf
      cc=cc+1
      end if
      end if
      next
      showsubfolders fso.getfolder(a)
      end if
      next

      ' write results to file in network share
      set writelog=fso.createtextfile(resultsfile)
      writelog.write(grandoutput)
      writelog.close
      sub showsubfolders(folder)
      on error resume next
          for each subfolder in folder.subfolders
              set objfolder = fso.getfolder(subfolder.path)
              set colfiles = objfolder.files
              cc=0
              for each objfile in colfiles
              if len(objfile.name) > 4 then
              if lcase(right(objfile.name,4))=filtertype(0) then
              grandoutput=grandoutput & subfolder.path & vbtab & objfile.name & vbtab & objfile.size & vbtab & objfile.DateLastModified & vbtab & objfile.DateLastAccessed & vbtab & objfile.DateCreated & vbcrlf
              cc=cc+1
              end if
              end if
              next
              showsubfolders subfolder
          next

      ' end
      end sub
      '****************************

       

      Regards and thanks,

       

      Cormac