zoukankan      html  css  js  c++  java
  • VB.Net : ApplicationEvents类中,创建主程序的快捷方式 , 捕获程序未Try的错误及抛出相关的类和方法名 , 是否联机等相关。。

    代码
    Imports System.ComponentModel
    Imports IWshRuntimeLibrary  '创建快捷方式所需

    Namespace My

        
    ' 以下事件可用于 MyApplication:
        ' 
        ' Startup: 应用程序启动时在创建启动窗体之前引发。
        ' Shutdown: 在关闭所有应用程序窗体后引发。如果应用程序异常终止,则不会引发此事件。
        ' UnhandledException: 在应用程序遇到未处理的异常时引发。
        ' StartupNextInstance: 在启动单实例应用程序且应用程序已处于活动状态时引发。
        ' NetworkAvailabilityChanged: 在连接或断开网络连接时引发。
        Partial Friend Class MyApplication
            
    Private Sub MyApplication_Startup(ByVal sender As ObjectByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup


                
    Dim startpath As String = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\旅游ERP系统\\旅行社机票管理系统.appref-ms"



                
    '创建快捷方式
                Dim shell As WshShell = New WshShell()
                
    Dim shortcut As IWshShortcut = CType(shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\旅游ERP系统222.lnk"), IWshShortcut)
                shortcut.TargetPath 
    = startpath
                shortcut.WorkingDirectory 
    = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\旅游ERP系统"
                shortcut.WindowStyle 
    = 2
                
    '//shortcut.Arguments = "/p XMAPGL /nologo";  //指向目标运行的参数
                shortcut.Description = "旅游ERP系统"
                shortcut.IconLocation 
    = System.Environment.CurrentDirectory + "\\" + "icon.ico" 'System.Environment.SystemDirectory + "\\" + "shell32.dll, 163"; 

                
    If Not System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\旅游ERP系统222.lnk"Then

                    shortcut.Save()
                
    Else


                
    End If


                
    'MsgBox("已经成功更新了该用户资料", MsgBoxStyle.OkOnly + _
                '        MsgBoxStyle.Exclamation, "更新成功")

                
    Call SetConnectionStatus(My.Computer.Network.IsAvailable)

            
    End Sub

            
    Private Sub MyApplication_UnhandledException(ByVal sender As ObjectByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
                
    Dim m As New currentMethodInformation(e.Exception.TargetSite)

                
    MsgBox(m.ToString, MsgBoxStyle.OkOnly, "try,continue,cancle,exit application:err from")
                e.ExitApplication 
    = False
                
    'If MsgBox(m.ToString, MsgBoxStyle.RetryCancel, "try,continue,cancle,exit application:err from") = MsgBoxResult.Retry Then
                '    e.ExitApplication = False

                
    'Else

                
    'End If

            
    End Sub

            
    Private Sub MyApplication_NetworkAvailabilityChanged(ByVal sender As ObjectByVal e As Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs) Handles Me.NetworkAvailabilityChanged
                
    ''If e.IsNetworkAvailable Then
                ''    'My.Forms.frmMain.Text = "网络暂时不可用"
                ''Else
                ''    'My.Forms.frmMain.Text = "Explorer(试用版)"


                
    ''    '.Text = My.Resources.DisconnectedText    '调用资源文件
                ''End If

                
    Call SetConnectionStatus(My.Computer.Network.IsAvailable)

            
    End Sub

            
    Private Sub SetConnectionStatus(ByVal Connected As Boolean)
                
    'With My.Forms.Form2.ConnectedStatusLabel

                
    '    If Connected Then
                '        .Image = My.Resources.connected.ToBitmap
                '        .Text = My.Resources.ConnectedText
                '    Else
                '        .Image = My.Resources.disconnected.ToBitmap
                '        .Text = My.Resources.DisconnectedText

                
    '    End If
                'End With
            End Sub


        
    End Class

    End Namespace

    Public Class currentMethodInformation
        
    Private gMethodbase As System.Reflection.MethodBase
        
    Sub New(ByVal methodbase As System.Reflection.MethodBase)
            gMethodbase 
    = methodbase
        
    End Sub

        
    Sub New(ByVal stackFrame As System.Diagnostics.StackFrame)
            gMethodbase 
    = stackFrame.GetMethod
        
    End Sub

        
    <Description("程序集名称")> _
        
    Public ReadOnly Property AssemblyName() As String
            
    Get
                
    Return gMethodbase.DeclaringType.Assembly.GetName.Name
            
    End Get
        
    End Property

        
    <Description("程序集版本")> _
        
    Public ReadOnly Property AssemblyVersion() As String
            
    Get
                
    Return gMethodbase.DeclaringType.Assembly.GetName.Version.ToString
            
    End Get
        
    End Property

        
    <Description("类名")> _
        
    Public ReadOnly Property TypeName() As String
            
    Get
                
    Return gMethodbase.DeclaringType.FullName
            
    End Get
        
    End Property

        
    <Description("方法名")> _
        
    Public ReadOnly Property Name() As String
            
    Get
                
    Return gMethodbase.ToString
            
    End Get
        
    End Property

        
    Public Overloads Function ToString() As String
            
    Dim b As New System.Text.StringBuilder
            b.Append(System.Environment.NewLine)
            b.AppendFormat(
    "  程序集名称 :{0}"Me.AssemblyName)
            b.Append(System.Environment.NewLine)
            b.AppendFormat(
    "  程序集版本 :{0}"Me.AssemblyVersion)
            b.Append(System.Environment.NewLine)
            b.AppendFormat(
    "        类名 :{0}"Me.TypeName)
            b.Append(System.Environment.NewLine)
            b.AppendFormat(
    "      方法名 :{0}"Me.Name)
            b.Append(System.Environment.NewLine)
            
    Return b.ToString
        
    End Function

    End Class

    /Files/Fooo/Interop.IWshRuntimeLibrary.rar

  • 相关阅读:
    F2etest v2.0.0 正式发布 ,阿里巴巴开源测试方案
    Spring-Wind 1.1.1 发布,SSM 架构核心库
    通过nginx配置文件抵御攻击 | WooYun知识库
    阿里云X-Forwarded-For 发现tomcat记录的日志全部来自于SLB转发的IP地址,不能获取到请求的真实IP。
    openresty+lua在反向代理服务中的玩法 | WooYun知识库
    java~lambda表达式让查询更优雅
    java~日期与字符串的转化
    java~google样式检查和命名规范
    springboot~Mongodb的集成与使用
    springboot~JPA把ORM统一起来
  • 原文地址:https://www.cnblogs.com/Fooo/p/1691558.html
Copyright © 2011-2022 走看看