Visual Basic,使应用程序仅在特定文件夹中打开

时间:2019-04-02 21:28:13

标签: vb.net

有没有一种方法可以使Visual Basic .net应用程序仅位于特定的文件夹/路径中,或者该文件夹中包含某个元素时才打开? 谢谢。

2 个答案:

答案 0 :(得分:0)

轻松,载入事件:

If not Application.StartupPath() = "C:\" then
    Application.Exit()
End if

答案 1 :(得分:0)

您可以使用它来检查应用程序路径中的文件夹或文件:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'check if folder exists
        If Not IO.Directory.Exists(Application.StartupPath & "\yourdirname") Then
            Application.Exit()
        End If

        'check if file exists
        If Not IO.File.Exists(Application.StartupPath & "\yourdirname\yourfile.ext") Then
            Application.Exit()
        End If

    End Sub
End Class
相关问题