Advertisement
JustJoe

lsgrabRemote.vbs

Aug 27th, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '#==============================================================================
  2. '#==============================================================================
  3. '#  SCRIPT.........:  lsgrabRemote.vbs
  4. '#  AUTHOR.........:  Joe Glessner
  5. '#  EMAIL..........:  
  6. '#  VERSION........:  1.0
  7. '#  DATE...........:  07JUN08
  8. '#  COPYRIGHT......:  2008, Joe-IT.com
  9. '#  LICENSE........:  Freeware
  10. '#  REQUIREMENTS...:  Requires lsgrab.exe (not free) from
  11. '#                    http://www.moernaut.com/default.aspx?item=grabberconsole
  12. '#
  13. '#                    lsgrab.exe MUST be in the %PATH% for this to work
  14. '#                    (c:\WINDOWS)!
  15. '#                  
  16. '#                    lsgrab requires Administrator rights on the computer that
  17. '#                    you are taking the screenshot of.
  18. '#
  19. '#  DESCRIPTION....:  Uses lsgrab.exe to take screenshots of remote machines,
  20. '#                    and renames the screenshots (using a timestamp) after they
  21. '#                    have been saved.
  22. '#
  23. '#  NOTES..........:  
  24. '#
  25. '#  CUSTOMIZE......:  Change the variables in the Script Configuration Section
  26. '#                    to reflect your environment.
  27. '#==============================================================================
  28. '#  REVISED BY.....:  
  29. '#  EMAIL..........:  
  30. '#  REVISION DATE..:  
  31. '#  REVISION NOTES.:
  32. '#
  33. '#==============================================================================
  34. '#==============================================================================
  35. '**Start Encode**
  36.  
  37. '#==============================================================================
  38. '#  START OF SCRIPT
  39. '#==============================================================================
  40. Option Explicit
  41. 'On Error Resume Next
  42.  
  43.     '#--------------------------------------------------------------------------
  44.    '#  Script Configuration Section
  45.    '#--------------------------------------------------------------------------
  46.    '#  OPTIONS:
  47.    '#            strComputer = The name of the computer to get the screenshot
  48.    '#                          from.
  49.    '#            objTargetDir = The directory where the resulting screenshot
  50.    '#                           will be placed.
  51.    '#
  52.    '#--------------------------------------------------------------------------
  53.    Dim strComputer:strComputer = "WKS01"
  54.     Dim objTargetDir:objTargetDir = "C:\Screenshots\"
  55.    
  56.     '#--------------------------------------------------------------------------
  57.    '#  Declare Variables
  58.    '#--------------------------------------------------------------------------
  59.    Dim myScr:myScr = "lsgrabRemote.vbs"
  60.     Dim current: current = Now
  61.     Dim strCh, strCmd1, strExists, strTime, strDate
  62.     Dim objScratchDir:objScratchDir = "C:\Scratch\"
  63.     Dim objBase:objBase = objScratchDir & strComputer & ".jpg"
  64.     Dim objFSO, objFolder, objTarget
  65.    
  66.     '#--------------------------------------------------------------------------
  67.    '#  Verify that the scratch directory exists, if not create it.
  68.    '#--------------------------------------------------------------------------
  69.    Set objFSO = CreateObject("Scripting.FileSystemObject")
  70.     If not objFSO.FolderExists(objScratchDir) Then
  71.         Wscript.echo "The scratch directory does not exist. Creating now..."
  72.     End If
  73.     If not objFSO.FolderExists(objScratchDir) Then
  74.         Set objFolder = objFSO.CreateFolder(objScratchDir)
  75.     End If
  76.    
  77.     '#--------------------------------------------------------------------------
  78.    '#  Verify that the destination directory exists, if not create it.
  79.    '#--------------------------------------------------------------------------
  80.    If not objFSO.FolderExists(objTargetDir) Then
  81.         Set objFolder = objFSO.CreateFolder(objTargetDir)
  82.     End If
  83.    
  84.     '#--------------------------------------------------------------------------
  85.    '#  Ensure we are not starting with a pre-existing screenshot
  86.    '#--------------------------------------------------------------------------
  87.    If objFSO.FileExists(objBase) Then
  88.         objFSO.DeleteFile objBase, True
  89.     End If    
  90.    
  91.     '#--------------------------------------------------------------------------
  92.    '#  Get the screenshot
  93.    '#--------------------------------------------------------------------------
  94.    strCmd1 = "lsgrab /c:" & strComputer & " /p:" & objScratchDir
  95.     command(strCmd1)
  96.    
  97.     '#--------------------------------------------------------------------------
  98.    '#  Wait for the new screenshot to exist.
  99.    '#--------------------------------------------------------------------------
  100.    Do Until strExists = "True"
  101.         If Not objFSO.FileExists(objBase) Then
  102.             wscript.sleep 1000
  103.         End If
  104.         If objFSO.FileExists(objBase) Then
  105.             strExists = "True"
  106.         End If
  107.     Loop
  108.    
  109.     '#--------------------------------------------------------------------------
  110.    '#  Rename the new screenshot with a timestamp.
  111.    '#--------------------------------------------------------------------------
  112.    strTime = timeStamp(current)
  113.     strDate = dateStamp(current)
  114.     objTarget = objTargetDir & strDate & "_" & strTime & "_" & strComputer & _
  115.     ".jpg"
  116.     objFSO.MoveFile objBase, objTarget
  117.  
  118. '#==============================================================================
  119. '#  SUBROUTINES/FUNCTIONS/CLASSES
  120. '#==============================================================================
  121.    '#-------------------------------------------------------------------------
  122.    '#  FUNCTION........:  command()
  123.    '#  ARGUMENTS.......:  Any command that can be run from a prompt.
  124.    '#  PURPOSE.........:  Executes a command line program.
  125.    '#  EXAMPLE.........:  command("net stop TermService")
  126.    '#  NOTES...........:  Must contain complete path if the command is not in
  127.    '#                     a %PATH% directory.
  128.    '#-------------------------------------------------------------------------
  129.    Function command(aCMD)  
  130.         Dim WshShell, oExec
  131.         Set WshShell = CreateObject("WScript.Shell")
  132.         Set oExec = WshShell.Exec(aCMD)
  133.         Do While oExec.Status = 0
  134.             WScript.Sleep 100
  135.         Loop
  136.     End Function
  137.    
  138.     '#-------------------------------------------------------------------------
  139.    '#  FUNCTION.......:  createDir(strDir)
  140.    '#  ARGUMENTS......:  strDir = Path of the directory to create.
  141.    '#  PURPOSE........:  Creates directories.
  142.    '#  EXAMPLE........:  createDir("c:\WSH_TEST\")
  143.    '#                    createDir("c:\WSH_TEST\" & "Files\")
  144.    '#  NOTES..........:  If creating a subdirectory of a directory that does
  145.    '#                    not exist, the parent directory must be created
  146.    '#                    first, as shown in the example.
  147.    '#-------------------------------------------------------------------------
  148.    Function createDir(strDir)
  149.         set filesys=CreateObject("Scripting.FileSystemObject")
  150.         Set objFSO = CreateObject("Scripting.FileSystemObject")
  151.         If Not filesys.FolderExists(strDir) Then
  152.             Set objFolder = objFSO.CreateFolder(strDir)
  153.         End If
  154.     End Function
  155.    
  156.     '#--------------------------------------------------------------------------
  157.    '#  FUNCTION.........:  dateStamp(ByVal dt)
  158.    '#  PURPOSE..........:  Generate an 8-character date stamp from the current
  159.    '#                      system date.
  160.    '#  ARGUMENTS........:  dt = The date stamp to convert.
  161.    '#  EXAMPLE..........:  Dim current: current = Now
  162.    '#                      WScript.Echo dateStamp(current)
  163.    '#  REQUIREMENTS.....:  
  164.    '#  NOTES............:  The above example will produce output of 20080730 if
  165.    '#                      run on 07/30/08.
  166.    '#--------------------------------------------------------------------------
  167.    Function dateStamp(ByVal dt)
  168.         Dim y, m, d
  169.         y = Year(dt)
  170.         m = Month(dt)
  171.         If Len(m) = 1 Then m = "0" & m
  172.         d = Day(dt)
  173.         If Len(d) = 1 Then d = "0" & d
  174.         dateStamp = y & m & d
  175.     End Function
  176.    
  177.     '#--------------------------------------------------------------------------
  178.    '#  FUNCTION.........:  timeStamp(ByVal dt)
  179.    '#  PURPOSE..........:  Generate a 6-character date stamp from the current
  180.    '#                      system time.
  181.    '#  ARGUMENTS........:  dt = The time stamp to convert.
  182.    '#  EXAMPLE..........:  Dim current: current = Now
  183.    '#                      WScript.Echo timeStamp(current)
  184.    '#  REQUIREMENTS.....:  
  185.    '#  NOTES............:  The above example will produce output of 210005 if
  186.    '#                      run on at 9:00:05 PM exactly.
  187.    '#--------------------------------------------------------------------------
  188.    Function timeStamp(ByVal dt)
  189.         Dim h, n, s
  190.         h = Hour(dt)
  191.         If Len(h) = 1 Then h = "0" & h
  192.         n = Minute(dt)
  193.         If Len(n) = 1 Then n = "0" & n
  194.         s = Second(dt)
  195.         If Len(s) = 1 Then s = "0" & s
  196.         timeStamp = h & n & s
  197.     End Function
  198.  
  199. '#==============================================================================
  200. '#  END OF FILE
  201. '#==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement