仅在文件存在时启动项目

时间:2016-06-29 09:40:22

标签: c# wpf visual-studio

我有两个不同的可执行文件,一个是登录名,另一个是主应用程序。

现在,我想让它只能打开登录,而不是主程序。现在,只需点击它即可打开主应用程序。

登录应用程序创建一个包含一些信息的小txt文件,然后主程序启动并删除该文件。

有没有办法让主程序只在这个文件存在时启动?因此,没有人首先登录,任何人都无法启动主应用程序。

因此,当您登录时,如果您的帐户存在,应用程序将检查mysql数据库。 然后运行:

try
{
    $auth = array(
        'Username'=>'XXXXX',
        'Password'=>'XXXXX',
    );

    $client = new \SoapClient('https://test.com//Indirect.svc?wsdl', array('soap_version' => SOAP_1_2, 'trace' => 1));

    $actionHeader = new \SoapHeader('http://www.w3.org/2005/08/addressing', Action', http://tempuri.org/IInDirect/AddProduct');

    $client->__setSoapHeaders($actionHeader);

    $response = $client->AddProduct($xmlstr);
}

catch (\Exception $e)
{
    echo "Error!";
    echo $e -> getMessage ();
    echo 'Last response: '. $client->__getLastResponse();
}

然后dat.exe启动,并运行:

    string übergabeparameter = Convert.ToString(typ);
       string filename = (@"C:\Users\viuser\Desktop\test\dat.exe");
        var proc = System.Diagnostics.Process.Start(filename, übergabeparameter);

        using (System.IO.StreamWriter sw = System.IO.File.CreateText("fluff.txt"))
        {
            sw.Write(benutzername + System.Environment.NewLine + typ);
        }


        Close();

我使用wpf和c#在Visual Studio中创建了这两个应用程序。

1 个答案:

答案 0 :(得分:1)

在主应用程序的启动代码中检查文件。如果文件不存在,您可以通知用户启动正确的exe(登录)。我也有登录添加某种哈希代码,所以主程序知道登录是合法的,以防止伪造登录或可能是一个旧的txt文件,在上次登录后没有被删除(主要组织可能在删除文件之前已经崩溃或其他异常终止。)

相关问题