vb 取得进程地址
vb 获取路径
vb 获取路径摘要:1.获取路径的意义2.VB 编程语言介绍3.VB 中获取路径的方法4.获取路径的实例演示5.总结正文:【1.获取路径的意义】在计算机编程中,获取路径是一项常见的操作。
路径指的是一个文件或文件夹在计算机中的具体存储位置。
获取路径可以帮助程序员在编写代码时准确地定位到某个文件或文件夹,以便对其进行读取、写入或删除等操作。
在VB 编程语言中,也有相应的函数可以实现获取路径的功能。
【2.VB 编程语言介绍】Visual Basic(简称VB)是一种由微软公司开发的编程语言,它具有简单易学、功能强大的特点,广泛应用于Windows 平台的应用程序开发。
VB 使用面向对象的编程方法,可以帮助程序员快速地构建出功能完善的软件。
【3.VB 中获取路径的方法】在VB 中,有多种方法可以获取路径。
以下列举了几种常用的方法:1) 使用“puter”对象```vbDim path As String =puter.FileSystem.SpecialDirectories("MyDocuments") ```2) 使用“My.Application”对象```vbDim path As String = .DirectoryPath```3) 使用“Path”函数```vbDim path As String = Path.GetTempPath()```【4.获取路径的实例演示】以下是一个简单的VB 程序,演示了如何获取"MyDocuments"文件夹的路径:```vbImports SystemModule Module1Sub Main()Dim path As String" 使用puter.FileSystem.SpecialDirectories 方法获取路径path =puter.FileSystem.SpecialDirectories("MyDocuments")Console.WriteLine("MyDocuments 路径:" & path)" 使用.DirectoryPath 方法获取路径path = .DirectoryPathConsole.WriteLine("应用程序路径:" & path)" 使用Path.GetTempPath() 方法获取路径path = Path.GetTempPath()Console.WriteLine("临时文件夹路径:" & path)Console.ReadKey()End SubEnd Module```【5.总结】通过以上介绍,我们可以看到,在VB 编程语言中,有多种方法可以获取路径。
VB利用GetObject(WinMgmts)获取系统信息
For Each wbemObject In wbemObjectSet
WScript.Echo "物理内存 (MB): " & CInt(wbemObject.TotalPhysicalMemory/1024)
用WMI对象列出系统所有进程:
----Instance.vbs---- 程序代Βιβλιοθήκη Dim WMI,objs
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_Process")
For Each obj In objs
next
msgbox infor
CPU的序列号:
---CPUID.vbs---
程序代码
Dim cpuInfo
cpuInfo = ""
set moc = GetObject("Winmgmts:").InstancesOf("Win32_Processor")
for each mo in moc
for each mo in moc
HDid = mo.Model
msgbox "硬盘型号为:" & HDid
next
网卡MAC物理地址:
---MACAddress.vbs---
程序代码
Dim mc
VB获取IP地址
IP = Right(IPstr, Len(IPstr) - InStr(IPstr, "["))
sLocalFile = "c:\ip.txt"
Call DeleteUrlCacheEntry(sSourceUrl)
If DownloadFile(sSourceUrl, sLocalFile) Then
hfile = FreeFile
Open sLocalFile For Input As #hfile
Dim Adapter As IP_ADAPTER_INFO
Call GetAdaptersInfo(ByVal 0&, cbRequired)
If cbRequired > 0 Then
ReDim buff(0 To cbRequired - 1) As Byte
WebBrowser1.Navigate ""
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error Resume Next '忽略错误 没有网络连接就没有从电信那获得外网IP 也就没有结果
Text2.Text = ""
End Sub
Private Sub Command1_Click()
VB函数GetProcessList(获得进程列表)
theloop = ProcessFirst(snap, proc) '获取第一个进程,并得到其返回值
i = 0
While theloop <> 0 '当返回值非零时继续获取下一个进程
'GetJingCheng = GetJingCheng & proc.szExeFile & Chr(2) & proc.th32ProcessID & Chr(2)
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
GetJingCheng = ""
Dim i As Long
Dim theloop As Long
Dim proc As PROCESSENTRY32
Dim snap As Long
Dim Exename As String
GetJingCheng = "" '清空所有内容
snap = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '获得进程“快照”的句柄
Private Const TH32CS_SNAPPROCESS = &H2
VB中怎么获取客户机电脑名和IP地址?谢谢!不是.net哦
VB中怎么获取客户机电脑名和IP地址?谢谢!不是.net哦分類:電腦/網絡 >> 程序設計 >> 其他編程語言解析:Private Const NCBASTAT = &H33Private Const NCBNAMSZ = 16Private Const HEAP_ZERO_MEMORY = &H8Private Const HEAP_GENERATE_EXCEPTIONS = &H4 Private Const NCBRESET = &H32Private Type NCBncb_mand As Bytencb_retcode As Bytencb_lsn As Bytencb_num As Bytencb_buffer As Longncb_length As Integerncb_callname As String * NCBNAMSZncb_name As String * NCBNAMSZncb_rto As Bytencb_sto As Bytencb_post As Longncb_lana_num As Bytencb_cmd_cplt As Bytencb_reserve(9) As Byte ' Reserved, must be 0ncb_event As LongEnd TypePrivate Type ADAPTER_STATUSadapter_address(5) As Byterev_major As Bytereserved0 As Byteadapter_type As Byterev_minor As Byteduration As Integerfrmr_recv As Integerfrmr_xmit As Integeriframe_recv_err As Integer xmit_aborts As Integerxmit_success As Longrecv_success As Long iframe_xmit_err As Integer recv_buff_unavail As Integer t1_timeouts As Integerti_timeouts As Integer Reserved1 As Longfree_ncbs As Integermax_cfg_ncbs As Integer max_ncbs As Integerxmit_buf_unavail As Integer max_dgram_size As Integer pending_sess As Integer max_cfg_sess As Integer max_sess As Integermax_sess_pkt_size As Integer name_count As IntegerEnd TypePrivate Type NAME_BUFFER name As String * NCBNAMSZ name_num As Integer name_flags As IntegerEnd TypePrivate Type ASTATadapt As ADAPTER_STATUSNameBuff(30) As NAME_BUFFEREnd TypePrivate Declare Function Netbios Lib "api32.dll" (pncb As NCB) As BytePrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)Private Declare Function GetProcessHeap Lib "kernel32" () As LongPrivate Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As LongPrivate Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long Private Function EtherAddress(LanaNumber As Long) As StringDim udtNCB As NCBDim bytResponse As ByteDim udtASTAT As ASTATDim udtT empASTAT As ASTATDim lngASTAT As LongDim strOut As StringDim x As IntegerudtNCB.ncb_mand = NCBRESETbytResponse = Netbios(udtNCB)udtNCB.ncb_mand = NCBASTATudtNCB.ncb_lana_num = LanaNumberudtNCB.ncb_callname = "* "udtNCB.ncb_length = Len(udtASTAT)lngASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY, udtNCB.ncb_length)strOut = ""If lngASTAT ThenudtNCB.ncb_buffer = lngASTATbytResponse = Netbios(udtNCB)CopyMemory udtASTAT, udtNCB.ncb_buffer, Len(udtASTAT) With udtASTAT.adaptFor x = 0 To 5strOut = strOut & "-" & Right$("00" & Hex$(.adapter_address(x)), 2)Next xEnd WithHeapFree GetProcessHeap(), 0, lngASTATEnd IfEtherAddress = strOutEnd FunctionPrivate Sub Command1_Click()Text1.Text = Right$(EtherAddress(0), 17)Text2.Text = Winsock1.LocalIPText3.Text = Winsock1.LocalHostNameEnd SubPrivate Sub Command2_Click()EndEnd Sub。
VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径
VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径本小程序采用枚举进程的方法,显示所有进程,也能显示隐藏进程。
同时,能显示进程的完整路径。
有意思的是,一些已经结束的进程,同样可以显示。
以下是程序运行截图:''''以下是 VB6 代码,在 WinXP 调试通过'需在窗体放置以下 5 个控件,不必设置任何属性,全部采用默认设置:' Command1、List1、Check1、Timer1、Label1'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.htmlPrivate Type tyProcpID As Long: pName As String: pPath As String: pHide As StringEnd TypeDim ctP() As tyProc, ctPs As LongPrivate Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As LongPrivate Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef lpcbNeeded As Long) As LongPrivate Declare Function GetModuleFileNameEx Lib "psapi.dll" Alias"GetModuleFileNameExA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As LongPrivate Declare Function GetProcessImageFileName Lib "psapi.dll" Alias"GetProcessImageFileNameA" (ByVal hProcess As Long, ByVal lpImageFileName As String, ByVal nSize As Long) As LongPrivate Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Const PROCESS_QUERY_INFORMATION = &H400Private Const PROCESS_VM_READ = &H10Private Const PROCESS_CREATE_PROCESS = &H80Private Const PROCESS_CREATE_THREAD = &H2Private Const PROCESS_DUP_HANDLE = &H40'Private Const PROCESS_QUERY_INFORMATION = &H400Private Const PROCESS_QUERY_LIMITED_INFORMATION = &H1000Private Const PROCESS_SET_QUOTA = &H100Private Const PROCESS_SET_INFORMATION = &H200Private Const PROCESS_SUSPEND_RESUME = &H800Private Const PROCESS_TERMINATE = &H1Private Const PROCESS_VM_OPERATION = &H8'Private Const PROCESS_VM_READ = &H10Private Const PROCESS_VM_WRITE = &H20'以下是在 NT 系统中提升当前进程权限的代码================================'系统级权限,可以:PROCESS_ALL_ACCESS OpenProcessToken、LookupPrivilegevalue、AdjustTokenPrivilegesPrivate Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As LongPrivate Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate Declare Function LookupPrivilegeValue Lib "advapi32" Alias"LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As LongPrivate Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_Privileges, ByVal BufferLength As Long, PreviousState As TOKEN_Privileges, ReturnLength As Long) As LongPrivate Type LUIDUsedPart As LongIgnoredForNowHigh32BitPart As LongEnd TypePrivate Type TOKEN_PrivilegesPrivilegeCount As LongTheLuid As LUIDAttributes As LongEnd TypePublic Sub AdjustPrivilege()'NT系统:提升权限Dim dl As Long, CurP As Long, nToKen As Long, nLuid As LUIDDim OldTKP As TOKEN_Privileges, NewTKP As TOKEN_PrivilegesDim pName As StringConst TOKEN_Adjust_Privileges = &H20Const TOKEN_Query = &H8Const SE_Privilege_Enabled_BY_DEFAULT = &H1 '默认权限Const SE_Privilege_Enabled = &H2 '开启权限Const SE_Privilege_USED_FOR_ACCESS = &H80000000 '所有访问权限'获取当前进程的一个句柄CurP = GetCurrentProcess()'打开进程令牌:用 nToKen 获得进程访问令牌的句柄dl = OpenProcessToken(CurP, (TOKEN_Adjust_Privileges Or TOKEN_Query), nToKen)'用 nLuid 返回指定权限的 LUID 结构'权限名称:SeDebugPrivilege、SeShutdownPrivilege、SeRestorePrivilege、SeBackupPrivilege、SeUnsolicitedInputPrivilegepName = "SeDebugPrivilege"dl = LookupPrivilegeValue("", pName, nLuid)NewTKP.PrivilegeCount = 1NewTKP.TheLuid = nLuidNewTKP.Attributes = SE_Privilege_Enabled'调整令牌权限dl = AdjustTokenPrivileges(nToKen, False, NewTKP, Len(NewTKP), OldTKP, 0&) End Sub'===================Private Sub Form_Load() = "宋体": Me.Caption = "枚举进程"Command1.Caption = "刷新" = Call AdjustPrivilege '提升本进程权限Timer1.Interval = 10Check1.Caption = "自动刷新": Check1.Value = 1End SubPrivate Sub Check1_Click()Timer1.Enabled = Check1.Value = 1End SubPrivate Sub Timer1_Timer()Static S As Long, S1 As LongDim nTai As StringS1 = S1 + 1If S1 > 2 ThenS1 = 0nTai = "↖↑↗→↘↓↙←"S = S + 1If S > 8 Then S = 1Label1.Caption = Mid(nTai, S, 1) '动画显示End IfCall ShowProcEnd SubPrivate Sub Command1_Click()List1.Clear: List1.RefreshCall ShowProcEnd SubPrivate Sub Form_Resize()Dim H1 As Single, T As SingleOn Error Resume NextH1 = Me.TextHeight("A")Command1.Move H1, H1, H1 * 4, H1 * 2Label1.Move H1 * 6, H1 * 1.5, H1, H1Check1.Move H1 * 8, H1, H1 * 8, H1 * 2T = Command1.Top + Command1.Height + H1 * 0.5List1.Move 0, T, Me.ScaleWidth, Me.ScaleHeight - TEnd Sub'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html Private Sub ShowProc()Dim pID(1023) As Long, Ps As Long, dwDesiredAccess As LongDim cbNeeded As Long, P As Long, hModule As LongDim hProcess As Long, nStr As String, I As LongDim IsChange As Boolean, P2() As tyProc, Ps2 As LongOn Error Resume NextdwDesiredAccess = PROCESS_QUERY_INFORMATION Or PROCESS_VM_READPs2 = ctPs: P2 = ctPctPs = 1: ReDim ctP(0 To 1)ctP(1).pName = "[System Process]"nStr = String(1024, 0)' 进程ID的数组,数组的大小,返回实际进程数组的大小If EnumProcesses(pID(0), 4& * 1024, cbNeeded) <> 0 ThenPs = cbNeeded \ 4 '进程总数For P = 0 To &HFFFF& Step 4hProcess = OpenProcess(dwDesiredAccess, 0, P) '返回指定进程的句柄If hProcess <> 0 ThenctPs = ctPs + 1: ReDim Preserve ctP(0 To ctPs)ctP(ctPs).pHide = "隐藏"For I = 0 To Ps - 1If P = pID(I) Then ctP(ctPs).pHide = "": Exit ForNext I'nStr 返回主模块全名:每个进程的第一模块即为进程主模块If EnumProcessModules(hProcess, hModule, 4&, 0&) <> 0 Then GetModuleFileNameEx hProcess, hModule, nStr, 1024Else '型如:\Device\HarddiskVolumeGetProcessImageFileName hProcess, nStr, 1024End IfCloseHandle hProcess '关闭进程的句柄With ctP(ctPs).pID = P '进程 ID.pPath = CutStr(nStr, vbNullChar) '进程路径If Left(.pPath, 4) = "\??\" Then .pPath = Mid(.pPath, 5) '去掉“\??\”.pName = CutStr(.pPath, "\", True) '进程名If P = 4 And .pName = "" Then .pName = "System"End WithEnd IfNextEnd If'List1.ClearFor P = 1 To ctPsnStr = AddSpace(P, 4) & ProcStr(ctP(P)) '合成显示条目If P > List1.ListCount ThenList1.AddItem nStr' List1.ListIndex = List1.NewIndexElseIf nStr <> List1.List(P - 1) Then List1.List(P - 1) = nStrEnd IfNext'删除多余条目For P = List1.ListCount - 1 To ctPs Step -1List1.RemoveItem PNextEnd SubPrivate Function ProcStr(P As tyProc) As StringProcStr = AddSpace(P.pID) & AddSpace(P.pHide, 6) & AddSpace(P.pName, 20) & AddSpace(P.pPath)End FunctionPrivate Function AddSpace(ByVal nStr As String, Optional ByVal S As Long) As StringIf S < 1 Then S = 6S = S - LenB(StrConv(nStr, vbFromUnicode))If S < 1 Then S = 1AddSpace = nStr & String(S, " ")End FunctionPrivate Function CutStr(nStr As String, Fu As String, Optional GetRight As Boolean) As String'GetRight=T 从右到左查找Dim S As LongIf GetRight Then ' 从右到左查找S = InStrRev(nStr, Fu)If S > 0 Then CutStr = Mid(nStr, S + 1) Else CutStr = nStrElseS = InStr(nStr, Fu)If S > 0 Then CutStr = Left(nStr, S - 1) Else CutStr = nStrEnd IfEnd Function'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html查看文档来源:/100bd/item/fbd87c3004c6f5342e0f8140。
如何获取程序运行路径
imports patibility
'首要在任何声明之前运用该语句导入该类库
下面代码即是获取程序的装置目录了
/
path=VB6.GetPath()
是不是很简略呢?本来还有愈加简略的办法,下面看办法二
获取程序运转途径办法二:运用中的Application.StartupPath()办法
Application是一个类似与vb6.0中app的保存关键词,能够用它来完成很多与控制台有关的操作,如今咱们就能够用它来获取到程序运转的途径,请看下面代码:
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
MsgBox(Application.StartupPath())
End Sub
以上是在VB6.0中的操作,升级到之后,中取消了对保存关键词app的支撑,那咱们要取得程序装置目录又该怎么办呢?不必着急,咱们在中有两种获取程序运转途径的办法。
获取程序运转途径办法一:运用向下兼容的类库patibility
了解VB6.0版别的兄弟必定知道,在自己编写的程序中,用app.path就能够很方便地完成获取程序运转途径,如下代码:
Private Sub Command1_Click()
MsgBox App.Path
End Sub
【深圳.NET培训】
获取程序运转的途径
假如要在查找程序目录的上一级目录中的文件,能够这么查找 dir(app.path & "\..\文件名称”,弹出增加引证的对话框,如下图所示,双击挑选Microsoft Visual Basic .NET Compatibility Runtime,然后确认即可。
VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径
VB代码VB小程序:通过枚举进程显示所有进程、隐藏进程、进程路径本小程序采用枚举进程的方法,显示所有进程,也能显示隐藏进程。
同时,能显示进程的完整路径。
有意思的是,一些已经结束的进程,同样可以显示。
以下是程序运行截图:''''以下是 VB6 代码,在 WinXP 调试通过'需在窗体放置以下 5 个控件,不必设置任何属性,全部采用默认设置:' Command1、List1、Check1、Timer1、Label1'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.htmlPrivate Type tyProcpID As Long: pName As String: pPath As String: pHide As StringEnd TypeDim ctP() As tyProc, ctPs As LongPrivate Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As LongPrivate Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef lpcbNeeded As Long) As LongPrivate Declare Function GetModuleFileNameEx Lib "psapi.dll" Alias"GetModuleFileNameExA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As LongPrivate Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As LongPrivate Declare Function GetProcessImageFileName Lib "psapi.dll" Alias"GetProcessImageFileNameA" (ByVal hProcess As Long, ByVal lpImageFileName As String, ByVal nSize As Long) As LongPrivate Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Const PROCESS_QUERY_INFORMATION = &H400Private Const PROCESS_VM_READ = &H10Private Const PROCESS_CREATE_PROCESS = &H80Private Const PROCESS_CREATE_THREAD = &H2Private Const PROCESS_DUP_HANDLE = &H40'Private Const PROCESS_QUERY_INFORMATION = &H400Private Const PROCESS_QUERY_LIMITED_INFORMATION = &H1000Private Const PROCESS_SET_QUOTA = &H100Private Const PROCESS_SET_INFORMATION = &H200Private Const PROCESS_SUSPEND_RESUME = &H800Private Const PROCESS_TERMINATE = &H1Private Const PROCESS_VM_OPERATION = &H8'Private Const PROCESS_VM_READ = &H10Private Const PROCESS_VM_WRITE = &H20'以下是在 NT 系统中提升当前进程权限的代码================================'系统级权限,可以:PROCESS_ALL_ACCESS OpenProcessToken、LookupPrivilegevalue、AdjustTokenPrivilegesPrivate Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As LongPrivate Declare Function GetCurrentProcess Lib "kernel32" () As LongPrivate Declare Function LookupPrivilegeValue Lib "advapi32" Alias"LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As LongPrivate Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, NewState As TOKEN_Privileges, ByVal BufferLength As Long, PreviousState As TOKEN_Privileges, ReturnLength As Long) As LongPrivate Type LUIDUsedPart As LongIgnoredForNowHigh32BitPart As LongEnd TypePrivate Type TOKEN_PrivilegesPrivilegeCount As LongTheLuid As LUIDAttributes As LongEnd TypePublic Sub AdjustPrivilege()'NT系统:提升权限Dim dl As Long, CurP As Long, nToKen As Long, nLuid As LUIDDim OldTKP As TOKEN_Privileges, NewTKP As TOKEN_PrivilegesDim pName As StringConst TOKEN_Adjust_Privileges = &H20Const TOKEN_Query = &H8Const SE_Privilege_Enabled_BY_DEFAULT = &H1 '默认权限Const SE_Privilege_Enabled = &H2 '开启权限Const SE_Privilege_USED_FOR_ACCESS = &H80000000 '所有访问权限'获取当前进程的一个句柄CurP = GetCurrentProcess()'打开进程令牌:用 nToKen 获得进程访问令牌的句柄dl = OpenProcessToken(CurP, (TOKEN_Adjust_Privileges Or TOKEN_Query), nToKen)'用 nLuid 返回指定权限的 LUID 结构'权限名称:SeDebugPrivilege、SeShutdownPrivilege、SeRestorePrivilege、SeBackupPrivilege、SeUnsolicitedInputPrivilegepName = "SeDebugPrivilege"dl = LookupPrivilegeValue("", pName, nLuid)NewTKP.PrivilegeCount = 1NewTKP.TheLuid = nLuidNewTKP.Attributes = SE_Privilege_Enabled'调整令牌权限dl = AdjustTokenPrivileges(nToKen, False, NewTKP, Len(NewTKP), OldTKP, 0&) End Sub'===================Private Sub Form_Load() = "宋体": Me.Caption = "枚举进程"Command1.Caption = "刷新" = Call AdjustPrivilege '提升本进程权限Timer1.Interval = 10Check1.Caption = "自动刷新": Check1.Value = 1End SubPrivate Sub Check1_Click()Timer1.Enabled = Check1.Value = 1End SubPrivate Sub Timer1_Timer()Static S As Long, S1 As LongDim nTai As StringS1 = S1 + 1If S1 > 2 ThenS1 = 0nTai = "↖↑↗→↘↓↙←"S = S + 1If S > 8 Then S = 1Label1.Caption = Mid(nTai, S, 1) '动画显示End IfCall ShowProcEnd SubPrivate Sub Command1_Click()List1.Clear: List1.RefreshCall ShowProcEnd SubPrivate Sub Form_Resize()Dim H1 As Single, T As SingleOn Error Resume NextH1 = Me.TextHeight("A")Command1.Move H1, H1, H1 * 4, H1 * 2Label1.Move H1 * 6, H1 * 1.5, H1, H1Check1.Move H1 * 8, H1, H1 * 8, H1 * 2T = Command1.Top + Command1.Height + H1 * 0.5List1.Move 0, T, Me.ScaleWidth, Me.ScaleHeight - TEnd Sub'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html Private Sub ShowProc()Dim pID(1023) As Long, Ps As Long, dwDesiredAccess As LongDim cbNeeded As Long, P As Long, hModule As LongDim hProcess As Long, nStr As String, I As LongDim IsChange As Boolean, P2() As tyProc, Ps2 As LongOn Error Resume NextdwDesiredAccess = PROCESS_QUERY_INFORMATION Or PROCESS_VM_READPs2 = ctPs: P2 = ctPctPs = 1: ReDim ctP(0 To 1)ctP(1).pName = "[System Process]"nStr = String(1024, 0)' 进程ID的数组,数组的大小,返回实际进程数组的大小If EnumProcesses(pID(0), 4& * 1024, cbNeeded) <> 0 ThenPs = cbNeeded \ 4 '进程总数For P = 0 To &HFFFF& Step 4hProcess = OpenProcess(dwDesiredAccess, 0, P) '返回指定进程的句柄If hProcess <> 0 ThenctPs = ctPs + 1: ReDim Preserve ctP(0 To ctPs)ctP(ctPs).pHide = "隐藏"For I = 0 To Ps - 1If P = pID(I) Then ctP(ctPs).pHide = "": Exit ForNext I'nStr 返回主模块全名:每个进程的第一模块即为进程主模块If EnumProcessModules(hProcess, hModule, 4&, 0&) <> 0 Then GetModuleFileNameEx hProcess, hModule, nStr, 1024Else '型如:\Device\HarddiskVolumeGetProcessImageFileName hProcess, nStr, 1024End IfCloseHandle hProcess '关闭进程的句柄With ctP(ctPs).pID = P '进程 ID.pPath = CutStr(nStr, vbNullChar) '进程路径If Left(.pPath, 4) = "\??\" Then .pPath = Mid(.pPath, 5) '去掉“\??\”.pName = CutStr(.pPath, "\", True) '进程名If P = 4 And .pName = "" Then .pName = "System"End WithEnd IfNextEnd If'List1.ClearFor P = 1 To ctPsnStr = AddSpace(P, 4) & ProcStr(ctP(P)) '合成显示条目If P > List1.ListCount ThenList1.AddItem nStr' List1.ListIndex = List1.NewIndexElseIf nStr <> List1.List(P - 1) Then List1.List(P - 1) = nStrEnd IfNext'删除多余条目For P = List1.ListCount - 1 To ctPs Step -1List1.RemoveItem PNextEnd SubPrivate Function ProcStr(P As tyProc) As StringProcStr = AddSpace(P.pID) & AddSpace(P.pHide, 6) & AddSpace(P.pName, 20) & AddSpace(P.pPath)End FunctionPrivate Function AddSpace(ByVal nStr As String, Optional ByVal S As Long) As StringIf S < 1 Then S = 6S = S - LenB(StrConv(nStr, vbFromUnicode))If S < 1 Then S = 1AddSpace = nStr & String(S, " ")End FunctionPrivate Function CutStr(nStr As String, Fu As String, Optional GetRight As Boolean) As String'GetRight=T 从右到左查找Dim S As LongIf GetRight Then ' 从右到左查找S = InStrRev(nStr, Fu)If S > 0 Then CutStr = Mid(nStr, S + 1) Else CutStr = nStrElseS = InStr(nStr, Fu)If S > 0 Then CutStr = Left(nStr, S - 1) Else CutStr = nStrEnd IfEnd Function'本人原创,转载请注明来源:/100bd/blog/item/c4199fedda35ba0763d09f6b.html查看文档来源:/100bd/item/fbd87c3004c6f5342e0f8140。
getwindowthreadprocessid vb用法
getwindowthreadprocessid vb用法**一、概述**getwindowthreadprocessid是一个常见的Windows API函数,用于获取指定窗口的线程进程ID。
在VB(Visual Basic)中,我们可以使用这个函数来获取与特定窗口关联的进程信息。
**二、函数语法**```vbDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As Boolean```其中,`hwnd`参数是你想要获取其进程ID的窗口的句柄,`lpdwProcessId`是一个变量,用于存储进程ID。
函数返回一个布尔值,表示操作是否成功。
**三、使用示例**以下是一个简单的VB代码示例,展示了如何使用getwindowthreadprocessid函数:```vbDeclare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As BooleanSub Main()Dim hwnd As IntPtr = FindWindow(0&, "窗口标题") ' 替换为你的窗口标题If hwnd <> 0 ThenDim processId As IntPtr = IntPtr.ZeroIf GetWindowThreadProcessId(hwnd, processId) Then Console.WriteLine("窗口关联的进程ID为:" & processId)ElseConsole.WriteLine("无法获取窗口的进程ID")End IfElseConsole.WriteLine("未找到指定的窗口")End IfEnd Sub```这段代码首先使用FindWindow函数找到指定窗口的句柄,然后调用GetWindowThreadProcessId函数获取进程ID,并将其输出到控制台。
VBA编程中的文件路径操作技巧与实践经验
VBA编程中的文件路径操作技巧与实践经验VBA(Visual Basic for Applications)是一种用于Office应用程序的编程语言,它可以让用户自定义功能和自动化任务。
在VBA编程中,文件路径操作是非常重要且常见的任务之一。
本文将介绍一些VBA编程中的文件路径操作技巧和实践经验,帮助读者更有效地处理文件路径。
1. 获取当前工作路径在VBA编程中,获取当前工作路径是很有用的操作。
可以使用VBA的`CurDir`函数来获取当前工作路径。
该函数返回一个字符串,表示当前工作路径。
```vbaDim currentPath As StringcurrentPath = CurDir```2. 获取文件路径有时候我们需要获取一个文件的路径,可以使用`Application.GetOpenFilename`或`Application.GetSaveAsFilename`函数获取文件路径。
`GetOpenFilename`函数将打开文件对话框,用户可以选择一个文件并返回其路径。
`GetSaveAsFilename`函数将打开保存文件对话框,用户可以指定文件名和路径并返回路径。
Dim filePath As StringfilePath = Application.GetOpenFilename```3. 拼接路径在VBA编程中,拼接路径是常见的操作。
可以使用`&`操作符将两个字符串拼接起来,构成新的路径。
```vbaDim folderPath As StringDim fileName As StringDim fullPath As StringfolderPath = "C:\Path\to\Folder\"fileName = "file.txt"fullPath = folderPath & fileName```4. 判断路径是否存在在VBA编程中,有时候需要判断一个文件或文件夹是否存在。
VBA中文件路径处理与管理的函数与技巧
VBA中文件路径处理与管理的函数与技巧VBA(Visual Basic for Applications)是一种用于Microsoft Office应用程序的宏编程语言,可以用于自动化处理文档、数据和其他任务。
在VBA中,文件路径的处理与管理是非常常见的需求,可以通过一些函数和技巧来实现。
###获取文件路径信息####1.获取当前工作目录路径使用 `CurDir(` 函数可以获取当前工作目录的路径,例如:```vbaDim currentPath As StringcurrentPath = CurDirMsgBox currentPath```####2.获取文件的完整路径使用 `FullName` 属性可以获取文件的完整路径,例如:```vbaDim filePath As StringfilePath = ThisWorkbook.FullNameMsgBox filePath####3.提取文件路径和文件名使用 `Dir(` 函数可以提取文件路径和文件名,例如:```vbaDim folderPath As StringDim fileName As StringfolderPath = Left(ThisWorkbook.FullName, InStrRev(ThisWorkbook.FullName, "\"))fileName = Dir(ThisWorkbook.FullName)MsgBox folderPath & vbCrLf & fileName```###判断文件路径和文件是否存在####1.判断文件路径是否存在使用 `Dir(` 函数可以判断文件路径是否存在,例如:```vbaDim folderPath As StringfolderPath = "C:\Test"If Dir(folderPath, vbDirectory) <> "" ThenMsgBox folderPath & " exists"MsgBox folderPath & " does not exist"End If```####2.判断文件是否存在使用 `Dir(` 函数可以判断文件是否存在,例如:```vbaDim filePath As StringfilePath = "C:\Test\Test.txt"If Dir(filePath) <> "" ThenMsgBox filePath & " exists"ElseMsgBox filePath & " does not exist"End If```###创建、删除和重命名文件夹####1.创建文件夹使用 `MkDir` 函数可以创建文件夹,例如:```vbaDim folderPath As StringfolderPath = "C:\Test"MkDir folderPathMsgBox folderPath & " created"```####2.删除文件夹使用 `RmDir` 函数可以删除文件夹,例如:```vbaDim folderPath As StringfolderPath = "C:\Test"RmDir folderPathMsgBox folderPath & " deleted"```####3.重命名文件夹使用 `Name` 函数可以重命名文件夹,例如:```vbaDim oldFolderPath As StringDim newFolderPath As String oldFolderPath = "C:\Test"newFolderPath = "C:\NewTest"Name oldFolderPath As newFolderPathMsgBox oldFolderPath & " renamed as " & newFolderPath ```###创建、删除和移动文件####1.创建文件使用 `FileCopy` 函数可以创建文件,例如:```vbaDim sourceFilePath As StringDim destFilePath As StringsourceFilePath = "C:\Test\Test.txt"destFilePath = "C:\NewTest\Test.txt"FileCopy sourceFilePath, destFilePathMsgBox destFilePath & " created"```####2.删除文件使用 `Kill` 函数可以删除文件,例如:```vbaDim filePath As StringfilePath = "C:\NewTest\Test.txt"Kill filePathMsgBox filePath & " deleted"```####3.移动文件使用 `Name` 函数可以移动文件,例如:```vbaDim sourceFilePath As StringDim destFilePath As StringsourceFilePath = "C:\NewTest\Test.txt"destFilePath = "C:\Test\Test.txt"Name sourceFilePath As destFilePathMsgBox sourceFilePath & " moved to " & destFilePath```###处理特殊字符和路径分隔符####1.处理路径分隔符使用 `Application.PathSeparator` 属性可以获取路径分隔符,例如:```vbaDim pathSeparator As StringpathSeparator = Application.PathSeparatorMsgBox "Path separator is " & pathSeparator```####2.处理特殊字符使用 `Replace(` 函数可以替换特殊字符,例如:```vbaDim filePath As StringDim fixedPath As StringfilePath = "C:\Test\Test*File.txt"fixedPath = Replace(filePath, "*", "")MsgBox "Original path: " & filePath & vbCrLf & "Fixed path: " & fixedPath```###获取特定文件夹下的所有文件####1.获取文件夹下的所有文件使用 `Dir(` 函数可以获取文件夹下的所有文件,例如:```vbaDim folderPath As StringDim fileName As StringfolderPath = "C:\Test"fileName = Dir(folderPath & "\*.*")Do While fileName <> ""MsgBox fileNamefileName = DirLoop```###批量处理文件####1.批量读取文件内容使用 `Open` 和 `Close` 函数可以批量读取文件内容,例如:```vbaDim filePath As StringDim fileContent As StringfilePath = "C:\Test\Test.txt"Open filePath For Input AsDo While Not EOF(1)Line Input , fileContentMsgBox fileContentLoopClose```####2.批量写入文件内容使用 `Open` 和 `Close` 函数可以批量写入文件内容,例如:```vbaDim filePath As StringDim fileContent As StringfilePath = "C:\Test\Test.txt"fileContent = "Hello, World!"Open filePath For Output AsPrint , fileContentClose```。
vb 获取路径
vb 获取路径在VB编程中,获取路径是一项基本操作。
本文将介绍两种在VB中获取路径的方法,并比较它们的特点和适用场景。
一、使用内置函数获取路径在VB中,可以使用内置的函数来获取路径。
其中,最为常用的函数是“Mid”和“Left”。
1.Mid函数Mid函数的作用是从一个字符串的中间截取一部分字符。
其语法格式为:Mid(string, start, length)。
其中,string表示原字符串,start表示开始位置,length表示截取长度。
例如,我们有一个字符串“C:UsersUsernameDocumentsexample.txt”,想要获取“Users”和“example.txt”之间的部分,可以使用以下代码:```vbDim path As Stringpath = Mid(MyPath, 7, 22)```2.Left函数Left函数的作用是从一个字符串的左边截取一部分字符。
其语法格式为:Left(string, length)。
其中,string表示原字符串,length表示截取长度。
使用Left函数获取上述路径中的“Users”和“example.txt”之间的部分,代码如下:```vbDim path As Stringpath = Left(MyPath, 22)```二、使用字符串操作获取路径除了使用内置函数,我们还可以通过字符串操作来获取路径。
1.字符串连接在VB中,可以使用“&”运算符将多个字符串连接在一起。
例如,获取上述路径中的“Users”和“example.txt”之间的部分,可以使用以下代码:```vbDim path As Stringpath = MyPath & "Users" & "example.txt"```2.字符串截取可以使用Left、Mid等函数对字符串进行截取。
例如,获取上述路径中的“Users”和“example.txt”之间的部分,可以使用以下代码:```vbDim path As Stringpath = Left(MyPath, 7) & "Users" & Left(Right(MyPath, 29), 24)```三、总结在VB中,获取路径的方法多种多样。
vb 调用路径 -回复
vb 调用路径-回复VB调用路径VB(Visual Basic)是一种基于事件驱动的编程语言。
它广泛应用于Windows操作系统上的应用程序开发中。
在VB中,调用路径指的是通过不同的方式来调用代码或程序的路径。
了解VB调用路径对于开发者来说非常重要,因为它有助于优化代码的结构和性能。
在本文中,我们将逐步回答有关VB调用路径的问题,帮助读者更好地理解和利用VB的编程特性。
首先,我们需要明确VB的调用路径是什么。
在VB中,调用路径可以通过两种方式来实现:过程调用和事件调用。
过程调用是指在代码中主动调用另一个过程或函数,而事件调用是指在特定事件被触发时自动调用相应的事件处理程序。
这两种调用方式在VB程序中经常被使用。
接下来,让我们来看一下如何进行过程调用。
过程调用是一种直接调用另一个过程或函数的方式。
在VB中,我们可以使用Sub和Function关键字定义过程或函数,然后在需要的地方通过调用它们来实现代码的复用。
例如,我们可以定义一个名为"CalculateSum"的函数来计算两个数的和:Function CalculateSum(num1 As Integer, num2 As Integer) AsIntegerDim sum As Integersum = num1 + num2Return sumEnd Function然后,我们可以在代码的其他部分通过调用这个函数来获取结果:Dim result As Integerresult = CalculateSum(10, 20)这样就实现了一个典型的过程调用。
除了过程调用,事件调用也是VB中非常重要的一部分。
事件调用允许我们在特定事件被触发时自动执行相应的代码。
在VB中,我们可以通过定义事件处理程序来实现对事件的响应。
例如,当用户单击一个按钮时,我们可以通过定义Button_Click事件处理程序来实现相应的操作。
事件处理程序的定义方式如下:Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button1.Click'执行相应的代码End Sub在这个例子中,当Button1按钮被单击时,Button_Click事件处理程序会被自动调用,并执行我们定义的代码。
四、VBA获取目录、文件路径简明代码(VB语句、FSO两种方式)
四、VBA获取目录、文件路径简明代码(VB语句、FSO两种方式)(一)VB语句方式''''程序入口↓''''获取所有文件路径Sub GetFileList()Call GetFolderList ''''调用GetFolderList()过程获取所有文件夹路径Columns(2).ClearDim fileName, folderPath As StringDim rowIndexA, rowIndexB, maxRow, lastRowA As Integer maxRow = Rows.CountlastRowA = Cells(maxRow,1).End(xlUp).RowFor rowIndexA =1To lastRowAfolderPath = Cells(rowIndexA,1).ValuefileName = Dir(folderPath)rowIndexB = Cells(maxRow,2).End(xlUp).Row +1Do While fileName <>""Cells(rowIndexB,2).Value = folderPath & fileNamerowIndexB = rowIndexB +1fileName = DirLoopNext rowIndexAEnd Sub''''获取GetMainDirectory拾取文件夹路径下的所有文件夹,放到A列Sub GetFolderList()Dim folderName As StringDim i, k As IntegerColumns(1).ClearCells(1,1).Value = GetMainDirectory(msoFileDialogFolderPicker)&"\"i =1k =1Do While i <= kfolderName = Dir(Cells(i,1).Value, vbDirectory)DoIf InStr(folderName,".")=0And _(GetAttr(Cells(i,1).Value & folderName)And vbDirectory)= vbDirectory Thenk = k +1Cells(k,1).Value = Cells(i,1).Value & folderName &"\"End IffolderName = DirLoop Until folderName =""i = i +1LoopEnd Sub''''函数,拾取一个文件夹路径,返回路径字符串Function GetMainDirectory(ByVal DialogType As MsoFileDialogType)As StringWith Application.FileDialog(DialogType)If.Show =True ThenGetMainDirectory =.SelectedItems(1)End IfEnd WithEnd Function(二)FSO方式''''##############################''''工具——引用类库文件"Microsoft Scripting Runtime"''''##############################''''程序入口↓''''获取文件列表Sub FsoGetFileList()Dim folderPath As StringDim maxRow, lastRow, maxRowB, LastRowB As IntegerDim i As IntegerDim folder, allFiles As ObjectDim fso As New FileSystemObjectCall FsoGetFolderList ''''调用FsoGetFolderList方法获取目录列表Columns(2).ClearmaxRow = Rows.CountlastRow = Cells(maxRow,1).End(xlUp).RowFor i =1To lastRowfolderPath = Cells(i,1).ValueSet folder = fso.GetFolder(folderPath)Set allFiles = folder.FilesmaxRowB = Rows.CountLastRowB = Cells(maxRowB,2).End(xlUp).Row +1For Each File In allFilesCells(LastRowB,2).Value = File.PathLastRowB = LastRowB +1NextNext iEnd Sub''''获取文件夹列表Sub FsoGetFolderList()Dim rowIndex As IntegerDim folderPath As String''''调用函数获取主文件夹目录folderPath = GetMainDirectory(msoFileDialogFolderPicker) rowIndex =1Columns(1).ClearDoIf rowIndex =1ThenGetFolderPath (folderPath)Cells(rowIndex,1).Value = folderPathElseGetFolderPath (Cells(rowIndex,1).Value)End IfrowIndex = rowIndex +1Loop Until Cells(rowIndex,1).Value =""End Sub''''定义函数,作用是获取给定文件夹路径(mainFolderPath)的子文件夹Function GetFolderPath(mainFolderPath)Dim mainFolder, childFolders As ObjectDim index As Integer''''创建FileSystemObject对象fsoDim fso As New FileSystemObject''''从路径获得folder对象mainFolderSet mainFolder = fso.GetFolder(mainFolderPath)''''获得mainFolder的子目录集合childFoldersSet childFolders = mainFolder.SubFolders''''行号初始值设定为A列最后一个非空行的+1行,第一次执行的时候index=2index = Cells(Rows.Count,1).End(xlUp).Row +1''''for each ……in 遍历集合取每一个子目录childFolder的路径pathFor Each childfolder In childFoldersCells(index,1).Value = childfolder.Path ''''路径index = index +1NextEnd Function''''函数,拾取一个文件夹路径,返回路径字符串Function GetMainDirectory(ByVal DialogType As MsoFileDialogType)As StringWith Application.FileDialog(DialogType)If.Show =True ThenGetMainDirectory =.SelectedItems(1)End IfEnd WithEnd Function。
VB获取系统各类文件夹路径
VB获取系统各类文件夹路径Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As LongPrivate Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As LongPrivate Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As LongConst MAX_LEN = 200 '字符串最大长度Const DESKTOP = &H0& '桌面Const PROGRAMS = &H2& '程序集Const MYDOCUMENTS = &H5& '我的文档Const MYFAVORITES = &H6& '收藏夹Const STARTUP = &H7& '启动Const RECENT = &H8& '最近打开的文件Const SENDTO = &H9& '发送Const STARTMENU = &HB& '开始菜单Const NETHOOD = &H13& '网上邻居Const FONTS = &H14& '字体Const SHELLNEW = &H15& 'ShellNewConst APPDATA = &H1A& 'Application DataConst PRINTHOOD = &H1B& 'PrintHoodConst PAGETMP = &H20& '网页临时文件Const COOKIES = &H21& 'Cookies目录Const HISTORY = &H22& '历史Private Sub Form_Load()Dim sTmp As String * MAX_LEN '存放结果的固定长度的字符串Dim nLength As Long '字符串的实际长度Dim pidl As Long '某特殊目录在特殊目录列表中的位置'*************************获得Windows目录**********************************Length = GetWindowsDirectory(sTmp, MAX_LEN)txtWin.Text = Left(sTmp, Length)'*************************获得System目录***********************************Length = GetSystemDirectory(sTmp, MAX_LEN)txtSystem.T ext = Left(sTmp, Length)'*************************获得Temp目录***********************************Length = GetTempPath(MAX_LEN, sTmp)txtTemp.Text = Left(sTmp, Length)'*************************获得DeskT op目录**********************************SHGetSpecialFolderLocation 0, DESKTOP, pidlSHGetPathFromIDList pidl, sTmptxtDesktop.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得发送到目录**********************************SHGetSpecialFolderLocation 0, SENDTO, pidlSHGetPathFromIDList pidl, sTmptxtSendT o.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得我的文档目录*********************************SHGetSpecialFolderLocation 0, MYDOCUMENTS, pidlSHGetPathFromIDList pidl, sTmptxtDocument.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得程序集目录***********************************SHGetSpecialFolderLocation 0, PROGRAMS, pidlSHGetPathFromIDList pidl, sTmptxtProgram.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得启动目录*************************************SHGetSpecialFolderLocation 0, STARTUP, pidlSHGetPathFromIDList pidl, sTmptxtStart.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得开始菜单目录*********************************SHGetSpecialFolderLocation 0, STARTMENU, pidlSHGetPathFromIDList pidl, sTmptxtStartMenu.T ext = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得收藏夹目录***********************************SHGetSpecialFolderLocation 0, MYFAVORITES, pidlSHGetPathFromIDList pidl, sTmptxtFavorites.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'**********************获得最后打开的文件目录*******************************SHGetSpecialFolderLocation 0, RECENT, pidlSHGetPathFromIDList pidl, sTmptxtRecent.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得网上邻居目录*********************************SHGetSpecialFolderLocation 0, NETHOOD, pidlSHGetPathFromIDList pidl, sTmptxtNetHood.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得字体目录**********************************SHGetSpecialFolderLocation 0, FONTS, pidlSHGetPathFromIDList pidl, sTmptxtFonts.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得Cookies目录**********************************SHGetSpecialFolderLocation 0, COOKIES, pidlSHGetPathFromIDList pidl, sTmptxtCookies.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得历史目录**********************************SHGetSpecialFolderLocation 0, HISTORY, pidlSHGetPathFromIDList pidl, sTmptxtHistory.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'***********************获得网页临时文件目录*******************************SHGetSpecialFolderLocation 0, PAGETMP, pidlSHGetPathFromIDList pidl, sTmptxtPageTmp.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得ShellNew目录*********************************SHGetSpecialFolderLocation 0, SHELLNEW, pidlSHGetPathFromIDList pidl, sTmptxtShellNew.T ext = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'***********************获得Application Data目录*****************************SHGetSpecialFolderLocation 0, APPDATA, pidlSHGetPathFromIDList pidl, sTmptxtAppData.Text = Left(sTmp, InStr(sTmp, Chr(0)) - 1)'*************************获得PrintHood目录*********************************SHGetSpecialFolderLocation 0, PRINTHOOD, pidlSHGetPathFromIDList pidl, sTmptxtPrintHood.T ext = Left(sTmp, InStr(sTmp, Chr(0)) - 1)End Sub。
VB.NET获取MAC地址
方法一:nbtstat 命令Public Function GetMac(ByVal IP As String) As StringTry'定义输出变量。
Dim StrMac As String = String.EmptyDim Str As String = String.Empty'定义进程参数。
Dim Info As New ProcessStartInfoInfo.FileName = ";nbtstat";Info.Arguments = ";-a "; + IPeShellExecute = FalseInfo.RedirectStandardInput = FalseInfo.RedirectStandardOutput = TrueInfo.RedirectStandardError = TrueInfo.CreateNoWindow = TrueInfo.WindowStyle = ProcessWindowStyle.Hidden'定义新进程。
Dim mProcess As New Process'开始执行操作。
mProcess = Process.Start(Info)'无限循环按行读取输出内容。
While True'读取一行数据。
Str = mProcess.StandardOutput.ReadLine()mProcess.WaitForExit()StrMac = Str.Trim()'判断是否有 Mac Address字眼。
If StrMac.ToLower.Contains(";mac address";) ThenExit WhileElseIf StrMac.ToLower.Contains(";host not found";) ThenExit WhileEnd IfEnd IfEnd While'返回值。
VB6读写内存的方法和技巧
VB读写内存一些背景知识不象C语音,VB不会自动包括普通的API函数的声明,因此我们必须把他们加入我们的项目文件。
在几乎所有的修改器中会使用到6个主要的函数,讨论如下:1. FindWindow(ClassName, WindowTitle) - FindWindow 返回符合指定的类名( ClassName)和窗口名( WindowTitle )的窗口句柄。
对我们来说,可以让ClassName 为空( Null ),只给出游戏的WindowTitle。
函数应该这样声明:Declare Function FindWindow Lib "user32" Alias"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String)As Long2. GetWindowThreadProcessId(WindowHandle, ProcessId) - 在这里我们把FindWindow函数中得到的句柄作为参数,来获得进程标识符(ProcessId )。
声明如下:Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessIdAs Long) As Long3. OpenProcess(DesiredAccess, Inherit, ProcessId) -这个函数将返回一个我们目标进程的句柄,可以用来对目标进行读写操作。
DesiredAccess参数的值决定了句柄对进程的存取权利,对我们来说,要使用PROCESS_ALL_ACCESS (完全存取权限)。
Inherit 应该总是False。
ProcessId 是从GetWindowThreadProcessId 函数中取得的。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Dim lngNumElements As Long
Dim lngProcessIDs() As Long
Public Const PROCESS_QUERY_INFORMATION = 1024
Public Const PROCESS_VM_READ = 16
Public Const MAX_PATH = 260
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
dwFlags As Long
szExeFile As String * 260 ' MAX_PATH
End Type
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
Dim booResult As Boolean
Dim lngLength As Long
Dim lngProcessID As Long
Dim strProcessName As String
cntThreads As Long
th32ParentProcessID As Long ' This process's parent process
pcPriClassBase As Long ' Base priority of process threads
PagefileUsage As Long
PeakPagefileUsage As Long
End Type
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
Public Const SYNCHRONIZE = &H100000
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Const TH32CS_SNAPPROCESS = &H2&
Public Const hNull = 0
Public Const WIN95_System_Found = 1
Dim lngSize As Long
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
QuotaPeakPagedPoolUsage As Long
QuotaPagedPoolUsage As Long
QuotaPeakNonPagedPoolUsage As Long
QuotaNonPagedPoolUsage As Long
Public Declare Function EnumProcesses Lib "PSAPI.DLL" (ByRef lpidProcess As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Public Declare Function GetModuleFileNameExA Lib "PSAPI.DLL" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Declare Sub GlobalMemoryStatus Lib "kernel32" (lpBuffer As MEMORYSTATUS)
'enumerate all the different explorer.exe processes
GetProcesses "project1.exe"
End Sub
Public Function GetProcesses(ByVal EXEName As String)
' the Replace function (on the end of the code)
'In a form
Private Sub Form_Load()
'Code submitted by Roger Taylor
Public Declare Function GetProcessMemoryInfo Lib "PSAPI.DLL" (ByVal hProcess As Long, ppsmemCounters As PROCESS_MEMORY_COUNTERS, ByVal cb As Long) As Long
End Type
Type PROCESS_MEMORY_COUNTERS
cb As Long
PageFaultCount As Long
PeakWorkingSetSize As Long
WorkingSetSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long '1 = Windows 95.
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
th32ProcessID As Long ' This process
th32DefaultHeapID As Long
th32ModuleID As Long ' Associated exe
Public Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
Public Declare Function CloseHandle Lib "Kernel32.dll" (ByVal Handle As Long) As Long
Public Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Public Const WINNT_System_Found = 2
Public Const Default_Log_Size = 10000000
Public Const Default_Log_Days = 0
Public Const SPECIFIC_RIGHTS_ALL = &HFFFF
Dim lngCBSize2 As Long
Dim lngModules(1 To 200) As Long
Dim lngReturn As Long
Dim strModuleName As String
'2 = Windows NT
szCSDVersion As String * 128