Mimic drag-and-drop from the Windows command prompt - windows

In Windows, you can initiate a Bluetooth transfer of a file by right clicking the file and choosing Send to > Bluetooth device. The Bluetooth File Transfer box appears, after which you select what device to send to. I have found that I can achieve the same effect by dragging-and-dropping the file that you want to send onto C:\Windows\system32\fsquirt.exe.
To figure out how Windows passes files to programs when you use Send to or drag-and-drop, I wrote the following Python script and placed a shortcut to it in C:\Users\<username>\AppData\Roaming\Microsoft\Windows\SendTo. The shortcut's Start In directory is the .py file's containing directory. (I am using Python 3.6.)
#!python3
import os, sys
print(os.getcwd())
print(sys.argv)
input("Press Enter to exit...")
When I drag-and-drop a file onto the shortcut or the script itself and when I right-click a file and choose Send to > the new shortcut, the same thing happens in all three cases: on the first line, Python prints out the containing directory of the .py file, and on the second line, Python prints out a repr of a list containing two elements: the absolute path to the .py file and the absolute path of the file that I chose.
I wrote the following batch file for testing:
cd C:\folder\of\py\file\
C:\folder\of\py\file\argv_dump.py "C:\path\to\a\file.txt"
When I run this batch file, either from the command prompt or by double-clicking it in Windows Explorer, I get the same output from before. on the first line, Python prints out the containing directory of the .py file, and on the second line, Python prints out a repr of a list containing two elements: the absolute path to the .py file and C:\path\to\a\file.txt.
Now, I am trying to initiate a Bluetooth transfer on Windows 10 from a script. I have written a three-line batch file for testing:
cd C:\Windows\system32\
C:\Windows\system32\fsquirt.exe "C:\path\to\a\file.txt"
pause
This does not appear to send "C:\path\to\a\file.txt" to fsquirt.exe. The Bluetooth File Transfer dialog box appears, but it still asks me to choose what file I want to send. Running these commands in a command prompt window yields the same result.
How does fsquirt.exe know the difference between when I drag-and-drop or use Send to and when I manually pass it an absolute file path from a batch file or the command prompt? How can I get fsquirt.exe to notice the file path that I am giving it?
I did look at this other question, which suggested checking the current working directory of the batch file. Wouldn't cding inside my batch file take care of that, though?

In the past, I have used the Bluetooth Command Line Tools via Bluetooth Installer. They allowed me to automate a Bluetooth workflow via the Windows command line.

Related

Running a selfwritten ruby program outside of an IDE

I was wondering if it was possible to run a selfwritten ruby program just like any other program by double-clicking an icon of some sort.
And if it's possible, how do I do it?
I wrote a little program for a friend but I don't want him to have to use the command line to run it, because that's rather inconvenient (unless there is a way to just double-click and the command line opens the program itself..).
Thanks for your help!
The simple answer that should work for all versions of Windows is to just create a simple batch launcher.
Create a .bat file. I usually just create a new .txt file via "right click > new > text document". Then rename it, highlight everything, including the extension, and rename it to something like run.bat. The .bat part is important. Once you rename it, the icon should change to gears. If you can't overwrite the extension, or Windows is still treating it as a text document, you'll need to either manually save it as a bat, or disable "hide file extensions" in the explorer settings so the extension can be changed.
Edit the bat file, and put into it something like:
#echo off
YOUR RUN COMMAND HERE THAT YOU WOULD NORMALLY TYPE MANUALLY
pause
Paste the command that you would normally run manually where the capital text is. The first line is so it doesn't repeat the commands back, and the pause is so if an error happens, the command prompt doesn't immediately close. This gives you a chance to read the error.
Save it and close it. Now, if you double click on the bat file, your program should run.
Multiple ways
if it's for occasional use and for one script only I would pack it
to a Windows executable with Ocra, then you can double click
the .exe itself or a link to it
same as above but use jRuby and create a .jar file, not for beginners though
the easiest: if you configure Windows to start/run .rb files with your ruby.exe you can double click the .rb files itself and they
will execute, they will have the red Ruby stone icon
if you run a .reg file to enable drap and drop on .rb files you can combine the previous technique to drop files on the script and
they will be the parameters to the script, see my answer here for the reg file
my favorite: copy the .rb to your windows "C:\Users\your_user\AppData\Roaming\Microsoft\Windows\SendTo\"
folder, then you can right click file(s) or folder(s) and select
sendto and select your script, the files or folder will again be the
parameters for your script
you can create a .bat or .cmd file that starts with the path to your ruby.exe and the script as parameter, use rubyw.exe if you
don't want output

Executing a command-line .exe file

I have a .exe file converted from a .jar.
It is a command based application, so I have to start it with a batch script. Here is the batch script:
#echo off
cd C:\desktop\plant-text-adventure-win
start planttextadventure
pause
When I double click on the batch script, this happens: Windows could not find 'planttextadventure'. Please confirm if you have input the correct name and retry.
I don't know what is happening, I have no idea about cmd as I use Mac, but I can confirm I have an executable called planttextadventure.exe in a folder called plant-text-adventure-win.
You should test your batch file by executing it within a shell.
Simply enter within the start menu the command cmd to open up a shell. Within this black box you could now simply enter the commands from your batch script and lookout for some error message.
If you look at your script I would guess that the cd command (to change the current directory) is not correct. Maybe you should replace it with
cd %USERPROFILE%\Desktop\plant-text-adventure-win
because the desktop folder is on a default installation not directly under the root drive but within the user profile available.
Another solution to get this thing to work, is by opening the windows explorer, going to the .exe file you wish to execute and drag & drop the .exe file with a right mouse click onto the desktop.
Then a context menu appears and you select the option Create shortcut here.

WinSCP script file works in Windows 10 but not in Windows 7

I want to automate really simple ftp transfers with WinSCP (Example script file shown below. The real file would handle many files, but all simple stuff.)
open ftp://username:password#ftp.site.com/
option confirm off
cd remotedirectory
get file.csv
close
exit
A batch file containing:
winscp.com /script="staging get.txt"
opens a command prompt window and executes correctly in Windows 10, but in Windows 7 the command window opens and then immediately closes, and no files are transferred. WinSCP is in the path in both environments. I assume that a parameter or command is missing from one or the other file, but I don't know what it would be.
I was making a couple of small syntax errors. I couldn't see them because the command prompt window closed almost immediately, but the log file showed me what was happening and it was easy to fix. The lesson is - always create a log file.

Is there a way to run a command line "inside" a symlink?

I have a symlink named example.avi that points to a real example.avi video file. When a program tries opens the symlink, it really opens the video file. But now I would like execute a command line whenever a program tries to open the symlink file.
Is that possible?
ps: windows
No, there is no built-in way of creating a symlink or other file system object that causes a command to be executed when it is opened by an application.
It should in principle be possible to do this with a file system filter driver. But that's very complicated. I believe there are some third-party tools to simplify this sort of task, but I don't have any experience with them.
While I am clearly ignorant on the subject of symlinks in Windows (see my comments on your question). I just played with it and proved that you could basically do this by symlinking to a wrapper for your avi. I.e. symlink to an exe or a batch file, etc. which does what you want and then opens the avi. Here's a test I ran with txt files and notepad:
Create a file called test.txt with some text. Create a file next to it called test.bat. Here's the batch:
notepad test.txt
When you run the batch, it just opens the txt in notepad.
Then I added a symlink:
mklink test2.txt test.bat
Now, when I type test2.txt in the command prompt, or double click on it, it runs the batch and opens the test.txt file. Obviously, you can use the same basic logic. It doesn't, however, fire the batch off when I open the symlink in Notepad++. It just opens to batch for editing instead.
Of course, maybe you don't want a second file, in which case you need to literally embed your avi in some wrapper. I guess we ned to know more about what you want to do. It sounds like an attempt at malware hidden in a video to me...

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