Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

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

Hi,

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.

REgards
Sharath
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")
	WScript.Quit
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
   Next
 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)
	Else
 
  	'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
loop
 
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."
  Else
    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"
    Else
       
  	'msgbox "Now attempting to open " & chr(34) & savefolder & "\" & strComputer & ".jpg" & chr(34)
  	   on error resume next
  	   wshshell.run chr(34) & savefolder & "\" & strComputer & ".jpg" & chr(34),1,false
  	   
    End If
  End if
  
End Function

Open in new window

Avatar of yehudaha
yehudaha
Flag of Israel image

what do you mean :

I want these 10 to be looped again and again from the first to the 10th each 10 min till i kill the process.
Avatar of bsharath

ASKER

I have these machine names in a txt file. When i run the vbs it actually goes to each machine takes a screen shot and ends with the 10th. I want it noww to start with 1 to 10 and again start with 1 till i end the process.
I have these machine names in a txt file. When i run the vbs it actually goes to each machine takes a screen shot and ends with the 10th. I want it noww to start with 1 to 10 and again start with 1 till i end the process.
Avatar of tigermatt
Sharath,

Please try this code. Be aware that you need to set the path to the script itself in the 'sScriptName' variable at the top of the script - so the script knows to call itself again once it completes executing.

The script will run just like before but keep running until you stop the process. Also, it will check if a screenshot already exists and if it does, it will append a number (0, 1, 2 and so on) to the end of the file name.

Matthew.
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
savefldr = "C:\folder"
computerfile = "C:\pcs.txt"
sScriptName = "C:\screenshot.vbs" 'The path to THIS script
 
'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")
        WScript.Quit
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
   Next
 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)
        Else
 
        '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
loop
 
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."
  Else
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
 
   strFile = savefolder & "\" & strComputer & ".jpg" 
 
If fso.FileExists(strFile) Then
	filei=0
	do while fso.FileExists(savefolder & "\" & strComputer & " (" & filei & ").jpg")
		filei=filei+1
strFile = savefolder & "\" & strComputer & filei & ".jpg"
	loop
End if
 
    '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"
    Else
       
        'msgbox "Now attempting to open " & chr(34) & savefolder & "\" & strComputer & ".jpg" & chr(34)
           on error resume next
           wshshell.run chr(34) & strFile & chr(34),1,false
           
    End If
  End if
  
End Function
 
WshShell.Run("cscript """ & sScriptName & """")
WScript.Quit

Open in new window

Updated per above.
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
savefldr = "C:\folder"
computerfile = "C:\pcs.txt"
sScriptName = "C:\screenshot.vbs" 'The path to THIS script
 
'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")
        WScript.Quit
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
   Next
 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)
        Else
 
        '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
loop
 
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."
  Else
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
 
   strFile = savefolder & "\" & strComputer & ".jpg" 
 
If fso.FileExists(strFile) Then
        filei=0
        do while fso.FileExists(savefolder & "\" & strComputer & " (" & filei & ").jpg")
                filei=filei+1
strFile = savefolder & "\" & strComputer & filei & ".jpg"
        loop
End if
 
    '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"
    Else
       
        'msgbox "Now attempting to open " & chr(34) & savefolder & "\" & strComputer & ".jpg" & chr(34)
           on error resume next
           wshshell.run chr(34) & strFile & chr(34),1,false
           
    End If
  End if
  
End Function
 
WshShell.Run("cscript """ & sScriptName & """")
WScript.Quit

Open in new window

Can i have individual folders created for these images. So i have 10 seperate folders
Can i have individual folders created for these images. So i have 10 seperate folders
Matthew the script does loop but does not create new files but it replaces the old to the new ones. So i dont have similar files as i wanted every time it takes a screenshot.

I'm going to rewrite this script for you and do it a slightly different way. Give me a few minutes.

With regards to the files, do you want the old screenshots to be overwritten or not?
In this case no
Sharath

I'm afraid the lsgrab program has been identified as a Virus, and as such on my domain I am unable to continue developing this script further (lsgrab has been removed from my system).

I do apologise,

-Matt
Ok... Thanks...
While its looping and it starts from the 1st machine again the 2nd and 3rd can it get a 1,2,3 and so on next to the machine name?

So that could sort the issue so i shall use another script to create folders of first 15 identicals you gave me some time ago
Ok... Thanks...
While its looping and it starts from the 1st machine again the 2nd and 3rd can it get a 1,2,3 and so on next to the machine name?

So that could sort the issue so i shall use another script to create folders of first 15 identicals you gave me some time ago
Sharath,

Try this script which seemed to be working before it detected it as a virus. Set the savefldr equal to the root folder where the screenshots should go.

-Matt
'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.  
savefldr = "C:\folder\"
'
'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")
 
'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")
 
'Get command-line arguments for a passed computername or IP address.
If objArgs.Count > 0 Then 
	msgbox("args")
	 strComputer = objArgs(0) 
	msgbox(strcomputer)
ElseIf objargs.count = 0 then
	wscript.quit
End If
 
if strComputer = "" Then WScript.Quit
 
If fso.FolderExists(savefldr) = False Then 
	Set storefolder = fso.CreateFolder(savefldr)
savefldr = savefldr & "\" & strComputer
	fso.CreateFolder(savefldr)
	
End if
 
savefldr = savefldr & "\" & strComputer
	If (fso.FolderExists(savefldr) = False) Then
		fso.CreateFolder(savefldr)
	End If
	Set trackfile = fso.OpenTextFile(savefldr & "\tracking.log",8,True)
	Set trackfile2 = fso.OpenTextFile(savefldr & "\tracking.log",1,False)
	
	do while not trackfile2.AtEndOfStream
		screenshotid = trackfile2.ReadLine
		
		If (screenshotid = "") Then
			screenshotid = 0
		Else
			screenshotid = CInt(screenshotid) + 1
		End If
	loop
trackfile.WriteLine screenshotid
msgbox("here " & screenshotid)
 
'If the passed computername contains any backslashes, remove them.
If InStr(strComputer,"\") Then strComputer = replace(strComputer,"\","")
dim bFatal
 
'Check to see if a user is logged in remotely.
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
   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
   Next
 
   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)
Else
 
  'Msgbox "Cannot acquire remote screenshot." & vbcrlf & vbcrlf & strMsg,48,"Screenshot unavailable."
End If
 
Function Screenshot(strComputer)
	Set WshShell = WScript.CreateObject("WScript.Shell")
  'Finally, run the screen grabber command
  strCommand = strLsGrab & " /c:" & strComputer & " /p:" & chr(34) & WshSysEnv("TEMP") & "\" & 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."
  Else
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    strFile = savefldr & screenshotid & ".jpg" 
strFile2 = WshSysEnv("TEMP") & "\" & strcomputer & ".jpg"
    'msgbox strFile
    Set f = objfso.GetFile(strFile2)
    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"
    Else
       
  	'msgbox "Now attempting to open " & chr(34) & WshSysEnv("TEMP") & "\" & strComputer & ".jpg" & chr(34)
  	   on error resume next
'  	   wshshell.run chr(34) & savefldr & chr(34),1,false
fso.MoveFile strFile2, strFile
  	   
    End If
  End if
  
End Function

Open in new window

You will also need this script. This one is what actually does the work and calls the other script above to take the screenshots. So you start by running this script, and just have the above one SOMEWHERE on your system.

In this script you need to set the 'pcs' variable to the name of the file containing your computer names.
Set pathtoscript equal to the path to the other script (the one above).

Then try running this script, not the above one. I'm afraid this is as far as I can go - as without being able to test I can't really debug it further.

-Matthew
pcs = "C:\pcs.txt"
pathtoscript = "C:\screenshot.vbs" 'The other script's path
Set fso=CreateObject("Scripting.FileSystemObject")
Set pcsf = fso.OpenTextFile(pcs,1)
Set wshshell = CreateObject("WScript.Shell")
 
do while not pcsf.AtEndOfStream
	wshshell.exec "cscript """ & pathtoscript & """ " & pcsf.readline
loop

Open in new window

Matthew i get a lot of boxes with ok buttons
I have 50 names in the txt file and it opened say 300+ command windows and msg boxes
Matthew i get a lot of boxes with ok buttons
I have 50 names in the txt file and it opened say 300+ command windows and msg boxes
Try this for the first script:

'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.  
savefldr = "C:\folder\"
'
'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")
 
'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")
 
'Get command-line arguments for a passed computername or IP address.
If objArgs.Count > 0 Then
      'msgbox("args")
       strComputer = objArgs(0)
      'msgbox(strcomputer)
ElseIf objargs.count = 0 then
      wscript.quit
End If
 
if strComputer = "" Then WScript.Quit
 
If fso.FolderExists(savefldr) = False Then
      Set storefolder = fso.CreateFolder(savefldr)
savefldr = savefldr & "\" & strComputer
      fso.CreateFolder(savefldr)
      
End if
 
savefldr = savefldr & "\" & strComputer
      If (fso.FolderExists(savefldr) = False) Then
            fso.CreateFolder(savefldr)
      End If
      Set trackfile = fso.OpenTextFile(savefldr & "\tracking.log",8,True)
      Set trackfile2 = fso.OpenTextFile(savefldr & "\tracking.log",1,False)
      
      do while not trackfile2.AtEndOfStream
            screenshotid = trackfile2.ReadLine
            
            If (screenshotid = "") Then
                  screenshotid = 0
            Else
                  screenshotid = CInt(screenshotid) + 1
            End If
      loop
trackfile.WriteLine screenshotid
'msgbox("here " & screenshotid)
 
'If the passed computername contains any backslashes, remove them.
If InStr(strComputer,"\") Then strComputer = replace(strComputer,"\","")
dim bFatal
 
'Check to see if a user is logged in remotely.
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
   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
   Next
 
   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)
Else
 
  'Msgbox "Cannot acquire remote screenshot." & vbcrlf & vbcrlf & strMsg,48,"Screenshot unavailable."
End If
 
Function Screenshot(strComputer)
      Set WshShell = WScript.CreateObject("WScript.Shell")
  'Finally, run the screen grabber command
  strCommand = strLsGrab & " /c:" & strComputer & " /p:" & chr(34) & WshSysEnv("TEMP") & "\" & 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."
  Else
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    strFile = savefldr & screenshotid & ".jpg"
strFile2 = WshSysEnv("TEMP") & "\" & strcomputer & ".jpg"
    'msgbox strFile
    Set f = objfso.GetFile(strFile2)
    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"
    Else
       
        'msgbox "Now attempting to open " & chr(34) & WshSysEnv("TEMP") & "\" & strComputer & ".jpg" & chr(34)
           on error resume next
'           wshshell.run chr(34) & savefldr & chr(34),1,false
fso.MoveFile strFile2, strFile
          
    End If
  End if
 
End Function
Matthew.

I did as you said. Now there are folders and txt files created in the folder. But only Jpg file is created outside the folder not within the creted folder.
And loop stops after 1st machine
Matthew.

I did as you said. Now there are folders and txt files created in the folder. But only Jpg file is created outside the folder not within the creted folder.
And loop stops after 1st machine
OK, for the smaller script, use this (and update the paths as appropriate).
pcs = "C:\pcs.txt"
pathtoscript = "C:\screenshot.vbs" 'The other script's path
Set fso=CreateObject("Scripting.FileSystemObject")
Set pcsf = fso.OpenTextFile(pcs,1)
Set wshshell = CreateObject("WScript.Shell")
 
do while not pcsf.AtEndOfStream
	wshshell.exec "cscript """ & pathtoscript & """ " & pcsf.readline
loop
wshshell.exec "cscript """ & wscript.scriptfullname & """"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of tigermatt
tigermatt
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The file names go on as this
Dev-pc186299.jpg
Machine name is
Dev-pc1862

The jpg files dont get created in the folders but get created inside the images folder.

The file names go on as this
Dev-pc186299.jpg
Machine name is
Dev-pc1862

The jpg files dont get created in the folders but get created inside the images folder.

In that case I would use one of your other scripts to move those files into the appropriate folders after they are created. The last digits after the end of the computer name is the number of the screenshot, so provided you know how long each PC name is, another script could move it. I don't know why this one isn't moving them, but as I say, I can't test any further as the program has been identified as a virus on this secure domain.

-Matthew
Thank U... I shall use the script to move them... :-))