How do I autorun my Python script when I plug in my USB device? - windows

I want to execute my Python script (at root, "autorun.pyw") whenever my USB device is plugged into a port.
I don't want to install any software. I am using Windows 10, and I have tried using an autorun.inf file.
Help would be greatly appreciated.

First Step: Install software
Restore the auto-run function To restore the "auto-run" function, the first thing we will need to do is download APO USB Autorun, a small free program that monitors the USB devices connected to the computer. Once installed, whenever you connect a USB storage device, such as a USB stick, it will check if there is an autorun.inf file inside the device and will run the configured program.
Second Step: Create autorun.inf
Create the autorun.inf file To automatically run a program from the flash drive, it needs to have two things, the program you want to run automatically and a script file that points to the program on the flash drive. Copy the executable file of the program you want to run to the pendrive. Then open the notepad, copy the text below and paste it into the notepad window to create the autorun script. [autorun]; Open = MEUAPP.exe ShellExecute = MEUAPP.exe UseAutoPlay = 1 Once you have pasted the text in the notepad, replace the text “MEUAPP” with the name of the program file you copied to the USB stick that will run automatically, as shown in the example below. Then, save the file to the USB stick named autorun.inf. Important: Make sure to select the option “All files (*. *)” In the “Type” field so that the file is saved with an INF extension and not a TXT extension. The flash drive should now contain the program's executable file and the autorun.inf file you just created. You can use the USB stick to place other files, but be sure to keep both files. Note: If the portable program has multiple files, you can copy its folder to the USB stick, just make sure to enter the path in the ShellExecute field. Ex: ShellExecute = PASTADOAPP \ MEUAPP.exe.
Final Step: Configure and run automatically
Run the program automatically: Once this is done, whenever you connect the pendrive to the computer, APO USB Autorun will detect your autorun.inf file inside the pendrive and will automatically run the program you have configured. Finally, note that you will need to install APO USB Autorun on all computers where you want to use autorun. Still, it can still be useful if you work on the same computers.

Related

Is there a way in Windows 10 to create a virtual link from an UNEXISTING file to an existing one?

I'm using Windows 10 on a device that has only one SSD formatted with NFTS, the drive letter is C:\
I have an application that looks for a file located in D:\afolder\needed.file (I can't change this)
Is there a way to put the file needed.file in C:\ and create a virtual link so that this application thinks is working on D:\afolder\needed.file but transparently the OS is redirecting it to the file located in C: ?
I tried with the command
mklink /H D:\afolder\needed.file C:\needed.file
but I receive the error
Local NTFS volumes are required to complete the operation.
Maybe it is because the drive D: doesn't exist at all on the device?
Is there a way to make it work?
NOTE: The SSD of the device is formatted with NTFS and I run the command mklink with admin privileges

Running vbscript in Windows when a USB Flash Drive is connected

I am looking for a ( VBS or BAT or ...etc ) that I will put it in my PC (Windows). And when a USB Flash Drive is connected to my PC, this VBS will run another VBS that is located also in my PC in order to do some tasks.
you can try an autorun file on your USB disk
Autorunning program from CD or USB on Win7/8
you can also try the powershell procedure given at this page
https://superuser.com/questions/219401/starting-scheduled-task-by-detecting-connection-of-usb-device

How to create a universal windows shortcut?

I have created a shortcut for my program (under Windows 7), whose target is in a sub-directory. But when I zip everything and send it to my colleague, the shortcut wont work because it the target directory cannot be found, it is like:
Target: C:\Users\my_user_name\Desktop\my_program\sub_directory\my_program.exe
and the shortcut is in C:\Users\my_user_name\Desktop\my_program\
When I send it to another PC, my_user_name directory cannot be found and shortcut doesnt work. How to solve this?
Create a batch file that launches the program. You can then use a relative path.
e.g.
C:\Users\my_user_name\Desktop\my_program\launch.cmd
cd sub_directory
start my_program.exe
possible solutions:
place the program with the exe on disk like c:\program\programname\ Location must be the same on all computers.
place the program with the exe on the network where you can both access, shortcut is the same
edit the shortcut in notepad and change the user

How to test for floppy in drive?

I am using Windows XP Pro with Service Pack 3.
I have a .bat file that tests if various drives are available, and if they are then the bat file writes a little script that another program, an exe file, uses.
The problem is when the bat file issues the command to test if a disk is in the floppy drive, Windows generates an error and a message box. Windows is doing its own testing and pops up a message box, which halts my bat file. I don't want Windows to do the testing.
Here is a short bat file I wrote to demonstrate the problem:
#ECHO OFF
CLS
REM TEST FOR FLASH DRIVE
IF EXIST G:\NUL (
ECHO Flash Drive found
)
REM TEST FOR FLOPPY DISK IN DRIVE
IF EXIST A:\NUL (
ECHO Floppy in Drive
)
How do I test for a floppy without Windows getting in the way?
you can remove the null operator, and have it just try the A: drive. This works for windows 7 so it might work for windows xp. or you can use a power shell command that list all active drives which is
get-psdrive.
Power shell has the ability to run commands like cmd with some more built in features.

Is it possible to have auto-run script to open up a certain file when a thumbdrive is inserted?

I am trying to find a way to make an auto-run script that when you inserted a thumbdrive into a pc it would open a certain file on the thumb? would be for windows 7
Create an autorun.inf file in the root of the thumbdrive.

Resources