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
Can a Windows batch file determine its invoked filename when invoked through a shortcut?
For example, I create real.bat, and create its shortcut named phony.bat (.lnk?)
And invoke phony by double-click on it.
Can this batch file detect the name phony.bat instead of real.bat?
Of course I can just copy it to another name, but when I edit one of them, I have to manually sync the content to all files.
The question is related to Can a Windows batch file determine its own file name?, but different.
As in your you mentioned that you've created the shortcut I assume you can create the with any properties you want.
So right click on your lnk file and change the the target line to:
C:\Windows\System32\cmd.exe /c "set "lnk_call=1"&"C:\PATH\TO\your.bat" "
This will change the icon of the link so to set back to batch file cog click on change icon and find the bat file icon in :
%SystemRoot%\System32\SHELL32.dll
Finally in your bat put this line:
if defined lnk_call echo triggered from lnk file
the lnk_call now can be used to determine if your file is called from double clicking on a .lnk file. I don't think it is possible to detect this from a shortcut that anyone else created.
Oh yeah, I found hardlink useful in this case:
mklink /h <link-name> <source-file>
I can create many hardlinks with different name, and they all points to the same file, so I can freely edit any one of them without manually sync their content.
I've been working on this for days but still cannot figure out how to do this: creating a custom folder.
Here's some information that I used:
Source 1
Source 2
Source 3
The major difference between the goal of these links and me is the fact that I am not trying to pin my folder to somewhere else. The only thing that I want to do is to create a redirect to a folder's subdirectory.
Here's my simple diagram:
So if I open Main Directory(the yellow part), desktop.ini and the system attribute of Main Directory will call up my custom CLSID (Explanation) and redirect my access to Redirect Folder automatically. My custom CLSID will also add an option in the context menu(the list that appears when right-clicked) to execute a .cmd file. The .cmd file will enable the user to access Hidden Folder when the correct password is typed.
So here're my registry keys:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}] #=""
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\DefaultIcon]
#=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,73,00,68,00,\
65,00,6c,00,6c,00,33,00,32,00,2e,00,64,00,6c,00,6c,00,2c,00,2d,00,34,00,00,\
00
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\InProcServer32]
#="shell32.dll" "ThreadingModel"="ApartMent"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Instance]
"CLSID"="{0E5AAE11-A475-4c5b-AB00-C66DE400274E}"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Instance\InitPropertyBag]
"TargetFolderPath"="C:\Custom\Location\to\the\Main\Directory"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Shell]
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Shell\Open
Vault]
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\Shell\Open
Vault\Command] #="cmd /c Open.cmd"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\ShellFolder]
"Attributes"=dword:00000000
It looked like this would work just as intended, but it had a flaw: my Main Directory did not actually redirect me to Redirect Folder. Here's my evidence:
When I right-clicked, every creating option was gone (Create new folder, text file, etc.)
When I create a file using a 3rd party software that was in the context menu, it did not create the file in Redirect folder but instead in Main Directory
Most importantly, when I Shift + right clicked and opened a command prompt, it showed my current directory as Main Directory instead of Redirect Folder
So what I'm trying to ask is this: how do I completely redirect my Main Directory access to Redirect Folder and keep my Hidden Folder opening option in the context menu?
I do not know how this works, but I found a way around.
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\shellex]
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\shellex{000214EE-0000-0000-C000-000000000046}]
#="{0AFACED1-E828-11D1-9187-B532F1E9575D}"
[HKEY_CLASSES_ROOT\CLSID{a79ff1d1-166e-4f20-967f-5aa2a0c19cd0}\shellex{000214F9-0000-0000-C000-000000000046}]
#="{0AFACED1-E828-11D1-9187-B532F1E9575D}"
The first step is to add above lines to the Registry.
After adding these, I created a shortcut file(.lnk) of a random folder(excluding self and some other special folders).
When I moved the .lnk file to the Main folder, I could access to create new option from my context menu.
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...
There can be "This file came from another computer and might be blocked" message in file properties.
Is there a way to block back file in windows 7?
I need this for program testing.
You have to recreate the alternate data stream for the file. The easiest way to do this is by using Notepad. Run cmd.exe and navigate to the directory that contains the file. I'll use test.txt as an example, type this command:
Notepad "test.txt:Zone.Identifier"
Double quotes required. Notepad prompts you to create a new file, click Yes. Paste or write this:
[ZoneTransfer]
ZoneId=3
Press Ctrl+S to save.