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

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.

Related

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

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.

Batch file to rar and password (very specific)

I was trying to make a batch file that compresses a specific folder (using winrar) to a specific location (not the same as the folder location), password (that I can choose myself) protects it AND does all of that without a cmd screen popping up.
I have very little knowledge of programming and managed to get some things working, but not all at the same time and in the same batch file.
Also to rar that file do I need Winrar to be installed on the computer or can I reffer to the rar.exe (copied from the Program Files Windows folder to a different location)?
AFAIK it's not possible to run a a bat file without a visible CMD window without using any additional tools. Here's a link to a post how to run a hidden console: https://superuser.com/questions/62525/run-a-batch-file-in-a-completely-hidden-way
It is possible to use just the rar.exe but I would use 7zip instead. The performance is way better, it's also portable and you have many options in the command line. So your project would contain the bat file itself, the vb script file and the 7z.exe (or rar.exe). If you want, you can even create a single .exe file out of these three by creating a SFX file: http://www.7zsfx.info/en/
Hope I could help you.

Fastest way to copy the full path of a file and insert it into a script

In many task I've to open a file with a script so I've to type the full path of the file. Usually I go to properties of the file and then I copy the path and then the name of the file. I wonder if there is a faster way to do that.
I would like to copy it in one click or drag the file in the IDE or something like that....
(I'm using Windows XP, Mac Mountain Lion and Ubuntu 12.04 sometimes).
In windows pressing shift and right-click allows you to select copy path.
In Mac right click and pressing alt allows copying file as path.
I've found Copy path for Windows that:
that will allow you to right click on a drive or file system object
and copy the path of the file to the clipbpoard. If the drive is a
mapped drive or the file system object exits on a mapped drive it will
resolve the full UNC path.
On Windows Shift+Right Click allows you to copy the path directly.
Alternatively many shell (like the shells of Spyder and Canopy,Ipython) support a drag and drop option that allow you to drag the file inside the shell and get the path of the file.

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

vb6 read and write a text file in win 7

I am trying to execute a .exe file (created by VB6) on Windows 7.
What the application will do is to simply create a text file, and then read the text for a text file.
All the functions are being tested successfully on Windows XP. When I execute the .exe file on Win 7, the functions act as usual but the file I created doesn't exist on the specific path (C:\test.txt). The most weird thing is that I can still read the content from the text file (through the .exe file) despite being unable to find the text file on file explorer.
Then I discovered that I have to choose [run as Administrator] to execute the .exe file, so that the file (test.txt) will be created on the C: drive. I am very curious how the .exe file can still read the text file even it is not existed, and how can I force the .exe file to run as Administrator?
Here is the coding to write and read a file.
Open "C:\" & "test.txt" For Output As #1
Print #1, cDrive.Text
Close #1
Open "C:\" & "test.txt" For Input As #1
Input #1, msg
Close #1
cDrive.Text = msg
Exit Sub
To answer the third remark:
Windows Vista and Windows 7 User Access Control (UAC) introduced a feature called the VirtualStore which is designed to add an extra layer of security protection for applications installed under the Program Files folder. If you search for the file on you hdd you might find a second instance of the file in /User/AppData/Local/VirtualStore
So that's why it is still able to read text.txt allthough is doesn't excist in the location you mentioned.
I suggest that you run the program as an administrator by using the feature in the shortcut (after compiling and installing).
If you asked about it when in debug mode - I believe that if the user that you use to debug is an admin - it's enough.
I have no answer for your question "I am very curious how the .exe file can still read the text file even it is not existed"
You should not specify open as #1 directly, use FreeFile() function instead Look here for a sample.
Good luck
Drive C is being protected by Win7, you can still write to it, but you really shouldn't.
If you want to run the app as admin:
right click on the EXE
select PROPERTIES
go into COMPATABILITY tab
check RUN THIS PROGRAM AS ADMINISTRATOR check box
click OK
Now every time you run the app, it will run as administrator

Resources