Remove autorun.inf from pendrive automatically - vb.net

I've made a simple application to automatically remove autorun.inf from pendrive.
My algo is very simple, at an interval the app runs how many drive is there if it gets a Removable disk it tries to delete autorun.inf file.
But i want to optimize it by removing the timer.
How to do it ?

Your question isn’t to clear. I assume you mean you want your application to run every time a USB drive is inserted? You should be able to do it using a managementeventwatcher.
http://msdn.microsoft.com/en-us/library/system.management.managementeventwatcher.aspx
This component runs a query you provide on your computers WMI instance. WMI will detect your USB drive and then your watcher will raise the event.

Related

Raspberry Pi 3 (Raspbian) programatically accessing a USB drive: best way to do this?

I'm running Raspbian 1.0, v9/15 on an RP3. I'm working on an application that will access a dedicated USB flash drive to store collected data. The static path to write the data is "/media/user/kingston". This works great unless I have a system crash at which point the owner and group for "/media/user/kingston" are changed to root, and the mount point for the flash drive now is now changed to "/media/user/kingston1" which (clearly) does not work with the static path defined in my application. Is there a standard dynamic path option that is available for this device and OS? Thanks in advance...
Update: Based on BJ Black's advice, this is what I added to fstab after creating a directory named /usb at the root of the filesystem,
/dev/sda1 /usb vfat noatime,nofail,user,rw,exec,umask=000 0 3
The advantages are,
1) allows bootup even when no USB drive is inserted,
2) allows any usb storage device to be used here.
Disadvantage is that the system must be powered down (or drive umounted) before flash drive is removed otherwise bad things happen, (I tried this). Question: Is there anything that I can do to reduce the "bad things" in the event that someone pulls out the usb while it is still mounted? Thanks in advance.
In general, I tend to prefer using a hard mount point for this kind of thing. There are possibly some neat tricks in /sys (or by using a grep against the output of mount(1) or /proc/mounts), but they'll fail as soon as you change out your Kingston stick for some other vendor (yuck).
Have a look at this link to better understand what's automounting your usb stick and how to shut that mechanism off.
As for mounting in a permanent place, I'd try either:
Create a mount point (say /data) and put an entry in fstab(5) so it gets mounted automatically on boot.
Same as 1, but use the noauto and user and do an explicit call to mount(1) from your application, or...
Install autofs and put an entry in auto.misc to automount the device (probably /dev/sda1) on use. Then symlink /data -> /misc/data.
Of these, I like option 3 the best, as the stick will unmount automatically when idle. Then your application need only double-check that the path is writable beforehand.
Also be super-careful on writes, as cheapie USB sticks tend to erase in large blocks and their wear levelling is weak at best (so both small random writes and large writes tend to wear the flash fast). Using f2fs or careful write buffering helps (and the noatime option on mount helps). And don't call fsync() all the time in your app!

Check if Dropbox has synced

Before I look into this any further I just wondered if it's possible within VB.net to check if DropBox has synced?
Basically the program I have written uses DropBox to synchronize jobs to a Main computer which then ultimately process the zip file and deletes it. Once the job is processed a text file is re synced and the person who originally sent the job gets feedback as to its progress. All this works great. However, I would like to give an indication within the program itself so some of the less computer literate can see that DropBox has synced and they can safely turn off there laptops and head off home.
Has anybody any experience of this?
You could use the Dropbox API to do the upload/download instead, at which point you'd know exactly when things had happened.
See https://www.dropbox.com/developers for information about the API.

In OSX (Mountain Lion) Only allowing an application to open if a condition is met

Is there any simple way to do this?
I basically want iTunes to not open if an external hard drive is not connected. This is essentially a user issue - as despite asking multiple times, my girlfriend will forget and open an audio or video file without the external HDD connected (where the iTunes library is kept) and so the usual rigamarole occurs... the media file will then try and add itself to the iTunes library, which can't be found, so it'll default back to it's position on the internal hard disk, and then when I come to use it, it'll try and consolidate it for me (which is nice), except it then decides it needs to organise it - and this takes about 6 hours due to the amount of music I have on there.
I've tried changing the internal (default) iTunes music folder path to an alias to the external one, but that starts throwing out some beastly errors once you get into the loop (when the alias is essentially a pointer to an invalid location).
Is Automator something that could be used? Sorry I'm not very pro with OS X I'm afraid.
Thanks,
Duncan
It seems a straightforward way to do this is just to move the iTunes.app onto the external hard drive, and replace iTunes.app in the Applications folder with an alias pointing to iTunes on the external HDD (called iTunes).
As iTunes is system protected, you'll need to change the permissions of iTunes.app to move it, which you can do via gui or terminal (sudo chmod...)
Simples.

Prevent locks on shared applications [duplicate]

This question already has answers here:
Don't lock files of application while running
(4 answers)
Closed 9 years ago.
I created a small application which users launch through a desktop shortcut pointing to a network share. Whenever I recompile the app and want to move it to the network share to make it available, it is always locked by many users who are using it, understandably. What I don't get is that I can close all the handles (net file 1234 /close) and the users are unaffected, i.e. they can still work on the app. I then copy the new file and ask them to restart.
Is there a way to "cut off" programmatically the users from the network exe file once they have launched it, so that I don't have to manually close all of the handles every the time?
They'll be affected but the way the jitter works indeed makes it a bit unlikely that their program will crash. Crashes are likely when you use Reflection in your code or the user's machine is under memory pressure from other processes and the program executes code that has not been jitted. YMMV.
The proper deployment choice here is ClickOnce. That creates a local copy of the program on the user's machine. And it automatically sees your update when they restart.
A possible band-aid is renaming the executable. Which works because Windows puts a lock on the file content, not the directory entry. Which lets you copy the update with the same name. Any user that restarts the app will now get the new version. You'll eventually be able to delete the renamed file. But do favor ClickOnce first.

File system operations (e.g. copy, delete, move) performed through ActiveSync - are they atomic?

I am developing an application in .NET Compact Framework 3.5, for Windows CE 6. I need to automate some data synchronization between the mobile application and a PC. So what I do is that, in the .NETCF application, I have a while loop that checks every few seconds, using System.IO.File.Exists(fullFilePath), whether the file I am expecting has been copied from the PC to the mobile device, through an ActiveSync connection.
Once the mobile app finds the file, it will open and read it using a StreamReader.
My problem is that, some times, File.Exists(fullFilePath) would return true, yet the subsequent use of StreamReader may fail with a FileNotFoundException.
Ruling out the possibility of the file getting deleted between the call to File.Exists() and the instantiation of the StreamReader, would anybody know how the exception may occur? Is it because file copy through ActiveSync is not atomic, such that the file is not actually ready for reading even though File.Exists() returns true?
A file copy is most certainly not going to be atomic. When you start the copy, the file is created, but has no data in it. As the file data gets written, the file "exists", but is not yet fully complete. You'd want to know not only that it exists, but that it's not currently in use (meaning the writer is done). Trying to open it exclusively would verify that.