C#: Open a Fullscreen process - c#

I'm creating a program that opens to applications (.exe). I can open one of them, that's a windowed application (samp.exe), but I can't open the other one (gta_sa.exe), that's a fullscreen application.
I don't know if using Process.Start() doesn't allow me to open it, but I guess it's not because of it.
Here's my code:
private void btnSA_Click(object sender, EventArgs e)
{
Process.Start(Properties.Settings.Default.SAPath);
}
The Properties.Settings.Default.SAPath is the file path (C:\Program Files (x86)\Steam\steamapps\common\Grand Theft Auto San Andreas\gta_sa.exe)

I found why it wasn't working.
For some reason my computer didn't show up the game because of some configs. After reversing them I managed to open the game normally.
Thank you all for your answers!

Related

Opening application with file C# Winforms

So I'm making a Notepad replica in my spare time just for fun, the core of the project is all done. However, I can't open my application from a file. For example, if you had a .txt file, you double click it and it would open the app (by default its Notepad).
I already know how to set the default application, but the code does not support opening the files yet, it can only open files from the menu inside the program.
How would I go about making it so that my application can be opened by files?
in you void Main(string[] args) method, the args will contain the path to the file that was opened with your application. You can also get them anywhere in the application by calling string[] Environment.GetCommandLineArgs(). Print the argument in a message box to see what arguments have been passed.
Here's some code you might want to use for that:
//In a form
public void MyButton_Clicked(object sender, EventArgs e)
{
string[] args = Environment.GetCommandLineArgs();
MessageBox.Show(string.Join(Environment.NewLine, args));
}
I like your question. Once you provide support for opening type files, and you find that your application is still not working, perhaps this might be useful: you can check under registry section HKEY_CLASSES_ROOT for the extension and action details. It talks about default applications, but it gets into more details.
Here's the page:
Finding the default application for opening a particular file type on Windows

Launching program on system startup not working

EDIT: I'm new to c#, I'm completely lost on this.
I have a program that is supposed to start every time windows starts up. I have it set it up so when you click a check box, it writes / deletes a regedit, code:
private void SetStartUp()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (LaunchCheckBox.Checked)
{
rk.SetValue("SystemStartupProgram", (defaultDirectory + "\\SystemStartupProgram.exe"));
}
else
{
rk.DeleteValue("SystemStartupProgram", false);
}
}
Where "defaultDirectory" is a custom set path. It's set up to be the directory in which the program itself is in, for example "c:\MyProgram\bin\Debug". The .exe file for this program is located in there.
This code works as far as I can tell, since if I go to task manager's start up section, it shows my program, it's location, and it's state, which is enabled. However, the program doesn't run on system start up.
I have a hunch it might be something to do with a .txt file my application uses. The file is located in the same directory. If I remove the .txt file and run my program manually, it tries to launch it but nothing happens. Maybe the windows start up doesn't find the .txt file, and thus can't start it? Is there any way around that?
EDIT 2: The program is a Windows Forms application. When run, it opens up a form. However, it doesn't show up when windows starts.
EDIT 3: Problem fixed, see answer below for details
After a long bug hunt, I found what the reason was. It was indeed what I suspected, when the program starts it tries to look for the .txt file located in the same directory as my .exe. Turns out when you start a program upon system startup, the directory it looks from is something like "Microsoft\windows32", which is not where my file is located at.
I set my program's directory to it's own folder (my case: bin\debug) whenever the program starts, and only then try to read the file.
The bug being fixed, I'm still going to make a windows service application version of it, since that seems to be the correct way to do things from what I managed to google. Thanks to everyone who helped :)

How to open a text document from Explorer?

I'm making a program which saves text documents and also opens them in the program in a textbox, the program works fine and I've managed to make it so I can save the files, and open them when giving the file name
However, I want to know if there's a way to open up explorer, then click the file and have it open in the program, I know Process.Start("explorer.exe"); is used to open explorer, but the files i open from there open in their default programs
If you know how to make it so text documents open in my program please let me know.
I think you need an OpenFileDialog control. which is basically a mini explorer that saves the file name you select in a property. Something like this should work:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
DialogResult result = ofd.ShowDialog();
if(result != DialogResult.Cancel)
{
richTextBox1.Text = File.ReadAllText(ofd.FileName);
}
}
There's not really an easy way to do what you want (windows explorer integration and change the default 'open with' program). Even if it was easy, it'd be considered bad practice.
If you need your program open a file, the best option is to allow an user to open the file from the program. There's a control called OpenFileDialog in the tool box (assuming you're using WinForms that can do this). Work through this tutorial. It's a bit old, but should get you started.

sound play for any computers

I use these following codes to play music while clicking the button.
private void button1_Click(object sender, EventArgs e)
{
SoundPlayer s = new SoundPlayer();
s.SoundLocation = #"f:\1.wav";
s.Play();
}
But these codes are only for my computer what should i do so that i can play this sound on the other computers like database. what should i do so that i can play this song in other computers?
Thanks in advance
You can import the file in the project's resources and load it from there using
Properties.Resources.<name_of_resource>
In order to import something to the resources do the following (assuming you use Visual Studio 2010 - it is similar to other versions I think):
In Visual Studio 2010 solution explorer, right click Properties -> Open -> Resources -> Add Resource -> Add Existing File
Note that when you will install your application later on other computers the resources will be installed as well.
In order to play the sound you need to do the following then:
SoundPlayer myPlayer = new SoundPlayer(yourNamespace.Properties.Resources.mySound);
myPlayer.Play();
You can do something like, get the file content as Stream from the database
You can do something like, get the file content as Stream from the database or remote system and pass the stream to the SoundPlayer instance.
You can store the sounds in a subfolder of the applications and access them via file's relative path (I believe, but I'm going to look it up precisely, it's Application.StartupPath in a winforms environment).
Or you could make them resources (see gkaran89's answer).

OpenFileDialog/c# slow on any file. better solution?

I am opening a file using the OpenFileDialog in c# and I am noticing it is taking between 20-40 seconds to load my file and clear the dialog.
Here is my sample code:
private void btnOpen_Click(object sender, EventArgs e)
{
if (ofdSettings.ShowDialog() == DialogResult.OK)
{
// do nothing
}
}
even with this limited example it takes the 20-40 second duration for the dialog to clear.
the file i'm selecting is a xml file that is only 1.36kb large
I had the same problem, openFileDialog1.ShowDialog() was slow, taking 10 seconds after closing it to execute the next line of my program.
I noticed in the dialog that I had a couple old shortcuts under "Computer" pointing to webdav url's which were no longer valid. I deleted these shortcuts from windows explorer, and the program is fast now.
Check if you have any network connection shortcuts tied to your computer, which also display in the dialog (on the left-hand panel in Windows 7). Try removing them and see if the dialog is faster.
Another option which helped in my case:
OpenFileDialog ofd = new OpenFileDialog
{
...
AutoUpgradeEnabled = false
};
With this option, OpenFileDialog renders simpler UI, "pre-Vista" style according to MSDN article.
I also had this problem when I want to open a example.url file with file open dialog. It takes 0-10 seconds. Then I find out that this has something todo with the file type association (*.url) When I changed the association from default web browser to notepad++ the problem was gone. But I this was no solution for me, because when somebody clicked on a example.url, the default browser should open this file. To solve this I added DereferenceLinks = false.
OpenFileDialog ofd = new OpenFileDialog
{
...
DereferenceLinks = false
};
For me this solution works perfect
You can use a free tool like ProcExp (SysInternals.com) to monitor what your application is doing during the lag. Is it scanning the file system? The registry? The network (maybe it is trying to connect to a network share that is slow to respond).
BTW, you can run ProcExp.exe without installing it from http://live.sysinternals.com/!

Categories