How to scan for files locked by Ransomware
I am trying to clean up the file shares on our servers and reorganize them. About a year before I started, the company got hit with a ransomware virus and the previous people before me didn't seem to do a good job at recovering the files in the file shares. There are a lot of old files that are still encrypted and folders that have the decrypt instructions link. It's too late to recover those files so it is better to delete them since no one is using them anymore. Is there a way to check which files are still encrypted without clicking on each one to see if they work or not?
This topic first appeared in the Spiceworks Community
Try EasyFind.
Similar Messages
-
how to scan for media
how do i scan for media. I have media on my mac but everytime i try to open it using itunes it wont let me add it to the library. ive tried everything through itunes even converting it to mp3 and nothing happens. help please
-
How to SCAN uploaded files for VIRUS in APEX
part 1:
Goal:
Do a virus scan of the uploaded file from APEX application prior to storing the file in custom tables.
The process:
Followed the document from www.developer.com:
Implementing an Anti-Virus File Scan in JEE Applications
By Vlad Kofman
Go to page: 1 2 3 Next
This article will discuss one of the ways to implement antivirus file scanning in Java, particular in the JEE applications. Viruses, Trojan Horses, and different malware and spyware are a real problem for current computer environments, and especially for the Windows operating system. If you are designing any application in Java that has a requirement to be able to upload external files, you have a potential security risk. By uploading, I mean any way to get the external file inside of the corporate firewall be it via HTTP protocol or any other means. It is quite common to have this type of requirement in an enterprise application and with Java being one of the most popular web development platforms, it is unfortunate that this type of gaping security risk is quite often overlooked.
Java's Development Kit (JDK) does not have any means to do the antivirus scan right out of the box. This is primarily because Java is a programming language, and does not have any virus scanning packages. Furthermore, anti-virus software is not Sun's area of expertise or business model. Developing this type of software (or Java package), and more importantly maintaining it, would be a huge task for Sun. Mainly because viruses are constantly evolving and keeping virus definitions up-to-date is a daunting task. Large companies such as McAffee, Symantec, or Zone Labs develop virus detecting and combating products and spend a lot of resources to maintain them.
Application Environment
To implement a virus file scan in Java, a third-party package needs to be used. For the purposes of this article, I will use Symantec Scan Engine (SSE) package, which comes with Java APIs. This package is an application that serves as a TCP/IP server and has a programming interface and enables Java applications to incorporate support for content scanning technologies. For this article, I used Symantec Scan Engine 5.1, which is available as a Unix or Windows install.
If you are using an anti-virus package from the different vendor, you will need to investigate what kind of APIs are available; however, the general approach should be similar. Also, note that my implementation can be used with JEE technology and any modern MVC framework such as Struts or Spring.
The architecture is as follows: A server machine needs to have SSE running at all times. This can be the same machine that hosts your Application Server, but in an enterprise environment this should be a different machine. The Default Port needs to be open through the firewall to allow communication with the scan engine. All JEE applications that need to do file scanning can talk to the SSE server machine through a default port. Also, multiple applications running on different application servers can re-use the same scanning server. For more information, you should refer to the Symantec Scan Engine (SSE) Installation Guide, available on the Symantec web site.
When an external file that needs to be scanned is sent to the SSE via its programming interface (Java APIs using the default port), before any other operation on the file is performed, the SSE returns a result code. For instance, a file is uploaded by an external user into the web email type application as an attachment; then, the SSE API is invoked by the application and the return code of pass or fail determines the outcome of the upload and whether that email can actually be sent. If you have an account on Yahoo mail, you probably have seen that Yahoo is using Norton Antivirus to scan all attachments, although no Java.
Click here for a larger image.
Figure 1: Screen shot from Yahoo
For details on the Scan Engine Server Installationm please see the Symantec Scan Engine (SSE) Implementation Guide from Symantec.
Here are some key things to remember about SSE:
• Java 2 SE Runtime (JRE) 5.0 Update 6.0 or later must be installed on the server before the SSE installation is done.
• After installation, verify that the Symantec Scan Engine daemon is running. At the Unix command prompt (if it's a Unix install), type the following command:
ps –ea | grep sym.
A list of processes similar to the following should appear:
o 5358 ? 0:00 symscan
o 5359 ? 0:00 symscan
If nothing is displayed the SSE process did not start.
If the SSE process did not start, type the following command to restart SSE:
/etc/init.d/symscan restart
• Keeping the virus definition up to date is the most important task and if new updates are not installed, the whole scan becomes ineffective. Symantec automatically downloads the most current file definitions through LiveUpdate. Please make sure that firewall rules are in place to allow the host server to connect to the Symantec update service.
Project Setup
For the purposes of this article, I included a wrapper for the Symantec SSE APIs, av.jar, which has Symantec Java APIs and serves as a client to the SSE server and takes care of all communications with the server. Please refer to the download source section. The av.jar should be included in the Java CLASSPATH to work with the SSE. This jar contains a class called AVClient that takes care of actually sending the files to SSE as byte arrays and returning the result.
In my project setting, I added three variables to be accessed via the System.getProperty mechanism. For example:
AV_SERVER_HOST=192.168.1.150
AV_SERVER_PORT=1344
AV_SERVER_MODE=SCAN
The AV_SERVER_HOST is the host name or IP of the machine where Scan Engine is installed.
The AV_SERVER_PORT is the port where Scan Engine listens for incoming files.
The AV_SERVER_MODE is the scan mode which can be:
• NOSCAN: No scanning will be done (any keyword that does not start with "SCAN" will result in ignoring the call to the Scan Engine and no files will be transferred for scanning).
• SCAN: Files or the byte stream will be scanned, but the scan engine will not try to repair infections.
• SCANREPAIR: Files will be scanned, the scan engine will try to repair infections, but nothing else will be done.
• SCANREPAIRDELETE: Files will be scanned, the scan engine will try to repair infections, and irreparable files will be deleted.
Note: For the file stream (byte array) scanning, the only meaning full values are "SCAN" and "NOSCAN".
Using the SSE Scanning Java APIs
In any class where scan is required, call the scanning API provided in the AVClient object located in the av.jar. The AVClient object will establish connection to the Scan Engine server and has the following APIs:
Figure 2: The significant APIs for the communication with to the Scan Engine Server.
If scanning a file on the file system, in SCAN only mode, use the call that accepts filename only.
If scanning a file on the file system, with SCANREPAIR or SCANREPAIRDELETE, use the call that accepts input and output file names.
If scanning an in-memory file (byte array), use the call accepting byte array.
For example:
import com.av.*;
Initialize setup parameters:
static String avMode =
(System.getProperty("AV_SERVER_MODE") != null)
? (String) System.getProperty("AV_SERVER_MODE") : "NOSCAN";
static boolean scan = avMode.startsWith("SCAN");
static String avServer =
(String) System.getProperty("AV_SERVER_HOST");
static int avPort =
Integer.parseInt( (String) System.getProperty("AV_SERVER_PORT"));
Scan check example for an in-memory file byte array:
public void scanFile(byte[] fileBytes, String fileName)
throws IOException, Exception {
if (scan) {
AVClient avc = new AVClient(avServer, avPort, avMode);
if (avc.scanfile(fileName, fileBytes) == -1) {
throw new VirusException("WARNING: A virus was detected in
your attachment: " + fileName + "<br>Please scan
your system with the latest antivirus software with
updated virus definitions and try again.");
Note that if you are using this code inside of the MVC handler, you can throw a custom VirusException and check for it in the calling method and perform any necessary cleanup. I have included the class in the AV Jar as well.
For example:
catch (Exception ex) {
logger.error(ex);
if (ex instanceof VirusException) {
// do something here
else {
// there was some other error – handle it
For more details on the Scan Engine Client API, please see Symantec Scan Engine Software Developers Guide.
Continuation in part2part 4:
c) Clienttester.java – This is the gui app set to test if the configuration is working or not. This gui uses the method scanfile(inputfile, outputfile) as you can see the result in the outputpane of the jframe.
* clienttester.java
* Created on April 12, 2005, 2:37 PM
* @author george_maculley
package com.av;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class clienttester
implements ActionListener {
// private String ipaddress = "127.0.0.1";
private String ipaddress = "199.209.150.58";
//private String ipaddress = "192.168.0.55";
static JFrame frame;
JFileChooser chooser = new JFileChooser();
TextField pathtofile = new TextField(System.getProperty("user.home"), 30);
// TextField pathtooutfile= new TextField(System.getProperty("user.home"),30);
private int port = 1344;
JButton filechooser = new JButton("Browse to file"); ;
private String originalfilename;
private String outputfilename;
JButton scanbutton = new JButton("Scan");
TextArea outputarea = new TextArea(20, 40);
TextField iptext = new TextField("127.0.0.1", 16);
TextField porttext = new TextField("1344", 5);
AVClient mine;
JRadioButton choosescan = new JRadioButton("SCAN");
// JRadioButton choosedelete= new JRadioButton("SCANREPAIRDELETE");
/** Creates a new instance of gui */
public clienttester() {
public clienttester(java.lang.String ip, java.lang.String infile, java.lang.String outfile, int port) {
this.ipaddress = ip;
this.port = port;
this.originalfilename = infile;
this.outputfilename = outfile;
boolean setValues(java.lang.String ip, java.lang.String infile, java.lang.String outfile, int port) {
this.ipaddress = ip;
this.port = port;
this.originalfilename = infile;
this.outputfilename = outfile;
return (true);
public void actionPerformed(java.awt.event.ActionEvent actionEvent) {
JComponent c = (JComponent) actionEvent.getSource();
if (c == filechooser) {
int retval = chooser.showDialog(frame, null);
if (retval == JFileChooser.APPROVE_OPTION) {
File theFile = chooser.getSelectedFile();
if (theFile != null) {
pathtofile.setText(theFile.getPath());
// pathtooutfile.setText(theFile.getPath());
JOptionPane.showMessageDialog(frame, "You chose this file: " + theFile.getPath());
if (c == scanbutton) {
//return object that can be passed to AVClient
String policy;
int thisport;
int scanresult;
String thisip;
String inputfile;
String outputfile;
outputarea.append("Server: " + iptext.getText() + "\r\n");
if (choosescan.isSelected()) {
policy = "SCAN";
else {
policy = "SCANREPAIRDELETE";
thisport = new Integer(porttext.getText()).intValue();
thisip = iptext.getText();
//mine= new AVClient(iptext.getText(),porttext.getText(),policy);
mine = new AVClient(iptext.getText(), thisport, policy);
if (mine.test() == 1) {
outputarea.append("Sorry. Incorrect parameters specified.\r\n");
System.exit(1);
else {
outputarea.append("Connection to SAVSE initialized.\r\n");
inputfile = pathtofile.getText();
// outputfile=pathtooutfile.getText();
outputfile = "/tmp";
outputarea.append("Scanning file " + inputfile + " \r\n");
if (policy == "SCAN") {
scanresult = mine.scanfile(inputfile);
else {
scanresult = mine.scanfile(inputfile, outputfile);
if (scanresult == 0) {
outputarea.append("File is clean.\r\n");
else if (scanresult == -1) {
outputarea.append("File is infected. \r\n");
else {
outputarea.append("Scan error.\r\n");
void display() {
Frame f = new Frame("SAVSE JAVA ICAP Client");
f.setLayout(new GridLayout(1, 2));
JPanel lpanel = new JPanel(new GridLayout(7, 1));
JPanel ippanel = new JPanel();
JPanel portpanel = new JPanel();
JPanel rpanel = new JPanel();
JPanel outputpanel = new JPanel();
JPanel buttonpanel = new JPanel();
JPanel pathpanel = new JPanel();
// JPanel outpathpanel= new JPanel();
JPanel policypanel = new JPanel();
ButtonGroup policygroup = new ButtonGroup();
filechooser.addActionListener(this);
scanbutton.addActionListener(this);
choosescan.setSelected(true);
policygroup.add(choosescan);
// policygroup.add(choosedelete);
buttonpanel.setBorder(BorderFactory.createTitledBorder("Scan Policy"));
buttonpanel.add(choosescan);
// buttonpanel.add(choosedelete);
pathpanel.setBorder(BorderFactory.createTitledBorder("Path to File"));
pathpanel.add(pathtofile);
f.setSize(new Dimension(650, 400));
f.setBackground(Color.white);
f.setResizable(true);
ippanel.setBorder(BorderFactory.createTitledBorder("SAVSE IP Address"));
ippanel.add(iptext);
outputpanel.setBorder(BorderFactory.createTitledBorder("OUTPUT"));
outputpanel.add(outputarea);
portpanel.setBorder(BorderFactory.createTitledBorder("ICAP Port"));
portpanel.add(porttext);
// outpathpanel.setBorder(BorderFactory.createTitledBorder("Path to Repair File"));
// outpathpanel.add(pathtooutfile);
lpanel.add(ippanel);
rpanel.add(outputpanel);
lpanel.add(portpanel);
lpanel.add(buttonpanel);
lpanel.add(pathpanel);
// lpanel.add(outpathpanel);
lpanel.add(filechooser);
lpanel.add(scanbutton);
f.add(lpanel);
f.add(rpanel);
f.setVisible(true);
public static void main(String[] args) {
clienttester g = new clienttester();
g.display();
d) my2.java – This is the class file I wrote to test that I am able to send a file and scan it and see the output in the JDEVELOPER. In this case the file is stored on the filesystem of the client machine. JDEVELOPER should be able to see the file.
NOTE:
“EICAR.com” is the test file downloaded from Symantec site to test a non malicious virus file. I n order to be able to test it like this, the Antivirus program running on your machine should be disabled, or else Antivirus will kick in and delete the file. In the first place you will not be able to download the test virus file either with anti virus running on the machine you are downloading to.
package com.av;
import java.io.*;
public class my2 {
static int my_return = 0;
* @param fileBytes
* @param fileName
* @return
public static int scanfile(String fileName){
String avMode = "SCAN";
boolean scan = avMode.startsWith("SCAN");
String avServer = "xx";--avserver ip address
int avPort = 1344;
int the_return = 0;
if (scan) {
AVClient avc = new AVClient(avServer,avPort,avMode);
the_return = avc.scanfile(fileName);
if (the_return == -1) {
return (the_return);
} else
return (the_return);
//my_return = the_return;
return (the_return);
public static void main(String[] args) throws Exception {
System.out.println("Hi there in Main");
byte[] b1 = new byte[4];
b1[1] = 68;
my_return = scanfile("c:\\eicar.com");
System.out.println(my_return);
e) Then finally we have my1.JAVA, which takes the filename, and it’s contents in the bytes form and scans the file. The reason for this method is we are not storing the file on the filesystem, it is read into the memory and only if it is clean, it is put into the database or else notify the user.
package com.av;
import java.io.*;
public class my1 {
static int my_return = 0;
static int a_length = 0;
* @param fileBytes
* @param fileName
* @return
public static int scanfile(String fileName,byte[] fileBytes) throws IOException {
String avMode = "SCAN";
boolean scan = avMode.startsWith("SCAN");
String avServer = "xxx";--avserver’s ip address
int avPort = 1344;
int the_return = 0;
if (scan) {
AVClient avc = new AVClient(avServer,avPort,avMode);
// File file = new File(fileName) ;
//byte[] fBytes = getBytesFromFile(file);
the_return = avc.scanfile(fileName, fileBytes);
if (the_return == -1) {
return (the_return);
} else
{return (the_return);}
my_return = the_return;
return (the_return);
// Returns the contents of the file in a byte array.
* @param file
* @return
* @throws IOException
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
// Close the input stream and return bytes
is.close();
return bytes;
// public static void main(String[] args) throws Exception {
//System.out.println("Hi there in Main");
// File file = new File() ;
// byte[] b1 = getBytesFromFile(file);
//System.out.println(b1);
// my_return = scanfile(,b1);
//System.out.println(my_return); }
Finally , you have the exceptions file,
e) package com.av;
public class VirusException
extends Exception {
public VirusException() {
super();
public VirusException(String text) {
super(text);
Once you have all these classes, you can use JDEVELOPER , to load these classes into the database: This is as follows:
Right click on the project, which has all these classes.
NEW -> deployment profiles -> load java and stored procedures.
When you are created deployment profile, you have to specify,
Loadjava options.
-f, -v (check the check boxes)
Under privileges:
-s – specify database schema these classes are loaded into
-s – create sysnonym check box
-g – grant to public or any specific users per your policy.
Under Resolver,
-r and –o (check the check boxes)
I accepted the default name storedproc1. Then you right click on the storedproc1.deploy, deploy to whichever database connection you created.
And then, In order to access this java class we need a pl/sql wrapper as follows:
create or replace package my1 is
function mycheck (pfilename in varchar2, psize in number)
return number;
end my1;
create or replace package body my1 is
function mycheck (pfilename in varchar2, psize in number)
return number is
language java
name 'com.av.my1.scanfile(java.lang.String, byte[]) return int';
end my1;
And the code is invoked from sql plus as follows:
Select my1.mycheck(“filename”, “filebytes”) from dual;
One important catch in the above method is to send the filename and filecontents in bytes form. In order to send the file contents as filebytes, you will need another java class and load into the data base as described above.
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
* This program demonstrates how to read a file into a byte array. This method
* reads the entire contents of the file into a byte array.
* @version 1.0
* @author Jeffrey M. Hunter ([email protected])
* @author http://www.idevelopment.info
public class ReadFileIntoByteArray {
* method to convert a byte to a hex string.
* @param data the byte to convert
* @return String the converted byte
public static String byteToHex(byte data) {
StringBuffer buf = new StringBuffer();
buf.append(toHexChar((data >>> 4) & 0x0F));
buf.append(toHexChar(data & 0x0F));
return buf.toString();
* Convenience method to convert an int to a hex char.
* @param i the int to convert
* @return char the converted char
public static char toHexChar(int i) {
if ((0 <= i) && (i <= 9)) {
return (char) ('0' + i);
} else {
return (char) ('a' + (i - 10));
* Returns the contents of the file in a byte array
* @param file File this method should read
* @return byte[] Returns a byte[] array of the contents of the file
private static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
System.out.println("\nDEBUG: FileInputStream is " + file);
// Get the size of the file
long length = file.length();
System.out.println("DEBUG: Length of " + file + " is " + length + "\n");
* You cannot create an array using a long type. It needs to be an int
* type. Before converting to an int type, check to ensure that file is
* not loarger than Integer.MAX_VALUE;
if (length > Integer.MAX_VALUE) {
System.out.println("File is too large to process");
return null;
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while ( (offset < bytes.length)
( (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) ) {
offset += numRead;
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file " + file.getName());
is.close();
return bytes;
* @param filename
public static byte[] chk_file(String filename) {
byte[] fileArray = null;
try {
fileArray = getBytesFromFile(new File( filename));
} catch (IOException e) {
e.printStackTrace();
if (fileArray != null) {
for (int i=0; i<fileArray.length; i++) {
System.out.println(
"fileArray[" + i + "] = " +
((int)fileArray[i] < 9 ? " " : "") +
( ((int)fileArray[i] > 9 && (int)fileArray[i] <= 99) ? " " : "") +
fileArray[i] + " : " +
" HEX=(0x" + byteToHex(fileArray) + ") : " +
" charValue=(" + (char)fileArray[i] + ")");
return fileArray;
* Sole entry point to the class and application.
* @param args Array of String arguments.
public static void main(String[] args) {
byte[] fileArray = null;
try {
fileArray = getBytesFromFile(new File("c:\\eicar.com"));
} catch (IOException e) {
e.printStackTrace();
if (fileArray != null) {
for (int i=0; i<fileArray.length; i++) {
System.out.println(
"fileArray[" + i + "] = " +
((int)fileArray[i] < 9 ? " " : "") +
( ((int)fileArray[i] > 9 && (int)fileArray[i] <= 99) ? " " : "") +
fileArray[i] + " : " +
" HEX=(0x" + byteToHex(fileArray[i]) + ") : " +
" charValue=(" + (char)fileArray[i] + ")");
Having main method helps you to run the file in JDEVELOPER or using JAVA.
DO not forget to load this class into the database.
And you create the pl/sql wrapper again as follows:
create or replace FUNCTION TOBY (pfilename in varchar2) RETURN VARCHAR2 iS
language java name
'ReadFileIntoByteArray.chk_file(java.lang.String) return byte[]';
And you call the function from sqlplus as follows:
Sql>Set serveroutput on size 20000;
Sql> call dbms_java.set_output(20000);
Sql> Select toby(“filename”) from dual; --
this file should be accessible, I mean you will not be able to send a file on your pc, from sql plus as sql/plus is running on your db server.
You will be able to see the output in sql plus:
If you are running it from the APEX:
When we use file browser widget from APEX, the file is stored in APEX_APPLICATION_FILES table. And we retrieve that into a variable and pass this variable to the function as follows:
DECLARE
scan_failed EXCEPTION;
x varchar2(400);
z number;
BEGIN
select filename into x from wwv_flow_files where name = :P1_FILE_NAME;
select my1.mycheck(x,toby(x)) into z from dual;
if z = 0 then
:P1_SUBJECT:= 'PASSED';
else
:P1_SUBJECT:= 'FAILED';
end if;
:P1_SCAN_RESULT := '** Scanning File **';
IF UPPER(:P1_SUBJECT) = 'PASSED' THEN
BEGIN
:P1_SCAN_FLAG := 'PASSED';
:P1_SCAN_RESULT := :P1_SCAN_RESULT || ' ** File passed scan **';
END;
ELSIF UPPER(:P1_SUBJECT) = 'FAILED' THEN
BEGIN
:P1_SCAN_FLAG := 'FAILED';
:P1_SCAN_RESULT := :P1_SCAN_RESULT || ' ** File failed scan **';
END;
ELSE
BEGIN
:P1_SCAN_FLAG := 'UNKNOWN';
:P1_SCAN_RESULT := :P1_SCAN_RESULT || ' ** Scan Is Not Conclussive **';
END;
END IF;
--IF :P1_SCAN_FLAG = 'FAILED'
-- THEN RAISE scan_failed;
--END IF;
EXCEPTION
WHEN OTHERS THEN
DELETE from APEX_APPLICATION_FILES WHERE name = :P1_FILE_NAME;
RAISE_APPLICATION_ERROR (-20000, 'seb OTHERS error encountered - file upload not allowed. Possible virus detected !');
raise;
END;
ACKNOWLEDMENTS:
1) JOHN SCOTT – who suggested this ICAP API in one of the threads which is my initial starting point in this direction.
2) VLAD KOFMAN who wrote the article on WWW.DEVELOPER.com
3) Mr. KIRAN –One of the engineers from Metalink, who helped me at every step of getting this java programs and pl/sql wrappers working. But for him, I would have not completed my project. -
Scan for file and report back if it exists
Hello,
I am new to scripting and trying to find a way to search for a supposed virus file named wsr[any two numbers]zt32.dll on a large group of computers. I'm not sure how or where to use Get-ChildItem -Path C:\Users -Filter ?zt32.dll -Recurse | export-csv
C:\scripts\output\test.csv in this script.
The below script keeps erroring out when I try messing with the Test-Path options and I'm not sure where to use Get-ChildItem or whatever to get this working. Thanks
# Edit these variables to fit your enviroment
# Set file to be tested for, put everything after c:\
# “c:\Users\Default” is the example path
$filetofind = ‘wsr*zt32.dll ‘
# Hostnames TXT Location
$hostnamestxt = ‘C:\scripts\computernames.txt‘
# Destination file for Online Machines
$onlinetxt = ‘C:\scripts\output\Machines_with_file.txt‘
# Destination file for Offline Machines
$offlinetxt = ‘C:\scripts\output\Offline_Machines.txt‘
# Begin Executing Script – Do Not Edit Below This Line
$computers = get-content “$hostnamestxt”
write-host “———————————————-”
write-host “Scanning hostnames from $hostnamestxt…”
write-host “———————————————-”
foreach($computer in $computers)
ping -n 1 $computer >$null
if($lastexitcode -eq 0)
if(test-path “\\$computer\c:\users\* -include $filetofind”)
echo “$computer” | Out-File -Append “$onlinetxt”
write-host “File FOUND on $computer”
else
{write-host “File NOT found on $computer”}
else
echo “$computer” | Out-File -Append “$offlinetxt”
write-host “$computer is OFFLINE/DID NOT RESPOND TO PING”
write-host “———————————————-”
write-host “Script has completed please check output.”
write-host “Hosts with file output location – $onlinetxt”
write-host “Hosts that were unpingable output location – $offlinetxt”
write-host “———————————————-”Although this works, it appears to be very slow. Also, the Offline machines are not getting logged. Is there a way to speed this up? I am reading about how gci is slow over UNC, but I'm going to have to research this more. Thanks
This makes the third time you have demanded someone custom build a solution for you. You need to step back and think about what you are doing. The solution was provided as you asked for it. You lack of technical experience led you to ask
fot a now unworkable solution so you are asking for more free consulting and a new solution.
As Bill has pointed out this should be done with AV software as just finding the fiole will accomplish nothing. If your system is infected you need to rake more aggressive steps and you should not be trying to write a scripted solution for this kind
of thing aunless you have the technical sjkills to understand what it is you are doing.
All remote scan methods are very slow. To do a local scan requires emoting to be installed and that you know how to use it, Once remoting is installed a single line will get you the file existence. Adding an AsJob will get you concurrent
scanning. You will need to learn how to use PowerShell and WMF remoting to proceed with this. An AV scanner 2would be more valuable and it would protect you in the future.
Also as I posted before this is a very weak construct for file scanning on a network.
$g = get-childitem \\$computer\c$\user\*
-recurse -ErrorActionsilentlycontinue
|? {$_.name
-match "wsr[0-9][0-9]zt32.dll"}
The following will be much faster.
$g = get-childitem \\$computer\c$\user\* -Include
wsr*zt32.dll -recurse
-ErrorActionsilentlycontinue
¯\_(ツ)_/¯ -
Hi!
How do I look for files (e.g. jpg) on the device or media card? Like in drives/folders in windows?Go to your Media icon and open it, press the Menu key and then EXPLORE.
1. If any post helps you please click the below the post(s) that helped you.
2. Please resolve your thread by marking the post "Solution?" which solved it for you!
3. Install free BlackBerry Protect today for backups of contacts and data.
4. Guide to Unlocking your BlackBerry & Unlock Codes
Join our BBM Channels (Beta)
BlackBerry Support Forums Channel
PIN: C0001B7B4 Display/Scan Bar Code
Knowledge Base Updates
PIN: C0005A9AA Display/Scan Bar Code -
How to search for file in jsp page
i need help on how to search for a file in a folder where there is a lot of subfolder.like how u search in a document in windows. i need a complete codes in jsp page.
thank you in advance.
Message was edited by:
n_dilahno i need to do a search engine in jsp page which is the j2ee.
i type smth than tat file from any folder will appear the same way when u need to search your file in a document in windows.
well can u nice people tell me where i can get the codes bcos i stinks when it come to programming.
thank you very very very much. -
How to search for files using wildcards * and ?.
Hi All,
I've been searching the forum for a couple of hours now and have been unable to find a good example of how to search a directory (Windows OS) for a file using wildcards * and/or ?. Does anyone out there have a good example that they can share with me?
ThanksHi All,
First of all I want to thank everyone for taking the time to respond to my question. All of your responses where greatly appreciated.
I took the example code that was posted by rkconner, thanks rkconner, and modified it to allow me to search for files in a directory that contain * and/or ?. Yes, I said and/or! Meaning that you can use them both in the same file name, example: r??d*.t* would find readme.txt.
I've posed my complete and thoroughly document code below. I hope it is very helpful to other as I have searched many forums and spent many hours today trying to resolve this problem.
Enjoy
* File Name: WildcardSearch.java
* Date: Jan 9, 2004
* This class will search all files in a directory using the
* asterisk (*) and/or question mark (?) as wildcards which may be
* used together in the same file name. A File [] is returned containing
* an array of all files found that match the wildcard specifications.
* Command line example:
* c:\>java WildcardSearch c:\windows s??t*.ini
* New sWild: s.{1}.{1}t.*.ini
* system.ini
* Command line break down: Java Program = java WildcardSearch
* Search Directory (arg[0]) = C:\Windows
* Files To Search (arg[1]) = s??t*.ini
* Note: Some commands will not work from the command line for arg[1]
* such as *.*, however, this will work if you if it is passed
* within Java (hard coded)
* @author kmportner
import java.io.File;
import java.io.FilenameFilter;
public class WildcardSearch
private static String sWild = "";
* @param args - arg[0] = directory to search, arg[1] = wildcard name
public static void main(String[] args)
String sExtDir = args[0]; // directory to search
sWild = args[1]; // wild card to use - example: s??t*.ini
sWild = replaceWildcards(sWild);
System.out.println("New sWild: " + sWild);
File fileDir = new File(sExtDir);
File[] arrFile = fileDir.listFiles(new FilenameFilter()
public boolean accept(File dir, String name)
return (name.toLowerCase().matches(sWild));
for (int i = 0; i < arrFile.length; ++i)
System.out.println(arrFile.getName());
} // end main
* Checks for * and ? in the wildcard variable and replaces them correct
* pattern characters.
* @param wild - Wildcard name containing * and ?
* @return - String containing modified wildcard name
private static String replaceWildcards(String wild)
StringBuffer buffer = new StringBuffer();
char [] chars = wild.toCharArray();
for (int i = 0; i < chars.length; ++i)
if (chars[i] == '*')
buffer.append(".*");
else if (chars[i] == '?')
buffer.append(".{1}");
else
buffer.append(chars[i]);
return buffer.toString();
} // end replaceWildcards method
} // end class -
How to put a file lock on the contents of a folder and sub folders?
Initally I recursively went through the children of the folder and created a file lock for each child, however after abour 2025 locks i recieved a Too many open files exception.
Is it possible to lock a folder such that the contents of the folder cannot be changed? and would that stop the Too many open files Exception?Hmm.... I would have thought that this was a reasonably common problem. If no-one here can help directly, can someone point me to a forum or similar which may be able to help me?
Cheers -
Please answer. how to search for files
Hi,
We need an integration with SAP. They send us files in the format: yyyymmddhhmiss.atv
For example we receive following files:
20050503101115.atv
20050504101115.atv
20050505101115.atv
So, we dont know how to search for all files with extensions ".atv" in the directory.
We are using PLSQL. Is there some way to resolve with UTL_FILE?
Any other suggestion?A possibility:
In sqlplus, issue a HOST command to list the files to a file:
ls *.atv > atv_dir.txt
Then use utl_file to read atv_dir.txt and parse it for the file names.
You could put the filenames in a pl/sql table and use that as loop control. -
Hi, I'm trying to make a program that scans for multiples of tree. When the program is executed, you have to give the lower and upper limit and the program tells you how much multiples of tree are in the limit. I thought of making a loop where in the number is devided by tree, it can result as an integer or not, but how can i use the scanner to scan for integers??
Greetings JordyHi, I'm trying to make a program that scans for
multiples of tree. When the program is executed, you
have to give the lower and upper limit and the
program tells you how much multiples of tree are in
the limit. I thought of making a loop where in the
number is devided by tree, it can result as an
integer or not, but how can i use the scanner to scan
for integers??
Greetings Jordy1. Are you talking about a tree or the number three?
2. Why would you use Scanner to determine if a number is divisible by three? (Am I missing something).
3. Loop through the range and use mod to determine if there is a remainder. -
How to scan for Values (matching)
Hi all,
how is it possible to scan for value matchings with oracle nosql?
e.g.:
I have the following structure:
Person / Smith / ZipCode
Person / Elison / ZipCode
and I want to retrieve all items in the database where the value of "ZipCode" equals a specific number or range.
How is this possible (with java)?
Thanks for your help,
MarioHi Mario,
What I couldn't tell from your original post was whether the ZipCode is part of the key or the value. If it's part of the key, then what you can't do is wildcard any piece of the key before the Zip Code. For instance, you can't do a wildcard like this:
/Person/*/90210/
Nor can you do a range query like this:
/Person/*/11111 -> /Person/*/22222
In any case, whether the zip code is part of the key or the value, you will still have to retrieve the records and check the zip code in your own code.
Charles -
How to scan for Delimiter?
Hi there,
My Vi is reading data from a bar code scanner. I would like to stop my while loop by reading the terminal string "/s" from the bar code that been scanned.
May I know to "scan" for the terminal string?
Thanks & Regards,
NormanHi Chris,
Thank you for your value reply.
When I add your solution to my vi it don't work well. Because I'm using Global variable to pass the data. Can help me to take a look of my vi and let me know where I can improve with?
To stop the while, I have try Match pattern, however it don't really work because it can't read the "/s" termial char.
I also tried Scan String For Token, it works however I not very sure whether it is the correct method to use or it is not?
Thank you in advance for the reply,
Best Regards,
Norman
Attachments:
Model_Read_Global.vi 10 KB
BarCode&Weight.vi 134 KB
BarCodeCtrl.ctl 7 KB -
How to scan for the viruses while uploading a file
Hi!!,
I have an appliaction written in java wherein I take as an input .xls file.
I want to have same facility for uploading other fils also, but I need to check
for the viruses before I keep it on my server.
Please suggest me how can I do this??How do you update the other fields of the database table?
I assume your database table has some fields like Changed by , Changed On, Change time etc., in its definition.
If you are making a direct table update, pass the SY-UNAME, SY-DATUM/SY-DATLO, SY-UZEIT/SY-TIMLO to the respective fields in your table along with the data modified.
Rgds
Vijay -
Adobe Reader X: How to disable resource file locks of PDFs
Hi,
I develop PDFs using LaTeX tools, and like to view my PDFs with Adobe Reader X (I am currently using version 10.1.0.534) on Windows XP.
Unfortunately, I cannot compile my LaTeX documents using pdflatex (or otherwise) when the file these tools are trying to write to are open by Adobe Reader X, which appears to place a resource lock on open files.
Is there any configuration option to prevent the Reader X from placing a resource lock on files? It is frustrating to have to manually close and re-open the reader whenever I recompile my PDFs that I am resorting to other PDF readers, like Sumatra or Foxit, which don't place locks on PDFs they read.
I understand that the resource lock may be a solution for dealing with problems related to ActiveX components for IE, but I only use Chrome and Firefox, so this is an unneccessary and annoying behaviour.
Thanks in advance,
RatzskiThanks for your suggestion, but doing this (kind of thing... as I couldn't exactly follow your instructions as they aren't visible in Reader X 10.1) didn't work.
Can anyone else offer any suggestions? -
How to search for file in a directory or subdirectories?
I need ur help urgently. I'm currently doing a java project in which the program should be able to do file searching.
For eg. if I key in a.jpg, it should display C:\pictures\a.jpg (a.jpg is stored in a folder called "pictures")
But the problem is that my program is only able to search in the C drive only.
If I move the file into a folder in the C drive, my program cannot detect this.
Can you help me to solve this problem? I'm really looking forward for your reply.
Thanks. Here are the codes.
import java.io.*;
import java.awt.*;
class FindFile
public static void main(String args[]) throws IOException
//reads the user input
BufferedReader userInput;
while(true)
userInput = new BufferedReader(new InputStreamReader(System.in));
String s = userInput.readLine();
//quits the system
if(s.equals("/quit"))
System.exit(0);
//if user does not key in anything, prompt msg appear
else if(s.equals(""))
System.out.println("Command Syntax: java ListFiles <filename>");
System.out.println("<filename> - The full name of a file and extension (i.e., test.txt)");
else if(userInput != null)
String t = "c:";
File f = new File(t);
String[] files = f.list();
char[] qwet;
boolean test = false;
//check for the file name and compare with the user input
for (int i = 0; i < files.length; i++)
if(files.equals(s))
System.out.println("");
System.out.println("File Found");
System.out.print("The File Found at This Path: ");
//display the path
System.out.print(f.getAbsolutePath());
System.out.println(files[i]);
test = true;
break;
//if file does not exist
if(test == false)
System.out.println("File Not Found");well, i think the best solution would be make a recursive search through the directory tree. I don't know if you are familiar to this, but the functions that searches for the file would look like this:
public String searchFile(String name) {
File[] roots = File.listRoots(); // List all file roots (in windows the different units, c:, d:, etc.)
for (int i = 0 ; i < roots.length() ; i++) {
String aux = recursiveSearch(roots, name);
if (aux != null) { // If the "recursiveSearch" returns something different than null is that the file is founded, so we return the path.
return aux;
return null; // If we get there nothing has been found
private String recursiveSearch(File f, String name) { // f is the directory to search for the file with name "name"
File[] childs = f.listFiles();
for (int i = 0 ;i < childs.length ; i++) {
if (childs[i].isDirectory()) { // If that is a directory we search inside
String aux = recursiveSearch(childs[i], name);
if (aux != null) { // We have found it inside this directory
return aux;
} else { // Is a regular file
if (name.compareTo(childs[i].getName()) == 0) { // If the file is what we want we return his path
return childs[i].getCanonicalPath();
// If we get here is because the file is not inside the directory or any subdirectory on it
return null;
You should just call the function searchFile(name) with the name of the file you want to search. If it finds one with this name it will return his absolute path, and if he doesn't the desired file he will return null.
If you don't understand anything just ask.
(Note: i have not tested this code, so can be some mistakes, but it think it is almost correct. mmmhh don't now why, but [ & ] appear in my code as < & >. Just replace them.).
Hope that helps.
Zerjio
Maybe you are looking for
-
My ipad2 is acting strangely. I am running iOS 5.1 and in the last several days it has stopped updating applications. If more than 1 app is available for updates, if I say "update all" it will update all of the apps except the last one in the list -
-
I am new to Service module,can anybody give the over view of service module
I am new to Service module,can anybody give the over view of service module including base table and Relation ship with other Oracle Application module.
-
Easily read strings while tracking the number of bytes read?
Hi all, I'm after a way to easily parse and read strings from a file, while also being able to check (at any point) how many bytes have currently been read from that file. I currently use the following for the string processing: BufferedReader in = n
-
How does one overlap text and images
I have the text box and the image on the Pages doc and when I move either to overlap the other, the one not selected "darts" away
-
HT5622 how do you find out what your rescue email address is
I have a new iphone. It asks me security questions to verify my identity. I forgot answers and therefore it sends information to my rescue email to change questions. How do I find out what my rescue email is?