troubleshooting Question

Code that takes screenshots of all machines in a file. Need an addition.

Avatar of bsharath
bsharathFlag for India asked on
Programming Languages-OtherScripting LanguagesVB Script
26 Comments1 Solution1178 ViewsLast Modified:

Code that takes screenshots of all machines in a file. Need an addition.
I have the machine names in a txt file. Say 10. I want these 10 to be looped again and again from the first to the 10th each 10 min till i kill the process.
The file names have to be with machine name and the date and time. So they dont clash. And if possible each machines files in seperate folders. So i have 10 folders with individual screenshots of the particular machine.

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
savefldr = "C:\folder"
computerfile = "C:\pcs.txt"
'Script version 2.0
'If you are running this from a secured share, you must have write permissions 
' on the scrserv.exe file (don't ask me why, it was written this way!) to 
' create a viable screenshot.  
'Just right-click the scrserv.exe file and apply modify permissions to whoever
' you want to set to use the tool.
'Valid command-line argument is:
'computer:computername|IP Address
'path:"x:\fullpath"|".\" (current directory
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
Set objArgs = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(savefldr) = False Then
	MsgBox("Folder " & savefldr & " does not exist")
End If
'on error resume next
Dim strComputer, strMsg
strScriptPath = replace(wscript.scriptfullname,wscript.scriptname,"")
'Set the screenshot grabber path in relation to the script path
strLsGrab = chr(34) & strScriptPath & "lsgrab\lsgrab.exe" & chr(34)
strTempFile = WshSysEnv("TEMP")
dim bFatal
if strPath = "" then strPath = ".\"
Set pcfile = fso.OpenTextFile(computerfile,1)
do while not pcfile.AtEndOfStream
bFatal = False
	strcomputer = pcfile.ReadLine
'If the passed computername contains any backslashes, remove them.
If InStr(strComputer,"\") Then strComputer = replace(strComputer,"\","")
 on error resume next
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT UserName FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
   For Each objItem In colItems
      strUser = objItem.UserName
 if err.number <> 0 then 
    strUser = ""
    'msgbox err.number & " " & err.description
		bFatal = true
	 if err.number = 451 then strMsg = "Could not enumerate WMI class.  You may not have permissions on the remote computer."
   end if
	If bFatal <> true then 
 	 Call Screenshot(strComputer, savefldr)
  	'Msgbox "Cannot acquire remote screenshot." & vbcrlf & vbcrlf & strMsg,48,"Screenshot unavailable."
	End If
	Set colItems = Nothing
	Set objWMIService = Nothing
	Set objItem = Nothing
on error goto 0
Function Screenshot(strComputer, savefolder)
	Set WshShell = WScript.CreateObject("WScript.Shell")
  'Finally, run the screen grabber command
  strCommand = strLsGrab & " /c:" & strComputer & " /p:" & chr(34) & savefolder & "\" & chr(34)
  'strInput = inputbox("the path is: ","test",strCommand)
  Set oExec = WshShell.Exec(strCommand)
  'msgbox oExec.stdout.readall
  if instr(oExec.stdout.readall,"denied") then
    msgbox "You do not have sufficient permissions on '" & strComputer & "' to retrieve the remote screen capture."
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    strFile = savefolder & "\" & strComputer & ".jpg" 
    'msgbox strFile
    Set f = objfso.GetFile(strFile)
    set objfso = nothing
    if f.size < 20000 Then 'less than 20kb
       'msgbox "Remote workstation was locked, so no screenshot was available.",48,"No screenshot created"
  	'msgbox "Now attempting to open " & chr(34) & savefolder & "\" & strComputer & ".jpg" & chr(34)
  	   on error resume next chr(34) & savefolder & "\" & strComputer & ".jpg" & chr(34),1,false
    End If
  End if
End Function
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 26 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 26 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros