Getting the short cut name - c#

I have one program, the exe is called main.exe. when main.exe is excuted. I allowed the user to be able to create a shortcut off main.exe. But when the user can create any name for the shortcut. so if the user is selecting the shortcut. I need the name of this short cut. not the program its pointing to

You can't getting the shortcut name from running exe. Application does not receive information about shortcut used to launch it.
You can use command line arguments and/or current working directory to configure your application (both can be set via properties of a shortcut).

Related

Open file with associated application and with specific user in C#

I need to open files of different types with their associated application. It works fine like this:
System.Diagnostics.Process.Start(#"C:\foo.jpg");
But when I need to open it with a specific user, I need to supply an executable, I can't open a document/image etc. ("The specified executable is not a valid application for this OS platform") Is there a smart workaround or would I need to get the associated application's data from registry and run the application with the document/image as argument? (So the question is not about how to run Process.Start() with arguments!)

Set Process 'image name' and 'description' wtih C#

I want to go into as much detail as possible so this question is easily understood and answer-able
Essentially I need a way set up the process name and process description with C# on the applications startup.
Here is an example of what I would like changing;
Note: I want to set my OWN C# applications image and description with CODE.
I want to be able to change the following things in my application on startup.
Image Name in the Processes list, as well as the Description in the Processes list.
So far in my C# application i can set the process name with the properties but id rather be able to set it with some sort of code snippet (as well as the description).
I hope this has been a information question and you good clever people at stackoverflow can help.
You can't change the image name. It's the name of your executable file.
The process description, however, can be changed on your C# project assembly info:
Right click on your C# project in Visual Studio > Properties > Application > Assembly information > Title.
You can't change the description at runtime from code: the OS loads the description at startup from the Version Information file resource.
The Image Name property is the name of the executable itself (ie Foobar.exe), the Description property is the Title of the application in the Assembly Information dialogue box, as shown below:
At this point, when you run your program, you will see two entries into the task manager as shown below:
One will say the name you specified in the Title box, the other will say vshost32.exe as the description. To fix this, untick the option called Enable the Visual Studio hosting process in the project properties page.
As close as I can come to an answer is to pragmatically create a new executable with the desired name and description launch that executable then allow your launch process to die.
Try using your application as a 'host' for another app.
As soon as the application is launched, it downloads a file from a dropbox link (a direct download link) and saves it locally, (In the temp folder probably).
Then our application launches that application and then kills itself with maybe an error.
now the process running on that one would be gone, and we have a new process with our set title and description. Easy!

How would I find an exe's path just by knowing its name?

How Would I find another exe's path by knowing its name in .net?
Would I add name to the OS environment variable?
Would the other application have to 'register' itself somewhere else?
I need App A to start-up App B and call some WCF services on it.
Thanks!
To answer your question: you cannot know the path simply by knowing the name. An exe can reside anywhere on the file system. There can be multiple instances of it that don't know about each other. Multiple exe files that are completely different can have the same name.
You could take one of several approaches to get round this, depending on the exe you are targetting:
get the user to browse for the exe using a normal file browse dialog
search the file system
see what traces the target exe leaves on the system (filesystem, registry, environmental variables, etc) and use those traces to locate the exe
For either of these options you save the result so you don't have to execute it again when your app is run the next time.
Searching the filesystem could take some time, you are not guaranteed to find the exe (depending upon the user level your app is running as) and you may get false positives, especially if the app is called something dumb like setup.exe.
Getting the user to locate the exe the first time you run is possibly the most reliable way of locating it, but then you have to decide what to do if your app runs but the target exe is no longer at the specified location, or the user has chosen the wrong exe.
If you have some control over App B (i.e. it is your product), then you could consider adding some info to a known spot in the registry when App B gets installed, so that App A can locate it easily. You still need to have a plan B though in case the info is missing.
Reference a path to a shortcut of the exe in the config setting, that way if the exe ever moves around the shortcut will still be up-to-date. Try it, make a shortcut to a exe, then cut and paste the exe somewhere else, then double click the shortcut and you'll see it points to the exe's new location thus will not require changes to app A if the location app B changes.
Really, just make the App B a windows service and start it up when needed.
UPDATE:
Another suggestion would be to create a hard link to the AppB's EXE:
mklink /H AppB-link.exe path_to_actual_exe
Or a symbolic link to whole directory where App B resides:
mklink /D virtual_directory path_to_actual_directory

start .net application from start menu search

bla.exe (application alias) points to a .net application called wpfapp1.exe.
When i add a key&value to eg. this key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\bla.exe
and then start application using Run -> bla.exe it starts
however when i start application using windows search i get an "windows cannot find wpfapp1.exe. make sure you typed the name correctly, and then try again."
I have successfully identified problem: this error only occurs to .net applications while native one start normally (eg. firefox.exe).
So is there any .net config that i've missed during development?
From MSDN:
The App Paths key is not used when
computing the DLL search path.
Maybe you're missing some dependent DLL...
I don't really understand your "points to" or if Windows search is specific to using the explorer search or using the start menu search.
I've had a similar problem with another application that the search could not find at all, neither in Explorer or Start menu (since it did not have an indexed folder to locate it) and solved it with a simple shortcut.
If you can create a shortcut of your application in your start menu or some other indexed folder, like a %PATH% folder, Windows search should be able to pick it up and then you can name your shortcut to whatever you want, for instance bla.exe.

How to create a shortcut using wix that could change depending on a user's system

I have created a Wix installer that places 3 shortcuts onto the desktop. One of these shortcuts references the user's DVD Drive. Is there a way to dynamically set the target of this shortcut based on that drive letter? Would a custom action be the way to go? If so how would I change the target of a shortcut using that custom action. I have been writing my custom actions in C# and would hope to continue doing so.
Thanks for any help.
You can set the target of a shortcut with the value of a property. For example, the following will take the value of the MYSTUFF property as the target:
<Shortcut Id="MyStuffShortcut" Name='My Stuff' Target="[MYSTUFF]" />
There is no standard windows installer property for "the DVD drive". I'm not sure what that would even mean if there were multiple DVD drives. You can use ROOTDRIVE to refer to the local drive with the most free space. You can use SourceDir to refer to the root of the drive where the installer is being executed from.

Categories