Obtain the running path of the Setup file

Source: Internet
Author: User
Yesterday, the project did not know the specific configuration information before packaging because it needs to be configured during installation. It seems convenient to use InstallShield for packaging, but this method does not work because it uses the running path of Visual Studio. Obtaining the installation path is also very simple and there are many methods.
I thought that the program had to have only one running instance when I was working on the project. This method is not very good. I want to handle it in another way: first obtain all processes currently running and then find the Setup or *. msi. As soon as you think of it, you can try it out and add and process the code in the program. Process [] processes = Process. GetProcesses ();
String tmp = "";
Int I = 0; // query the number of threads during debugging
Foreach (Process pro in processes)
{
// MSI Title is the Title displayed when your package file is running.
If (pro. ProcessName. ToLower () = "msiexec" & pro. MainWindowTitle = "MSI Title ")
{
// During the test in Vista, the file is read and written (because Vista uses UAC to enhance security,
// The operation must be performed as an administrator, but running an msi file directly can only be executed with normal permissions ),
// If the user does not directly run the msifile, the user needs to run it from the setup.exe file,
// This is not required if you do not need to use it in Vista
MessageBox. Show ("Please run setup.exe", "ERROR", MessageBoxButtons. OK, MessageBoxIcon. Error );
Throw new InstallException ("run ");
}
Else if (pro. ProcessName. ToLower (). IndexOf ("setup")> 0 & pro. MainWindowTitle = "MSI Title ")
{// Determine whether ProcessName is setup and Its MainWindowTitle is the Title of your Installation File
Tmp = tmp + pro. Id + "" + pro. ProcessName + Environment. NewLine;
Tmp = tmp + "" + I. toString () + "=" + pro. mainModule. fileName + Environment. newLine; // pro. mainModule. fileName is the complete running path of Setup.
Tmp = tmp + "" + I. ToString () + "=" + pro. MainWindowTitle + Environment. NewLine;

}
}
MessageBox. Show (tmp );

If the user changes the file name of setup.exe or *. msi, it will be difficult to handle it. To prevent the user from running the installation after changing the file name, you can add it to the program to judge the processing of the file name change and give the user a prompt.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.