Please can someone help me create a batch file that detects when its being copied.
I am pretty good with batch but all I want to do is put a security warning on my batch program like this: "Do Not Copy This File Or It Will Be Deleted!" then it deletes itself when the user try's to copy it (so it can't be stolen etc...)
A running program can lock the file so that nothing else can open it. I'm not sure how to do this in a batch script, but I assume that there's some way that it could lock itself. But if the file is just sitting there and no other running process has it locked, that won't work.
Why can't you use file permissions to prevent others from accessing the file?
Not that this will prevent anyone of reading the file and copy it nevertheless...
if not "%computername%#%~df0"=="AKOYA#C:\Users\Stephan\test\4\s.bat" echo this has been copied!! & del %~df0
Related
My macro creates 1 identical txt files. One file is written to a shared network drive and the other file is written to a user personal drive. The file names are identical.
Each file should have a Total Line. Some files are created without a Total Line and this causes issues in downstream processing. If we could isolate that issue, then this question is irrelevant. However, we have not found the cause of the missing Total lines.
My solution was to check to check the shared network to see if the file exists. So far so good as that works.
Next I read the file (shared network drive) to see if the total line is found. That works as expected.
If the total line isn't found, I want to use this code to delete both files:
Kill vFileName
Kill vFileName2
vFileName and vFileName2 contain the path and file name including extension.
When the code runs, the first "kill" command is executed as expected.
When the 2nd "kill" command is executed, the macro exits the subroutine, without deleting the file, and continues running.
I added a On Error GoTo 0 to see what the error message is but there is no error message. I'm not sure what is going on. Any suggestions as to what is going on and why the 2nd file is not deleted would be appreciated. Thanks in advance for your help.......
I need to test a program that creates temporary file. When run finishes it deletes the file. How can I check it file has be created and deleted.
I am thinking about sending some signals to process (like Ctrl-Z) to suspend it and check but should be simpler ways.
I am using bash in Linux.
Since you don't have access to the program code, then you could use the strace tool to intercept all the system calls issued by the process. Then with simple greps you can look for file creation, deletion and all related operations. Probably you have to use the "-f" option to make sure everything is logged including the operations performed by any process's child
If you can, with some certainty, know when the file will be created you can use the link command to hang onto the file. For example, in the code you are testing there is a sequence like:
open some temporary file for writing
# do stuff
write stuff to open file
close file
unlink file
If, in between the open and unlink in the tested program, you can run
ln the_temp_file my_temp_file
then when the unlink occurs, the tested program will have no idea that you have a hard link to the file so it didn't get removed from the file system.
This will not work for symbolic links ln -s so your link will need to be on the same physical device.
I have an old VB6 app that I'm distributing with the PDW. I need to determine after installation if it's the first run of the app. What's the simplest way to do this?
Currently, I install a dummy text file and use its existence as evidence of first run. If firstrun.txt is in the app directory, I open a subroutine that creates some directories and copies some files and then deletes the txt file. The next time, it skips the subroutine because firstrun.txt isn't there. Works perfect until users get an error code 70 because they don't have the appropriate permission to delete the file.
This is the code I'm using to delete the text file:
mobjFSO.DeleteFile App.Path & "\firstrun.txt
Anyone have a better way? Or could someone tell me how to allow the program to delete the file regardless of permisson?
Thanks in advance!
Try the opposite approach. If no file exists, assume it is the first run. After the first run does its thing, write a file -- but write it to a user area, such as C:\Users\myuser\AppData on Windows. This would be a more appropriate place to store this kind of data and you won't suffer the same permissions issues.
I using centos5.8
I wonder why syslog stop writing log after certain log edited.
for example, after cut the line of /var/log/messages, syslog doesn't write new log.
Just old logs are remained.
But If I delete the messages file and reboot the system, syslog works fine.
Is there any ways, syslogd write new logs continuosely after edit certain log??
It depends how exactly a file is edited.
Remember that syslogd keeps the file open for continuously writing. If your editor writes a new file with the old name after unlink()ing or rename()ing the old file, that old file remains in operation for syslogd. The new file, however, remains untouched.
It can be informed about the new file to be used with the HUP signal.
Well, that would depend on how syslogd works. I should mention that it's probably not a good idea to edit system log files, by the way :-)
You may have been caught out by one peculiarity of the way UNIX file systems can work.
If process A has a file open and is writing to it, process B can go and just delete the file (either with something like rm or, as seems likely here, in an edit session which deletes the old file and rewrites a new one).
Deletion of that original file does not destroy the data, it simply breaks the link between the file name (the directory entry) and that data.
A process that has the original file open can continue to write to it as long as it wants and, since there's no entry in the file system for it, you can't (easily) see it.
A new file with that file name may be bought into existence but process A will not be writing to it, it will be writing to the original. There will be no connection between the old and the new file.
You'll sometimes see this effect when you're running low on disk space and decide to delete a lot of files to clear it up somewhat. If processes have those files open, deleting them will not help you at all since the space is still being used (and quite possibly the usage is increasing).
You have to both delete the files and somehow convince those processes holding them open to relinquish them.
If you edited /var/log/syslog you need to restart the syslog service afterwards, because syslogd needs to open the file handle again.
I have doubt in the following scenario
Scenario:
A process or program starts with opening a file in a write mode and entering a infinite loop say example: while(1) whose body has logic to write to the opened file.
Problem: What if i delete the opened or created file soon after the process enters the infinite loop
In Unix, users really cannot delete files, they only can drop references to files. The kernel deletes the file when there are no references (hard links and open file descriptors) left.
From what you're saying, it sounds like in reality you don't want an infinite loop, but rather a while loop with some flag, something to the effect of
while (file exists)
perform operation
Add a line that checks to see if the file exists during the while loop. If it doesn't exist, kill the loop.
It appears that what happens is that your file disappears (basically).
Try this, create a file test.py and put the following in it:
import os
f = open('out.txt', 'w') # Open file for writing
f.write("Hi Mom!") # Write something
os.remove('out.txt') # Delete the file
try:
while True: # Do forever
f.write("Silly English Kanighit!")
except:
f.close()
then $ python test.py and hit enter. Ctrl-C should stop the execution. This will open, then delete the file, then continue writing to the file that no longer exists, for the reasons that have previously been mentioned.
However, if you really have a different question such as "How can I prevent my file from being accidentally deleted while I'm writing to it?" or something else, it's probably better to ask that question.