Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Wednesday, 15 October 2008

Get your Application to run at windows start-up

Hi,

Creating a registry key to get your application to run at start-up. I put it in the Local machine folder to get it starting for all users. The example shows for local user, not sure if this will run for every user.

Click me

Enjoy!

This was used in the Flexi (MyTime) system.

Friday, 10 October 2008

Put your application in the system tray

Found this blog. East step by step guide on how to setup your application to run in the System Tray.

http://www.developer.com/net/csharp/article.php/3336751

Enjoy!

Thursday, 9 October 2008

Run a DTS package through an application

To run a dts package through code:

Using:
using System.Threading;
using DTS;

Declare:
private Thread dts;

Method:
private void CallDTS()
{
dts = new Thread(new ThreadStart(RunDTSPackage));
dts.Start
}

private void RunDTSPackage()
{
try
{
object obj = new object();

PackageClass csDTS = new PackageClass();
csDTS.LoadFromSQLServer("Server", null, null, DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, null, null, null, "PackageName", ref obj);
csDTS.Execute();
csDTS.UnInitialize();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

You might need to wait until the package is finished running before you carry on and call other methods so check for:
while (dts.IsAlive)
{
}
DoSomething();

Thats it.

Check if an instance of another app is open

The following method checks to see if an instance of a specific application is running.....

using System.Diagnostics;

private bool CheckIfPPlusOpen()
{
Process[] pApps = Process.GetProcesses();
bool bPPlus = false;
foreach (Process p in pApps)
{
if (p.ProcessName.Equals("P+Test"))
{
bPPlus = true;
}
}
if (!bPPlus)
{
GetPPlusAbsenceData();
}
else
{
MessageBox.Show("Please close P+ before refreshing the P+ data!", "Close P+", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
return bPPlus;
}

Stop multiple instances of your windows app running

I needed to stop users from starting up more than one copy of the MyTime app running and I found this link to help.

I changed where the code actually runs, I think its a bit better this way.

1. Open up the Program.cs file.

2. Add System.Threading into the using list.

3. Paste this in the class declaration
private static Mutex mutex;
private static string mutexName = "MyTime.Mutex";

4. Paste this in the main() method before any other code runs.
try
{
mutex = Mutex.OpenExisting(mutexName);

//since it hasn’t thrown an exception, then we already have one copy of the app open.
MessageBox.Show("A copy of MyTime is already open.",
"MyTime", MessageBoxButtons.OK, MessageBoxIcon.Information);

//use this command as we haven't called the run method of the application
Environment.Exit(0);
}
catch
{
//since we didn’t find a mutex with that name, create one
mutex = new Mutex(true, mutexName);
}

//Hook up the Application Exit event to release the mutex so that the app can re-open correctly.
Application.ApplicationExit += new EventHandler(delegate { mutex.ReleaseMutex(); });


5. Thats it. Test it!


Don't think there is much else to this. Any questions let me know.

Monday, 4 August 2008

Windows installer - Remove Previous Versions

http://www.simple-talk.com/dotnet/visual-studio/updates-to-setup-projects/

Excellent link and explains how to unisintall previous versions of your application.

Note that the version number in the article refers to the installer version number that is accessed in the properties window. This must also being at 1.0.0 or above, otherwise the RemovePreviousVersions property won't pick it up as a previous version and won't work.

Enjoy!

Wednesday, 25 June 2008

Deploying Windows Applications

Quick guide.......

1. Open .Net project
2. Right click solution in the solution explorer
3. Add - New Project
4. Select setup and Deployment from Project Types
5. Select Setup Project
6. Enter relevant name
7. Right click Setup project
8. Add - Project Output - ok (all dependencies should appear)
9. Build Setup and Project
10. MSI installer is created in the setup project folder which has been created beside the main project application.
11. Run the installer to create the MSI.


For any other prerequisites that might be needed for the application right click on the setup project in the solution explorer, click prerequisites and check the prerequisites to install and then build the setup file.

For example we had a problem trying to deploy an Windows .Net 2005 application which had crystal reports included in it. To get round this the Crystal Reports for .Net Framework 2.0 prerequisites had to be checked (following the steps above). This then created an MSI for the Crystal Reports Framework in the setup folder. Once installed on the users machine the reports worked fine.
Free Hit Counter