Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

How do check for active files from a Batch file.


  • Please log in to reply
3 replies to this topic

#1 Ripcord52

Ripcord52

  • Members
  • 66 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:01:47 PM

Posted 11 August 2013 - 03:41 PM

I've been writing my first batch file, with the purpose of archiving files and to make it easy for the users to...use. I'm down to the point where it is almost ready to deploy, hopefully.

I'm writing the batch file on my XP machine. I expect to put the batch on the local server (2008 R2) with a shortcut to run it on each of the two client machines, which each run Win 7.

 

As long as the shortcuts have appropriate permissions, there shouldn't be a problem there. (Unless someone here points out otherwise.)

 

The main concern I have now is active files.

 

The files being archived are rather numerous and include sub-folders. Most of the files are generated in Excel although a couple other programs are involved as well. Most of the programs are hosted on the server, although one or two are hosted on one or both of the client machines. So I have a mixed bag of events here.

 

Note: As I'm writing this on XP, without the assistance of batch writing software, some commands are not available to me, such as 'robocopy' Thus far these limitations have not stopped me but for writing/testing purposes, I cannot use such commands.

 

 

I wish to avoid a problem where activating the batch file has it trying to archive a file that is currently in use. How can I do this?

 

If more information is needed, just ask.

 

 

 

 

 



BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:11:47 AM

Posted 11 August 2013 - 07:13 PM

I wish to avoid a problem where activating the batch file has it trying to archive a file that is currently in use. How can I do this?

Just try to archive the file. If the file is in use, the move operation will fail due to a sharing violation.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 Ripcord52

Ripcord52
  • Topic Starter

  • Members
  • 66 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:01:47 PM

Posted 11 August 2013 - 08:32 PM

Indeed, but to the operators there would be no indication of the failure and they are unlikely to check the archive folder to see if it worked or not. Plus, I don't need an error statement saying so as there could be any one of multiple programs causing the error to occur. I'm trying to keep this "operator friendly" as much as possible. Their problem will be immediate but my availability to resolve it will not.

I'll have to look at the current archives and make a list of which programs generate the files contained therein. Then I'll need a method of finding out if any of those programs are running at the time of the batch file run and, if so, display a statement to the operators which program needs to be closed before continuing with the archive.

Bear in mind that although my computer skills are "limited", they tower above those of the operators.

 

Granted, in the end I may have to go 'as is' and hope the operators will at least check the backups or taking place and/or recognize they need to ensure certain programs are closed before archiving.

I'm really trying to avoid that though.



#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:11:47 AM

Posted 12 August 2013 - 12:37 PM

Considering Windows provides no API to get this information at the C level, I don't think you're going to be able to find that out in a batch script. (Yes, the shell has some detection for this, but I'd assume that's powered by inspecting the system handle table, which requires calling undocumented APIs)

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users