• VB6 CHECK is run as admin privilege


    vb6 code:

    Private Declare Function IsUserAnAdmin Lib "Shell32" Alias "#680" () As Integer
    
    
    Private Sub Form_Load()
    
    If IsUserAnAdmin() = 0 Then
    MsgBox "Not admin"
    Else
    MsgBox "Admin"
    End If
    
    end sub
    

      

    get windows OS version information:

    Option Explicit
    
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
        (lpVersionInformation As OSVERSIONINFO) As Long
    
    Private Type OSVERSIONINFO
      OSVSize         As Long
      dwVerMajor      As Long
      dwVerMinor      As Long
      dwBuildNumber   As Long
      PlatformID      As Long
      szCSDVersion    As String * 128
    End Type
    
    Private Const VER_PLATFORM_WIN32s = 0
    Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    Private Const VER_PLATFORM_WIN32_NT = 2
    
    ' Returns the version of Windows that the user is running
    Public Function GetWindowsVersion() As String
        Dim osv As OSVERSIONINFO
        osv.OSVSize = Len(osv)
    
        If GetVersionEx(osv) = 1 Then
            Select Case osv.PlatformID
                Case VER_PLATFORM_WIN32s
                    GetWindowsVersion = "Win32s on Windows 3.1"
                Case VER_PLATFORM_WIN32_NT
                    GetWindowsVersion = "Windows NT"
    
                    Select Case osv.dwVerMajor
                        Case 3
                            GetWindowsVersion = "Windows NT 3.5"
                        Case 4
                            GetWindowsVersion = "Windows NT 4.0"
                        Case 5
                            Select Case osv.dwVerMinor
                                Case 0
                                    GetWindowsVersion = "Windows 2000"
                                Case 1
                                    GetWindowsVersion = "Windows XP"
                                Case 2
                                    GetWindowsVersion = "Windows Server 2003"
                            End Select
                        Case 6
                            Select Case osv.dwVerMinor
                                Case 0
                                    GetWindowsVersion = "Windows Vista/Server 2008"
                                Case 1
                                    GetWindowsVersion = "Windows 7/Server 2008 R2"
                                Case 2
                                    GetWindowsVersion = "Windows 8/Server 2012"
                                Case 3
                                    GetWindowsVersion = "Windows 8.1/Server 2012 R2"
                            End Select
                    End Select
    
                Case VER_PLATFORM_WIN32_WINDOWS:
                    Select Case osv.dwVerMinor
                        Case 0
                            GetWindowsVersion = "Windows 95"
                        Case 90
                            GetWindowsVersion = "Windows Me"
                        Case Else
                            GetWindowsVersion = "Windows 98"
                    End Select
            End Select
        Else
            GetWindowsVersion = "Unable to identify your version of Windows."
        End If
    End Function
    

      

    check OS byte 32 or 64:

    Private Declare Function GetProcAddress Lib "kernel32" _
        (ByVal hModule As Long, ByVal lpProcName As String) As Long
    
    Private Declare Function GetModuleHandle Lib "kernel32" _
        Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
    
    Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
    
    Private Declare Function IsWow64Process Lib "kernel32" _
        (ByVal hProc As Long, ByRef bWow64Process As Boolean) As Long
    
    Public Function IsHost64Bit() As Boolean
        Dim handle As Long
        Dim is64Bit As Boolean
    
        ' Assume initially that this is not a WOW64 process
        is64Bit = False
    
        ' Then try to prove that wrong by attempting to load the
        ' IsWow64Process function dynamically
        handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")
    
        ' The function exists, so call it
        If handle <> 0 Then
            IsWow64Process GetCurrentProcess(), is64Bit
        End If
    
        ' Return the value
        IsHost64Bit = is64Bit
    End Function
    

      

     shellexcute, application is run as admin

    Private Declare Function ShellExecute Lib "shell32.dll" Alias _
            "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
            String, ByVal lpFile As String, ByVal lpParameters As String, _
            ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Declare Function IsUserAnAdmin Lib "Shell32" Alias "#680" () As Integer
    
    
    sample:
     
     ShellExecute 0, "runas", App.Path & "1.exe", "/admin", vbNullString, 1
    

      

  • 相关阅读:
    扒皮下音悦台的“返回顶部”图标效果
    扒皮下京东首页楼层图标的动画效果实现方式
    总结前端开发中的一些特殊规范
    用JS识别各版本浏览器
    各主流浏览器内核介绍
    CSS百分比定义高度的冷知识
    图解js中常用的判断浏览器窗体、用户屏幕可视区域大小位置的方法
    从一个简单例子来理解js引用类型指针的工作方式
    仿京东首页商品分类底部色标随鼠标移动特效
    知乎网首页一个延时交互的小思路
  • 原文地址:https://www.cnblogs.com/wgscd/p/9229185.html
Copyright © 2020-2023  润新知