How to determine first run of an app/How to allow file delete in app folder - file-permissions

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.

Related

Linux bash to compare two files but the second file must be find

I have a batch that integrates an xml file time to time but could happens daily. After it integrates it puts in a folder like /archives/YYMMDD(current day). The problem is if the same file is integrated twice. So I need a script what verifys the file (with diff command its possible but risky to make a bottleneck) but the problem is I can't find to resolve how to make to give the second files location.
P.S. I can't install on the server anything.
Thanks in advance.

Batch file that detects when its being copied?

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

Can't Overwrite CSV file if Open

I'm using powershell to export-csv a table. If the csv file is open anywhere on the network, the script will not overwrite the file. Is there anyway to work around this?
You would need to change how the network deals with users opening the files.
Usually, when a user (who is not an admin) opens a file on the network, you want the user to open it as read-only.
Only then, you will be able to overwrite the file using your script (with admin privs ofc)
If you do not have control over the network, the best option would be to create a different file with the same name but with revision number at the end. For example, "a.csv" would become "a001.csv" after the first edit.
Because of the nature of the solution, it will create havoc if multiple users are working on the same file.
In this case, I would suggest looking at version control softwares... But then again, it would be silly to go through all this for just editing a simple .csv file.. So, the answer is "it's complicated"

shell script to create backup file when creating new file in particular directory

Recently I was asked the following question in an interview.
Suppose I try to create a new file named myfile.txt in the /home/pavan directory.
It should automatically create myfileCopy.txt in the same directory.
A.txt then it automatically creates ACopy.txt,
B.txt then BCopy.txt in the same directory.
How can this be done using a script? I may know that this script should run in crontab.
Please don't use inotify-tools.
Can you explain why you want to do?
Tools like VIM can create a backup copy of a file you're working on automatically. Other tools like Dropbox (which works on Linux, Windows, and Mac) can version files, so it backs up all the copies of the file for the last 30 days.
You could do something by creating aliases to the tools you use for creating these file. You edit a file with the tools you tend to use, and the alias could create a copy before invoking a tool.
Otherwise, your choice is to use crontab to occasionally make backups.
Addendum
let me explain suppose i have directory /home/pavan now i create the file myfile.txt in that directory , immediately now i should automatically generate myfileCopy.txt file in the same folder
paven
There's no easy user tool that could do that. In fact, the way you stated it, it's not clear exactly what you want to do and why. Backups are done for two reasons:
To save an older version of the file in case I need to undo recent changes. In your scenario, I'm simply saving a new unchanged file.
To save a file in case of disaster. I want that file to be located elsewhere: On a different computer, maybe in a different physical location, or at least not on the same disk drive as my current file. In your case, you're making the backup in the same directory.
Tools like VIM can be set to automatically backup a file you're editing. This satisfy reason #1 stated above: To get back an older revision of the file. EMACs could create an infinite series of backups.
Tools like Dropbox create a backup of your file in a different location across the aether. This satisfies reason #2 which will keep the file incase of a disaster. Dropbox also versions files you save which also is reason #1.
Version control tools can also do both, if I remember to commit my changes. They store all changes in my file (reason #1) and can store this on a server in a remote location (reason #2).
I was thinking of crontab, but what would I backup? Backup any file that had been modified (reason #1), but that doesn't make too much sense if I'm storing it in the same directory. All I would have are duplicate copies of files. It would make sense to backup the previous version, but how would I get a simple crontab to know this? Do you want to keep the older version of a file, or only the original copy?
The only real way to do this is at the system level with tools that layer over the disk IO calls. For example, at one location, we used Netapps to create a $HOME/.snapshot directory that contained the way your directory looked every minute for an hour, every hour for a day, and every day for a month. If someone deleted a file or messed it up, there was a good chance that the version of the file exists somewhere in the $HOME/.snapshot directory.
On my Mac, I use a combination of Time Machine - which backs up the entire drive every hour, and gives me a snapshot of my drive that stretches back over a year and a half) and Dropbox which keeps my files stored in the main Dropbox server somewhere. I've been saved many times by that combination.
I now understand that this was an interview question. I'm not sure what was the position. Did the questioner want you to come up with a system wide way of implementing this, like a network tech position, or was this one of those brain leaks that someone comes up with at the spur of the moment when they interview someone, but were too drunk the night before to go over what they should really ask the applicant?
Did they want a whole discussion on what backups are for, and why backing up a file immediately upon creation in the same directory is a stupid idea non-optimal solution, or were they attempting to solve an issue that came up, but aren't technical enough to understand the real issue?

Corflags.exe cf001 Could not open file for wiriting

I am trying to edit the corflags file so that I can run 32bit applications on a 64 bit pc but everytime I try to edit the file using something like corflags.exe assembly /32bit+ it comes up with the error message cf001 could not open file for writing.
Now I have tried a lot of different options such as:
Running in administrator mode;
Finding the file using a search and checking read only is not ticked
Checking that user full control is ticked
Tried to set the whole folder to non read only
When trying the whole folder, it goes through looking like it has set read-only, but then I click OK and re-right click on the whole folder, the box is filled in (not ticked) does this mean that part of the folder is read only and why does it reset to read only?
I just faced the same problem and have tried the same things.
Run cornflags from an elevated ("Run as administrator") Visual Studio Command Prompt. I did the same for a copy of the original .exe just to make sure no other process was using the program.
Create a copy of the file you intend to target with CorFlags.
(e.g. "WcfServiceHost.exe" --creates--> "WcfServiceHost - Copy.exe")
Rename the original file to something else:
(e.g. "WcfServiceHost.exe" --> "WcfServiceHose_Original.exe")
Rename to copy to the original file name
(e.g. "WcfServiceHose - Copy.exe" --> "WcfServiceHost.exe"
For my purposes, I created copies and named them describing their configuration:
Example:
WCFServiceHost_With32BitOn.exe
WCFServiceHost_With32BitOff.exe
Now I can destroy the WCFServiceHost.exe files and create them from these pre-modified copies. No more CorFlags operations necessary.
Note: this is basically a more verbose version of #RMalke answer and that answer should be marked as the answer.
I realise this is years later, but for anyone else looking, I found that the quickest way was to copy cmd and corflags.exe into the same folder as the one you want to edit. Then run cmd as admin from there.

Resources