Launch_Programs_Class
1| using System;
2| using System.Collections.Generic;
3| using System.Linq;
4| using System.Text;
5|
6| //add references
7| using System.IO;
8| using System.Windows.Forms;
9|
10| namespace MyDesktop
11| {
12| class Launch_Programs_Class
13| {
14| //constructor method
15| public Launch_Programs_Class()
16| {
17|
18| }
19|
20| public void Launch_Drive(Drives_Class[] oDrive, int iIndex)
21| {
22| string sDrivePath = oDrive[iIndex].Get_Path();
23|
24| try
25| {
26| System.Diagnostics.Process.Start(sDrivePath);
27| }
28| catch
29| {
30| MessageBox.Show("No media in this drive.");
31| }
32| }
33|
34| public void Launch_App(Apps_Class[] oApp, int iIndex)
35| {
36| //Save the current MyDesktop.exe directory
37| string sSaveCurLoc = Directory.GetCurrentDirectory();
38| string sPath = oApp[iIndex].Get_Path();
39| string sDirectory = "";
40|
41| //create a new object
42| System.Diagnostics.Process oProcess = new System.Diagnostics.Process();
43|
44| //We do not need to know when application finishes
45| oProcess.EnableRaisingEvents = false;
46|
47| //Full path name for full drive, path, and name of program.
48| oProcess.StartInfo.FileName = oApp[iIndex].Get_Path();
49|
50| /*Set the UseShellExecute to "true" for non-executable launches and
51| "false" for executable launches (.exe)*/
52| if (oApp[iIndex].Get_Path().EndsWith("exe"))
53| {
54| oProcess.StartInfo.UseShellExecute = false;
55| }
56| else
57| {
58| oProcess.StartInfo.UseShellExecute = true;
59| }
60|
61| //specific launch arguments
62| oProcess.StartInfo.Arguments = oApp[iIndex].Get_Parameter();
63|
64| //Is there a start-in value
65| if(!oApp[iIndex].Get_Start_in().Equals(""))
66| {
67| Directory.SetCurrentDirectory(oApp[iIndex].Get_Start_in());
68| }
69| else
70| {
71| sDirectory = sPath.Substring(0, sPath.LastIndexOf("\\") + 1);
72| System.IO.Directory.SetCurrentDirectory(sDirectory);
73| }
74|
75| oProcess.Start();
76|
77| //Very last thing
78| Directory.SetCurrentDirectory(sSaveCurLoc);
79| }
80|
81| public void Launch_Site(Sites_Class[] oSite, int iIndex)
82| {
83| string sURL = oSite[iIndex].Get_Url();
84| string sBrowser = oSite[iIndex].Get_Browser();
85|
86| try
87| {
88| System.Diagnostics.Process.Start(sBrowser, sURL);
89| }
90| catch
91| {
92| MessageBox.Show("Site not available or invalid URL.");
93| }
94| }
95| }//end of class
96| }