|  |  | 
              
              | 
                  | Title | Prevent the user from renaming an executable in Visual Basic .NET | 
|---|
 | Description | This example shows how to prevent the user from renaming an executable in Visual Basic .NET. | 
|---|
 | Keywords | rename, prevent rename, executable, execute, VB.NET | 
|---|
 | Categories | Software Engineering, Miscellany | 
|---|
 |  | 
 |  | When the program starts, it gets the current process's name. It compares that name to the program's original name stored in code. If the names do not match, the example program gives the original and new names. A real application might refuse to run. |  | 
 |  
                | Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    Const CORRECT_NAME As String = "howto_net_dont_rename"
    ' Get the current process name.
    Dim proc_name As String = _
        Process.GetCurrentProcess.ProcessName
    ' Compare to a hard-coded value.
    If proc_name = CORRECT_NAME Then
        lblStatus.Text = "Original name:" & _
            vbCrLf & CORRECT_NAME
        lblStatus.ForeColor = Color.Blue
    Else
        lblStatus.Text = "Renamed from:" & _
            vbCrLf & CORRECT_NAME & vbCrLf & _
            "To:" & vbCrLf & proc_name
        lblStatus.ForeColor = Color.Red
    End If
End Sub |  |  |  |   |  |  |  |  |