Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '#==============================================================================
- '#==============================================================================
- '# SCRIPT.........: lsgrabRemote.vbs
- '# AUTHOR.........: Joe Glessner
- '# EMAIL..........:
- '# VERSION........: 1.0
- '# DATE...........: 07JUN08
- '# COPYRIGHT......: 2008, Joe-IT.com
- '# LICENSE........: Freeware
- '# REQUIREMENTS...: Requires lsgrab.exe (not free) from
- '# http://www.moernaut.com/default.aspx?item=grabberconsole
- '#
- '# lsgrab.exe MUST be in the %PATH% for this to work
- '# (c:\WINDOWS)!
- '#
- '# lsgrab requires Administrator rights on the computer that
- '# you are taking the screenshot of.
- '#
- '# DESCRIPTION....: Uses lsgrab.exe to take screenshots of remote machines,
- '# and renames the screenshots (using a timestamp) after they
- '# have been saved.
- '#
- '# NOTES..........:
- '#
- '# CUSTOMIZE......: Change the variables in the Script Configuration Section
- '# to reflect your environment.
- '#==============================================================================
- '# REVISED BY.....:
- '# EMAIL..........:
- '# REVISION DATE..:
- '# REVISION NOTES.:
- '#
- '#==============================================================================
- '#==============================================================================
- '**Start Encode**
- '#==============================================================================
- '# START OF SCRIPT
- '#==============================================================================
- Option Explicit
- 'On Error Resume Next
- '#--------------------------------------------------------------------------
- '# Script Configuration Section
- '#--------------------------------------------------------------------------
- '# OPTIONS:
- '# strComputer = The name of the computer to get the screenshot
- '# from.
- '# objTargetDir = The directory where the resulting screenshot
- '# will be placed.
- '#
- '#--------------------------------------------------------------------------
- Dim strComputer:strComputer = "WKS01"
- Dim objTargetDir:objTargetDir = "C:\Screenshots\"
- '#--------------------------------------------------------------------------
- '# Declare Variables
- '#--------------------------------------------------------------------------
- Dim myScr:myScr = "lsgrabRemote.vbs"
- Dim current: current = Now
- Dim strCh, strCmd1, strExists, strTime, strDate
- Dim objScratchDir:objScratchDir = "C:\Scratch\"
- Dim objBase:objBase = objScratchDir & strComputer & ".jpg"
- Dim objFSO, objFolder, objTarget
- '#--------------------------------------------------------------------------
- '# Verify that the scratch directory exists, if not create it.
- '#--------------------------------------------------------------------------
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- If not objFSO.FolderExists(objScratchDir) Then
- Wscript.echo "The scratch directory does not exist. Creating now..."
- End If
- If not objFSO.FolderExists(objScratchDir) Then
- Set objFolder = objFSO.CreateFolder(objScratchDir)
- End If
- '#--------------------------------------------------------------------------
- '# Verify that the destination directory exists, if not create it.
- '#--------------------------------------------------------------------------
- If not objFSO.FolderExists(objTargetDir) Then
- Set objFolder = objFSO.CreateFolder(objTargetDir)
- End If
- '#--------------------------------------------------------------------------
- '# Ensure we are not starting with a pre-existing screenshot
- '#--------------------------------------------------------------------------
- If objFSO.FileExists(objBase) Then
- objFSO.DeleteFile objBase, True
- End If
- '#--------------------------------------------------------------------------
- '# Get the screenshot
- '#--------------------------------------------------------------------------
- strCmd1 = "lsgrab /c:" & strComputer & " /p:" & objScratchDir
- command(strCmd1)
- '#--------------------------------------------------------------------------
- '# Wait for the new screenshot to exist.
- '#--------------------------------------------------------------------------
- Do Until strExists = "True"
- If Not objFSO.FileExists(objBase) Then
- wscript.sleep 1000
- End If
- If objFSO.FileExists(objBase) Then
- strExists = "True"
- End If
- Loop
- '#--------------------------------------------------------------------------
- '# Rename the new screenshot with a timestamp.
- '#--------------------------------------------------------------------------
- strTime = timeStamp(current)
- strDate = dateStamp(current)
- objTarget = objTargetDir & strDate & "_" & strTime & "_" & strComputer & _
- ".jpg"
- objFSO.MoveFile objBase, objTarget
- '#==============================================================================
- '# SUBROUTINES/FUNCTIONS/CLASSES
- '#==============================================================================
- '#-------------------------------------------------------------------------
- '# FUNCTION........: command()
- '# ARGUMENTS.......: Any command that can be run from a prompt.
- '# PURPOSE.........: Executes a command line program.
- '# EXAMPLE.........: command("net stop TermService")
- '# NOTES...........: Must contain complete path if the command is not in
- '# a %PATH% directory.
- '#-------------------------------------------------------------------------
- Function command(aCMD)
- Dim WshShell, oExec
- Set WshShell = CreateObject("WScript.Shell")
- Set oExec = WshShell.Exec(aCMD)
- Do While oExec.Status = 0
- WScript.Sleep 100
- Loop
- End Function
- '#-------------------------------------------------------------------------
- '# FUNCTION.......: createDir(strDir)
- '# ARGUMENTS......: strDir = Path of the directory to create.
- '# PURPOSE........: Creates directories.
- '# EXAMPLE........: createDir("c:\WSH_TEST\")
- '# createDir("c:\WSH_TEST\" & "Files\")
- '# NOTES..........: If creating a subdirectory of a directory that does
- '# not exist, the parent directory must be created
- '# first, as shown in the example.
- '#-------------------------------------------------------------------------
- Function createDir(strDir)
- set filesys=CreateObject("Scripting.FileSystemObject")
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- If Not filesys.FolderExists(strDir) Then
- Set objFolder = objFSO.CreateFolder(strDir)
- End If
- End Function
- '#--------------------------------------------------------------------------
- '# FUNCTION.........: dateStamp(ByVal dt)
- '# PURPOSE..........: Generate an 8-character date stamp from the current
- '# system date.
- '# ARGUMENTS........: dt = The date stamp to convert.
- '# EXAMPLE..........: Dim current: current = Now
- '# WScript.Echo dateStamp(current)
- '# REQUIREMENTS.....:
- '# NOTES............: The above example will produce output of 20080730 if
- '# run on 07/30/08.
- '#--------------------------------------------------------------------------
- Function dateStamp(ByVal dt)
- Dim y, m, d
- y = Year(dt)
- m = Month(dt)
- If Len(m) = 1 Then m = "0" & m
- d = Day(dt)
- If Len(d) = 1 Then d = "0" & d
- dateStamp = y & m & d
- End Function
- '#--------------------------------------------------------------------------
- '# FUNCTION.........: timeStamp(ByVal dt)
- '# PURPOSE..........: Generate a 6-character date stamp from the current
- '# system time.
- '# ARGUMENTS........: dt = The time stamp to convert.
- '# EXAMPLE..........: Dim current: current = Now
- '# WScript.Echo timeStamp(current)
- '# REQUIREMENTS.....:
- '# NOTES............: The above example will produce output of 210005 if
- '# run on at 9:00:05 PM exactly.
- '#--------------------------------------------------------------------------
- Function timeStamp(ByVal dt)
- Dim h, n, s
- h = Hour(dt)
- If Len(h) = 1 Then h = "0" & h
- n = Minute(dt)
- If Len(n) = 1 Then n = "0" & n
- s = Second(dt)
- If Len(s) = 1 Then s = "0" & s
- timeStamp = h & n & s
- End Function
- '#==============================================================================
- '# END OF FILE
- '#==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement