open a text file via windows double click with ruby - ruby

I'm fairly new to Ruby, so please excuse me if my question is too basic...
I wrote a program that searches a text file for certain values.
The way it works is that when I run the program from command line it asks for the file to search through. So I drag the file over to the command window and press Enter. The program takes over and does what it's supposed to... I also created an exe file using Ocra just so I don't have to run it from command line.
It works great, but I want to take it a step further. How can I modify my program to be able to double click the text file in Windows and have my program automatically open and do it's search?

Related

Copy all text from Command Window programatically

This article shows the well-known way to manually copy text from a Command window.
I'm looking for a way to do this programmatically. How could the cmd script that is running select all the text in its output window, and write it to a file?
I've found tools to do a screen capture into a file, but that may miss output if it has scrolled out of view? I'm looking for a way to capture an unattended cmd script's output (without modifying the whole script to redirect every line to a file).
Possibly this could be done with the windows API by finding the cmd window, sending CTRL-A and CTRL-C keycodes, and then write the clipboard text to a file. A possible approach for clip2txt is presented in this post.
Is there any other approach that should be considered?

How to Launch a Metro App from Microsoft Access VBA on Windows 10 Computer

I have a situation in which I wanted to utilize the camera app in Windows 10 from my Microsoft Access program. Normally I could just send a command to execute the program's executable, but with the metro app there is no straightforward executable.
The basic code I use is this:
Shell """" & PthToExe & """", vbNormalFocus
PthToExe is the path name for the executable.
I looked around a decent bit, but was unable to find any simple solutions and ended up coming up with my own. My solution is to make a shortcut link to the camera application and then to launch the link.
In order to make a shortcut link in Windows 10, you can click on the start button, go to "All Apps", find the app you want (in my case "Camera"), and then click and drag it to the desktop.
Now that you have a shortcut, you can launch the shortcut from a command line. (So my shortcut doesn't clutter up my desktop, I dragged it off my desktop and into a folder on the "C" drive.)
Type the path into a command prompt like this and hit enter to test launching your app: C:\GJ\Camera.lnk
So that solves the problem if you wanted to launch from a command line. For some reason, though, Access would not accept that command. The way I got around it was I put the command in a batch file (Edit: Alternatively, see HansUp's comment). To do that, you just need to open notepad, type in the same thing you typed in the command prompt, save the note pad document, and then rename the document to have a .bat extension.
You can then execute the .bat file from Microsoft Access as follows:
Shell "C:\GJ\OpenCamera.bat", vbMinimizedNoFocus
Note that normally, I use vbNormalFocus when running the shell command, but in this case, it is desirable not to see the little command prompt open before the actual program opens.

autofilling a login box for an .exe program with shortcuts/scripts

I'm wondering if its possible to write a script or add a shortcut command or something to an .exe file that I open quite regularly and have to log on each time.
The program is called iMonitor which when you click on the .exe file opens up to a log in box with 3 fields, user name, password, and server. Is there some standard format or way anyone knows of to auto-fill those fields or would it be a program specific thing they would have to write into the code itself to allow?
Thanks in advance
Chuck

VB script to open .exe file and perform 4 activities

I have a tool based on .net. I need a vb script which would open this tool (.exe file) and then select 3 radio buttons, click on a button to browse a xml file stored in same folder and then click on invoke button. Is this possible? I am a complete fresher and just have this idea in mind for an automation. This is required as I have to perform the same steps daily.
I could find this code:
CreateObject("WScript.Shell").Run("""C:\Users\abc\Desktop\folder\Tool.exe""")
Which is doing my task to open the .exe file perfectly. Can someone help/guide me in achieving the further steps?
You might be better off making your tool work via the command line and having it accept arguments.
That way, you could use a .bat file to call your 'tool' passing in the arguments it needs and away you go.
These should get you started on your quest.
Creating a HelloWorld Console Application Using VisualBasic.NET
How to Parse Command Line Parameters?
What is a bat file

My Ruby files don't run correctly

When i click on a .rb file to run it a CMD window pops up for a brief second and then closes again. This is probably a really nooby question thats easily fixed but i've looked everywhere for help. But like i said it pops up for a brief second and i THINK while its up its executing the code but when the codes done it closes so i don't know if i'm making mistakes in code or other important things like that.
Run the program through the command prompt (CMD), that way you can see the result, otherwise the window closes when the program exits.
Alternatively, you can prevent the program from exiting by putting some sort of blocking instruction at the end of the script, such that the program waits for user input before exiting.
Press Windows_Key+R and then type CMD. Browse to the location of the file and then type ruby your_ruby_file.rb. The program is running, but Windows automatically closes the window upon completion of the command.
To get Windows to run your *.rb files through Ruby when you click on them in the UI, you have to associate the .rb extension with the ruby.exe executable. Such an association is called a "Windows File Association." Here's a Microsoft Knowledge Base article that'll tell you how to create such a thing.
http://support.microsoft.com/kb/307859

Resources