I have made a very simple WPF application that is intended to have a couple of options:
Option 1 is to launch a PDF file
Option 2 is to launch a couple of exe files needed to run my software.
The problem is that on the machine I have developed this on it does open both .exe files just fine, but the strange thig is that when I try this on my HP Laptop it only wants to open the unity3d exe file and not the Voice Server exe file.
Does anybody have any idea why this is the case, it's driving me nuts trying to figure it out. here is how I have by button call coded in C#
public static void LaunchKOS()
{
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var desktopPathkos = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// Launch Voice Server
var combinedPath = Path.Combine(desktopPath, "Knight O S Beta01_Data/voice-recognition-server-pc/VoiceServer/bin/Release/KittVoiceServer");
Process.Start(combinedPath);
// Launch Knight O.S. Unity Settings Window
var combinedPathkos = Path.Combine(desktopPathkos, "Knight O S Beta01");
Process.Start(combinedPathkos);
// Close This Window
Environment.Exit(0);
}
EDIT:
On the outside chance that for some reason it did not like doing both .exe files from one button I have even tried just launching the Voiceserver.exe from the one button call and I still get the same result where it will launch it on the machine I have developed the app on but not on any other machine despite the fact that the file folders are exactly the same??
There has to be some logical reason for why this is not working??
Anyone?!?
EDIT: More than one way to skin a cat
Well, it may not be the most elegant way to have solved the problem but I've managed to come up with a work-around.
What I did was create a shortcut of the VoiceServer.exe and then in my button code execute the shortcut and now it will open both .exe files.
It's beyond stupid that I should even have to do that, but that's what I ended up doing. :/
The folder separator for local files paths is "\" rather than "/".
Path.Combine() is defined with a params parameter, so to avoid issues with \ being treated as an escape character, it's cleaner to just pass each folder name as a separate string.
var combinedPath = Path.Combine(desktopPath, "Knight O S Beta01_Data", "voice-recognition-server-pc", "VoiceServer", "bin", "Release", "KittVoiceServer");
Related
This seem a very odd question but I'd like to know if this is possible. I'm dealing with a Japanese boss that requested a custom launching program, which I accomplished using Windows Forms. From that launcher you can launch 3 installed casino programs.
The bad news is, there is a certain casino application which path is not installed in Program Files folder. It is installed on user's Appdata folder instead.
What I did is, when you click the launch button of that casino
private void AlienLaunchBtn_Click(object sender, EventArgs e)
{
Process p = Process.Start(#"%HOMEPATH%\AppData\Local\Programs\Alien Casino\1.2.135\Alien Casino.exe");
}
But I get an unhandled exception error
I discussed it that if it will be used on various computers, the file path differs.
So he came up with a crazy idea to put a text file having the paths written inside it and when you fire up the installation setup of the custom Launcher, it should get the paths contained on that text file.
Is this even possible? If not what is the best solution to this situation?
Have you tried :
Process p = Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)+#"\AppData\Local\Programs\Alien Casino\1.2.135\Alien Casino.exe");
BTW if you're not using fw4+ , you can use this instead :
System.Environment.GetEnvironmentVariable("USERPROFILE")
After your edit : see the exception. it says it can't find the file.
I would like to open programmaticaly an application.
First i used System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Program1.exe") works fine, but the application always needs to be on the same path (not always true because different computer)
And a simple way to find it (with mouse & click, not programmaticaly though) is to use the windows file explorer, i enter the title of my application and i find it instantly.
I would like to code that.
I thought i could use the keyboard shortcut "Home + F" and simulate the word with SendKeys.Send("blabla") but the "Home key" doesn't seem to exist with c# (at least not here https://msdn.microsoft.com/fr-fr/library/ms127847(v=vs.110).aspx)
It's a little program for children i can't expect them to find manually the path (so forget the OpenFileDialog..)
Maybe thats a very bad idea and there are another solution to find a program without knowing his path, i don't know have you got better idea?!
You're trying to solve the problem the wrong way. What you're trying to "program" is the setting oft the working directory when the program is run using Explorer. The right way to do that is to use Process.Start by passing it all of the necessary info to start the process:
var startInfo = new ProcessStartInfo("Program1.exe");
startInfo.WorkingDirectory = #"C:\Program Files (x86)\";
Process proc = Process.Start(startInfo);
If I try to open Notepad from a .NET console application it works fine.
I'm doing it as follows:
var p = new Process
{
StartInfo =
{
FileName = "c:\windows\system32\notepad.exe";
}
};
p.Start();
When I try to open the application I actually want to open, nothing happens. If I open that application by hand I see a Java process being created, which means it's a Java application packaged as an exe file.
Any ideas on how to open Java exe apps through .NET?
Thanks in advance
There shouldn't be much of a difference between a regular EXE and an "exified" Java application. Have you tried adjusting the working directory? Maybe there's some unzipping going on.
Lets say you had an application named "HelloWorld". Then from a command prompt (and from your code) you would launch it with:
java HelloWorld
Now this would assume that java is in your path. Which is a bad assumption. So you would be better off either having logic to populate the path to java, or to hardcode it.
I don't ever recommend hardcoding a path if you plan to pass this software around. It's never a sure thing...
I need to remove Application launch and "Pin this application to taskbar" from the taskbar context menu for an application. Reason is that the application cannot start standalone, it must be fed with information from another application.
Does anyone know how?
According to this post, you can use the Windows API Code Pack but the required classes are internal. The OP said that they copied 50k lines of code to get it working. I'm not sure if it's improved since that post but here's a workaround I just thought of. Since you can only pin EXE files (and shortcuts as per comment) to the taskbar, you could rename your application to a non-exe extension (most non-exe extensions cannot be pinned).
When you want to call it from your other app, rename it to .exe, launch it, then rename it back again. For example:
Process p = new Process();
//fake extension so it can't be drag/dropped to taskbar
string fakeExtensionName = #"C:\MyFile\myProgram.test";
//what it's actually called
string exeExtensionName = #"C:\MyFile\myProgram.exe";
//rename the fake one to the real one
File.Move(fakeExtensionName, exeExtensionName);
p.StartInfo.FileName = exeExtensionName;
//launch the real one
p.Start();
//rename it back to the fake extension
File.Move(exeExtensionName, fakeExtensionName);
Anyone can rename it to an exe if they really wanted to, so your program should assume that a user can launch it directly and handle that scenario, but any file can be pinned to the taskbar by renaming it to an exe so there's no protection around that.
Ok, i found a ugly but easy solution here https://stackoverflow.com/a/3872503/1323570
apparantly the registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileAssociation\AddRemoveNames contains some words that may not exist in an executable if pinning should be possible.
you can also read more here: http://www.west-wind.com/weblog/posts/2009/Oct/08/Application-that-wont-Pin-to-Taskbar-in-Windows-7
Edit:
Found the way to do it properly:
Add the key:
HKEY_CLASSES_ROOT\Applications\Example.exe\NoStartPage
ref: http://msdn.microsoft.com/en-us/library/windows/desktop/hh127439(v=vs.85).aspx
I am using the following code to open flash:
private Process flash = new Process();
flash.StartInfo.FileName = ("Flash.exe");
flash.Start();
The target machine has many version of flash like flash cs5,4,3. I want to open the newest version or let the user choose, how can I possibly do that?
Typically speaking, all other flash installations would be in different program folders, so you would just need to make sure you're running Flash.exe from the right folder. For instance, my current installation lies here: C:\Program Files (x86)\Adobe\Adobe Flash CS5\Flash.exe, but an alternate one could very well be in C:\Program Files (x86)\Adobe\Adobe Flash CS4\Flash.exe`.
An important thing to notice is that you can't assume the user installed flash CS* in its default directory! You should always query the Windows registry to find the list of installed products.
Also, another notice would be that you don't need parentheses around string literals. So you can just write:
string foo = "Hello!";
instead of
string foo = ("Hello!");
Edit 1:
Hey, I found a similar problem being treated in a forum thread here! I downloaded the code sample and ran it through a vb.net -> C# converter (like this one) and got it to work after a few minor syntax tweaks. Now it's able to output a list of the installed programs with their appropriate version numbers.
There will be a bunch of methods that get programs form e.g. certain users. All of these will then be placed in a common list, returned to the user. Now, this seems perfect, but there is just one flaw - no path is available... so far!
You can just query the UninstallString, and get a path to the uninstaller (which is IIRC in the same folder as Flash.exe). For instance, in GetUninstallKeyPrograms, after the
try
{
IsSystemComponent = Convert.ToInt32(CurrentSubKey.GetValue("SystemComponent", 0));
}
snippet, you can try to get the UninstallString value in order to obtain the path. Hope it helps!