How to call a function when opening program from file? - visual-studio-2010

I made a project in visual studio 2010 (maybe a bit outdated but I like it this way).
With that project I made a separate project that handles the setup file for the installation. In this setup project I assigned a file type to my project so that the program can be started by double-clicking the file.
Now all of this works, the file gets a icon similar to the program and when I double-click it, the program opens. The only problem is that it doesn't open the file that was clicked.
I think I need to change something in the 'command' that is seen in the file type properties. As it is, I just have it set to "Primary output form Project 1". How can I make it so that it doesn't just open the program, but also calls a function that loads the data inside the file?
I'm sorry if this question has been asked before. I searched for it but I couldn't find a similar question. I'm also pretty new to the whole programming thing.
Thank you in advance!

You want to pass the filename to your program as a command line argument.
Add %1 to the end of the command you have associated with the file extension.
For example: "C:\path\to\MyProgram" "%1"

Related

Win CLI open file with "How to open"?

I need to open the file using Windows 10 cmd. But when the file opens, I need Windows to show me a modal window "How do you want to open this file?". The system should do this even if it already has a program selected by default to open a certain type of file. Is it possible to do this?
To clarify my problem:
I need the console to run for example ".py" not through the standard Python.File="C:\Windows\py.exe " "%L" %*, and for example via VS Code. You might tell me about the VS Code CLI. But how to handle an event where the user will not have VS Code, but for example Pycharm, and the user will want to open it through it? That is why the question was posed in such a way that the user could choose through what to open the file already through the built-in modal window in Windows. In any case, I will be glad of any suggestion to solve my problem.
I tried to find something similar, but apart from the standard start something.som I didn't find it. And this is not a solution to the problem, because start starts the file in the program that is specified by default in the system. This program may not even be the one that the user ever chose later. I came across a similar question in Stackoverflow, where a person wanted to see which program was responsible for opening a file with a certain extension, where assoc and ftype were used, but they did not give the desired result.

How to implement "open with" in a notepad application

Getting straight to the point, I am basically creating a clone of notepad in java and I want to implement this functionality:
Assume I have a file like this with the .txt exention
I procede to right click and select the open with option, where notepad and vscode are also present
What I want is for my application to be here, and I know that I have to edit the registry and add the main executable of my app for every text file associations and I'm pretty confident I can do it with by running the reg command in batch (correct me if I'm wrong).
The part where my personal research was not good enough is actually how to physically implement the open with behavior in my java code, meaning I don't have any "entry points". If only I had the path of the selected file I could call my open() function with that path and the job would be done. However, I don't understand what's going on in the background.
Note: I am still learning batch and windows related topics so I apologize if this is a stupid question

The visual studio F# interactive window keeps not opening in current directory

So I want to work a little bit in the interactive window in visual studio, to take a look at some F#.
Now View>other windows>F# interactive
In order to load my file I then type
>#load "Distance.fs";;
It is important to mention that Distance.fs is the current file that I am standing on.
however now, I get this error:
It looks like it keeps looking in the wrong directory, and it keeps doing this across different files and projects. Why does this happen? Is there any way I can configure VS to always open the interactive windows on the currently open directory
FSI defaults its current directory to whatever %TEMP% is and just needs a little help. Create a scratch script (as #TheQuickBrownFox suggested), and put your #load statement in there. Above that, add
open System
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
Highlight those two lines and press Alt-Enter to tell FSI to change to the script's current directory, then your #load statement should work (if needed, adjust your path, for example if you create a separate scripts folder, then maybe you now need #load "../Distance.fs", etc.

How can I open a Microsoft Access Database file with an .exe?

I have been working on creating a pretty advanced GUI enabled database in Microsoft Access and am now in the implementation phase of my project.
My dream is to make an .exe file that will point to the actual .accdb database file (which will be hidden) as I cannot change the icon of the .accdb but will be able to modify the .exe's icon thus giving my implementation a more professional feel.
I'd prefer not to just create a shortcut to the .accdb and change that icon.
Through some quick digging, my plan was to create a .bat file that opens the .accdb and then use some online ".bat to .exe" converter to then add an icon to the .exe.
I can't figure out how to create a .bat file that opens my .accdb. I've tried a variety of different things like:
start "" C:\Program Files (x86)\CompassTrack "Science Department.accdb"
and other things that dont work.
It occurred to me that a .bat to .exe approach may not be the best way to do this. I don't particularily like the brief command prompt window appearance and would be open to any suggestions as to how to get a nice looking .exe file to open my .accdb.
If the best way really is a .bat file, I'd appreciate some help with the .bat file. The path to the file is C:\Program Files (x86)\CompassTrack\Science Department.accdb but for some reason every time, command prompt would return "Cannot find C:\Program "
Thanks in advance!
to change icon of an exe file using batch, look here
and to start your file use:
cd "C:\Program Files (x86)\CompassTrack"
start "" "Science Departement.accdb"
I believe you can just change the icon of your Access database. Go to Current Database (in recent versions under Office Button > Access Options) and the option is in there.
Here's a really simple C# program that you can compile into an exe very easily to if you have .NET 3.5 installed. it uses a utility called the command line compiler. You'll have to change the file path obviously.
using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
public class App
{
public static void Main(string[] args)
{
Process myProcess = new Process();
myProcess.StartInfo.FileName = #"c:/your_file_path_goes_here/YourDB.accdb";
myProcess.Start();
}
}
You'll write the above to a text file with the extension .cs. Then create a batch file (a text file with the extension .bat) with this code.
#echo OFF
echo Compiling A File . . .
C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe /win32icon:_.ico /target:winexe /recurse:*.cs
echo.
#pause
Put these in the same dir as whatever icon you want to use, but make sure the icon is an iso file named _, as seen in the batch program. When you run the bat file, it will create the exe with the icon of your choice and it will simply launch the access database.
The feature and ability is part of the Access development system. Attempting to modify some .exe file etc. will not work.
I do suggest that you set the icon under file->options current database. It not clear why this is not working (perhaps start a new question to resolve that issue).
Keep in mind that if you deploy or change the resulting location, then you have to change the above “options” setting (manually, or by code – this much explain why your icon is not displaying – the path name cannot be relative – must be absolute.
ALSO select the box that says to use the icon for all forms and reports (this will give your application a MUCH more polished look. Since the .exe that actually runs your file is msacces.exe, then you can’t really change the application icon any other way. You see icons for the application AND ALSO forms like this "when" you set the application icon as per above:
So you WILL want to set the application icon. You then create a shortcut on your desktop. And again set the icon for that windows shortcut (it will nicely show up in the task bar with that icon).
The actual shortcut will look much like this:
"C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE"
"c:\RidesDev\SkiRides\ RidesXP.accde" /runtime
The above shortcut will be on a single line (space between the two lines). The above is for Access 2010, so for 2013, then the folder is office15, and for 2016, it is office16 in above.
Also NOTE very important is the /runtime. This will ensure that the access icon NEVER shows during start-up.
Also, during start-up you will often see the MS Access splash logo during start-up. E.g. this:
You can replace this splash screen by placing a .bmp (picture) file in the SAME folder as the accDE with the same name.
So in above, if I place a RidesXMP.bmp picture file, then during start-up in place of the access splash screen, you see this:
Since you likely want the forms + reports icon to be custom, then the above makes the most sense. Your approach would ONLY give you a desktop icon, not one for the task bar, forms etc.
The above will result in hiding the access splash logo during start-up, and also apply an icon to all forms etc. I don’t suggest some approach that attempts to modify some .exe or some such – that’s likely to cause issues on customers computers. And using some .exe will not give you the icon for forms and repots.

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

Resources