阻止删除文件(文件占坑)的VB代码(翻译自VC版)

页面导航:首页 > 软件编程 > vb.net > 阻止删除文件(文件占坑)的VB代码(翻译自VC版)

阻止删除文件(文件占坑)的VB代码(翻译自VC版)

来源: 作者: 时间:2016-01-21 10:23 【

文章作者:zhouweizhu翻译自:http://forum.eviloctal.com/thread-32738-1-3.html呵呵下面是关键代码的VC和VB的对照翻译所有声明、结构、常量都有提权代码就自己随便找一个吧……使用方法DupFile “要

文章作者:zhouweizhu

翻译自:">http://forum.eviloctal.com/thread-32738-1-3.html
呵呵
下面是关键代码的VC和VB的对照翻译
所有声明、结构、常量都有
提权代码就自己随便找一个吧……
使用方法DupFile “要阻止删除的文件路径”,进程ID
引用:
VC版摘录自
VB版由兔子翻译,
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function DuplicateHandle Lib "kernel32" (ByVal hSourceProcessHandle As Long, ByVal hSourceHandle As Long, ByVal hTargetProcessHandle As Long, lpTargetHandle As Long, ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwOptions As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Const WebSite As String = ""
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_WRITE = &H2
Private Const FILE_SHARE_READ = &H1
Private Const OPEN_ALWAYS = 4
Private Const FILE_ATTRIBUTE_NORMAL = &H80
typedef   struct   _SECURITY_ATTRIBUTES   {
      DWORD     nLength;
      LPVOID   lpSecurityDescriptor;
      BOOL       bInheritHandle;
  }   SECURITY_ATTRIBUTES,   *PSECURITY_ATTRIBUTES;
Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Boolean
End Type
Private Const PROCESS_DUP_HANDLE As Long = &H40
Private Const INVALID_HANDLE_VALUE = -1
Private Const DUPLICATE_SAME_ACCESS = &H2
Private Const DUPLICATE_CLOSE_SOURCE = &H1
Dim xxNull As SECURITY_ATTRIBUTES
BOOL DupFile( LPCTSTR lpFileName , int pid )
Public Function DupFile(lpFileName As String, pid As Long) As Boolean
{
    BOOL    bRedup;
    Dim bRedup As Boolean
    HANDLE  hFile,hProcess;
    Dim hFile As Long, hProcess As Long
    HANDLE  hTargetHandle;
    Dim hTargetHandle As Long

    EnablePrivilege(SE_DEBUG_NAME,TRUE);
    EnablePrivilege (SE_DEBUG) 提升权限

    if(ProcessList(pid)) printf("Process Name: %s ",szProcessName);

    hProcess = OpenProcess( PROCESS_DUP_HANDLE, FALSE, pid);
    hProcess = OpenProcess(PROCESS_DUP_HANDLE, False, pid)
    if ( hProcess == NULL )
    If hProcess = 0 Then
       {
           printf("PROCESS_DUP_HANDLE Error ");
        MsgBox "PROCESS_DUP_HANDLE Error"
           return FALSE;
        DupFile = False
        Exit Function
       }
    End If

Tags:

相关文章

    文章评论

    最 近 更 新
    热 点 排 行
    Js与CSS工具
    代码转换工具
    
    <