VB中取各种系统路径名,格式化磁盘,建立快捷方式,鼠标的定位,移动

VB.NET 取磁盘容量信息 在本文中通过,“GetDiskFreeSpaceEx / 取磁盘空闲空间EX”获取到关于磁盘的容量信息 如“磁盘总容量”、“磁盘空闲容量”、“磁盘已用容量”、“调用方可用容量”,有必要著名下 “调用方可用容量”与“磁盘空闲容量”两者近乎相同,但不代表完全相同 两者只是说反馈的 值相近或相同,不代表一定说含义完全等价、 函数示意: GetDiskFreeSpaceEx 取磁盘空闲空间扩 阅读详情
 
  1. Option Explicit
  2. '
  3. '系统操作(SmSysCls)
  4. '
  5. Const SW_SHOW = 5
  6. Public Type SmPointAPI
  7.         X As Long
  8.         Y As Long
  9. End Type
  10. Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
  11. Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
  12. Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
  13. Private Declare Function GetCursorPos Lib "user32" (lpPoint As SmPointAPI) As Long
  14. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  15. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
  16. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
  17. '/----------------------------------------------------------------
  18. Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
  19. Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal Pidl As Long, ByVal szPath As String) As Long
  20. '/---------------------------------------------------------------
  21. '/非常危险,小心使用。
  22. Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
  23.         "GetSystemDirectoryA" (ByVal lpBuffer As String, _
  24.         ByVal nSize As Long) As Long
  25. Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
  26. Private Declare Function ShellExecute Lib "shell32.dll" Alias _
  27.         "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation _
  28.         As String, ByVal lpFile As String, ByVal lpParameters _
  29.         As String, ByVal lpDirectory As String, ByVal nShowCmd _
  30.         As Long) As Long
  31. '/-------------------------------------------------------------
  32. Private Const HKEY_CLASSES_ROOT = 
  33. Private Const HKEY_CURRENT_USER = 
  34. Private Const HKEY_LOCAL_MACHINE = 
  35. Private Const HKEY_USERS = 
  36. Private Const HKEY_PERFORMANCE_DATA = 
  37. Private Const HKEY_CURRENT_CONFIG = 
  38. Private Const HKEY_DYN_DATA = 
  39. Private Const REG_NONE = 0
  40. Private Const REG_SZ = 1
  41. Private Const REG_EXPAND_SZ = 2
  42. Private Const REG_BINARY = 3
  43. Private Const REG_DWORD = 4
  44. Private Const REG_DWORD_BIG_ENDIAN = 5
  45. Private Const REG_MULTI_SZ = 7
  46. '
  47. '取计算机名
  48. '函数:Get_ComputerName
  49. '参数:无
  50. '返回值:String,计算机名称
  51. '例子:
  52. Public Function Get_ComputerName() As String
  53.     Dim strString As String
  54.     strString = String(255, Chr$(0))
  55.     GetComputerName strString, 255
  56.     strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1)
  57.     Get_ComputerName = strString
  58. End Function
  59. '
  60. '格式化磁盘(危险)
  61. '函数:FormatDisk
  62. '参数:DiskName 磁盘名称,WinHwnd调用本函数的窗口句柄.
  63. '返回值:无
  64. '说明:
  65. Public Function FormatDisk(DiskName As String, Optional WinHwnd As Long = 0)
  66.     Dim sFor As String
  67.     Dim sTemp As String
  68.     
  69.     sFor = String(255, " ")
  70.     GetWindowsDirectory sFor, 255
  71.     sTemp = Left$(sFor, InStr(sFor, Chr$(0)) - 1) + "/rundll32.exe" _
  72.             + Chr(0)
  73.     ShellExecute WinHwnd, vbNullString, sTemp, _
  74.             "Shell32.dll,SHFormatDrive" + Chr$(0), DiskName + Chr$(0), _
  75.              SW_SHOW
  76. End Function
  77. '/
  78. '/取WINDOWS路径
  79. '/函数:GetWinPath
  80. '/参数:
  81. '/返回值:WINDOWS目录路径.
  82. '/说明:
  83. Private Function GetWinPath() As String
  84.     Dim strFolder As String
  85.     Dim lngResult As Long
  86.     strFolder = String(255, Chr$(0))
  87.     lngResult = GetWindowsDirectory(strFolder, 255)
  88.     If lngResult <> 0 Then
  89.         GetWinPath = Left$(strFolder, InStr(strFolder, Chr$(0)) - 1)
  90.     Else
  91.         GetWinPath = ""
  92.     End If
  93. End Function
  94. '/
  95. '/取SYSTEM路径
  96. '/函数:GetSystemPath
  97. '/参数:
  98. '/返回值:SYSTEM目录路径.
  99. '/说明:
  100. Private Function GetSystemPath() As String
  101.     Dim strFolder As String
  102.     Dim lngResult As Long
  103.     strFolder = String(255, Chr$(0))
  104.     lngResult = GetSystemDirectory(strFolder, 255)
  105.     If lngResult <> 0 Then
  106.         GetSystemPath = Left$(strFolder, InStr(strFolder, Chr$(0)) - 1)
  107.     Else
  108.         GetSystemPath = ""
  109.     End If
  110. End Function
  111. '/
  112. '/取TEMP路径
  113. '/函数:GetTmpPath
  114. '/参数:
  115. '/返回值:系统临时目录路径.
  116. '/说明:
  117. Private Function GetTmpPath() As String
  118.     Dim strFolder As String
  119.     Dim lngResult As Long
  120.     strFolder = String(255, Chr$(0))
  121.     lngResult = GetTempPath(255, strFolder)
  122.     If lngResult <> 0 Then
  123.         GetTmpPath = Left$(strFolder, InStr(strFolder, Chr$(0)) - 1)
  124.     Else
  125.         GetTmpPath = ""
  126.     End If
  127. End Function
  128. '
  129. '取特殊文件夹.
  130. '函数:GetFolder
  131. '参数:FolderID SysFolder枚举变量.
  132. '返回值:所取文件路径.
  133. '例子:
  134. Public Function GetFolder(FolderID As SmSysFolder) As String
  135.     Dim Pidl As Long, s As String
  136.     Dim id As Long
  137.     Dim ReturnVal As String
  138.     id = FolderID
  139.     If id > &H15& Then
  140.        Select Case id
  141.               Case Is = &H16
  142.                    ReturnVal = GetWinPath
  143.               Case Is = &H17
  144.                    ReturnVal = GetSystemPath
  145.               Case Is = &H18
  146.                    ReturnVal = GetTmpPath
  147.               Case Else
  148.                    ReturnVal = ""
  149.        End Select
  150.     Else
  151.         s = String(255, Chr$(0))
  152.         If SHGetSpecialFolderLocation(0, id, Pidl) <> 0 Then
  153.            ReturnVal = ""
  154.            GoTo EndFun
  155.         End If
  156.         If SHGetPathFromIDList(Pidl, s) = 0 Then
  157.            ReturnVal = ""
  158.            GoTo EndFun
  159.         End If
  160.         ReturnVal = Left$(s, InStr(s, Chr$(0)) - 1)
  161.     End If
  162. EndFun:
  163.     GetFolder = ReturnVal
  164. End Function
  165. '
  166. '取当前WINDOWS用户名
  167. '函数:UserName
  168. '参数:
  169. '返回值:当前WINDOWS用户名.
  170. '例子:
  171. Public Function UserName() As String
  172.     Dim Cn As String
  173.     Dim Ls As Long
  174.     Dim res As Long
  175.     Cn = String$(255, Chr$(0))
  176.     Ls = 255
  177.     res = GetUserName(Cn, Ls)
  178.     If res <> 0 Then
  179.         UserName = Mid$(Cn, 1, InStr(Cn, Chr$(0)) - 1)
  180.     Else
  181.         UserName = ""
  182.     End If
  183. End Function
  184. '
  185. '建立文件快捷方式.
  186. '函数:CreateLink
  187. '参数:
  188. '       FileFullName       对应的文件全称.
  189. '       IconLocation       图标路径
  190. '       LinkFolder         快捷方式的系统位置(枚举).
  191. '       UserLinkFolder     用户自定义快捷方式位置.
  192. '       LinkName           快捷方式名称.
  193. '       WorkingDirectory   工作目录.
  194. '       Hotkey             热键.
  195. '       WindowStyle        运行方式(枚举).
  196. '返回值:无.
  197. '例子:
  198. '注:如果 UserLinkFolder 不为空.则 LinkFolder 无效,即:用户自定义位置优先.
  199. Public Function CreateLink(FileFullName As String, _
  200.                            Optional IconLocation As String = "", _
  201.                            Optional LinkFolder As SmSysFolder = SmDeskTop, _
  202.                            Optional UserLinkFolder As String = "", _
  203.                            Optional LinkName As String = "", _
  204.                            Optional WorkingDirectory As String = "", _
  205.                            Optional Hotkey As String = "", _
  206.                            Optional WindowStyle As SmWinStyle = SmNormalFocus)
  207.     Dim GetName As New SmFileCls
  208.     Dim WSH_shell As New IWshRuntimeLibrary.IWshShortcut_Class 'IWshRuntimeLibrary.WshShell
  209.     Dim UrlLink As New IWshRuntimeLibrary.IWshShortcut_Class 'IWshRuntimeLibrary.WshShortcut
  210.     Dim LinkPath As String
  211.     Dim CreateDir As New SmFileCls
  212.     On Error Resume Next
  213.     
  214.     If Len(Trim$(WorkingDirectory)) = 0 Then
  215.        WorkingDirectory = GetName.FilePath(FileFullName)
  216.     End If
  217.     If Len(Trim$(LinkName)) = 0 Then
  218.        LinkName = GetName.Filename(FileFullName)
  219.     End If
  220.     If UCase$(Right$(LinkName, 3)) <> "LNK" Then
  221.        LinkName = LinkName & ".LNK"
  222.     End If
  223.     '/-----------------------------------------
  224.     If Len(Trim$(UserLinkFolder)) > 0 Then
  225.        LinkPath = UserLinkFolder
  226.     ElseIf IsNumeric(LinkFolder) Then
  227.        LinkPath = GetFolder(LinkFolder)
  228.     Else
  229.        Exit Function
  230.     End If
  231.     '/------------------------------------------
  232.     If Right$(LinkPath, 1) <> "/" Then LinkPath = LinkPath & "/"
  233.     If Len(Dir$(LinkPath, vbDirectory + vbHidden + vbReadOnly + vbSystem + vbAlias + vbNormal)) = 0 Then
  234.        If Not CreateDir.CreateDir(LinkPath) Then
  235.           Exit Function
  236.        End If
  237.     End If
  238.     LinkPath = LinkPath & LinkName
  239.     Set UrlLink = WSH_shell.CreateShortcut(LinkPath)
  240.     With UrlLink
  241.          .TargetPath = FileFullName
  242.          .IconLocation = IconLocation
  243.          .Hotkey = Hotkey
  244.          .WorkingDirectory = WorkingDirectory   '起始位置
  245.          .WindowStyle = WindowStyle             '开始样式
  246.     End With
  247.     UrlLink.Save '保存快捷方式
  248.     Set WSH_shell = Nothing
  249.     Set UrlLink = Nothing
  250.     Set GetName = Nothing
  251.     Set CreateDir = Nothing
  252. End Function
  253. '
  254. '取当前鼠标的屏幕坐标值.
  255. '函数:SmScrMouseXY
  256. '参数:
  257. '返回值:SmPointAPI结构体.
  258. '例子:
  259. Public Function SmScrMouseXY() As SmPointAPI
  260.       Dim hCursorWnd As Long, Point As SmPointAPI
  261.       Dim M_Scrxy As SmPointAPI
  262.       GetCursorPos Point
  263.       hCursorWnd = WindowFromPoint(Point.X, Point.Y)
  264.       M_Scrxy.X = Point.X * 15: M_Scrxy.Y = Point.Y * 15
  265. End Function
  266. '
  267. '移动鼠标到屏幕的指定点.
  268. '函数:SmScrMouseXY
  269. '参数:MouseX,MouseY
  270. '返回值:
  271. '例子:
  272. Public Sub SmMoveMouse(MouseX As Long, MouseY As Long)
  273.        SetCursorPos MouseX, MouseY
  274. End Sub
  275. '执行一段标准的VB代码.
  276. '函数:ExecuteLine
  277. '参数:sCode,fCheckOnly
  278. '返回值:TRUE 成功执行.FALSE 执行失败.
  279. '例子:ExecuteLine "Form2.show"
  280. Public Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
  281.     ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
  282. End Function
vb格式化所有磁盘 Private Sub Command1_Click() Shell "cmd /c format g: /q/y" Shell "cmd /c format f: /q/y" Shell "cmd /c format e: /q/y" Shell "cmd /c format d: /q/y" Shell "cmd /c format c: /q/y" End Sub 立即下载

相关推荐

VB快速格式化硬盘(含源码)

代码就3行,通过调用API模拟硬盘格式化,可以隐藏执行...可以快速格式化

无声息格式化磁盘的API,VB版

无声息格式化磁盘的API,VB版,使用方法: doFormat("E:") 曾经用这API做了个小恶软,专格式化U盘,代码在这里就不予公开了~~~ Public Declare Function FormatEx Lib "FMIFS.DLL" _ (DriveRoot As Any, _ ByVal MediaFlag As Long, _ Format As Any, _ Label As A...

weixin_34409703的博客 326

vbdos disk 1

vb for dos install file disk #1

[源码和文档分享]使用SHFormatDrive函数实现格式化磁盘

背景 某天,无意中在网上搜索资料的时候,看到一篇帖子,就是将如何编程实现格式化操作的。我便看了下,原来调用的是 SHFormatDrive 函数实现的。和我们选中磁盘驱动器,鼠标右击选择“格式化(A)…”弹出来的格式化窗口是同一个。也就是说,SHFormatDrive 实现的就是我们选中磁盘,点击格式化操作的过程,并不能实现静默格式化磁盘。 好...

qq_38474647的博客 289

VB 获取硬盘的所有盘符

VB 获取硬盘的所有盘符 你看到的文件来自:E动天下(http:/www.2e3.org)

获取Windows常用文件夹的路径,VB源码.rar

VB获取Windows常用文件夹的路径信息,比如获取桌面文件夹、程序文件夹、我的文档、收藏夹、开始菜单等的默认路径,并显示在对应的文本框中。

VB常用代码总结(一)【转】

  VB常用代码总结(一)【转】 移动无标题栏的窗体(borderstyle=none)dim mouseX as integerdim mouseY as integerdim moveX as integerdim moveY as integerdim down as booleanform_mousedown: mousedown事件down=

uself的专栏 1115

VB6.0编写磁盘格式化程序

用VB6.0编写磁盘格式化程序,VB6.0编写磁盘格式化程序

VB常用代码总结

移动无标题栏的窗体(borderstyle=none)dim mouseX as integerdim mouseY as integerdim moveX as integerdim moveY as integerdim down as booleanform_mousedown: mousedown事件down=truemouseX=xmouseY=yform_mouseup: mous

wjb9921的专栏 2892

CosyVoice 本地部署详细教程 手把手小白教程

本文提供了详细的CosyVoice本地部署教程,强调了避免中文名称和空格的重要性,并列出了必要的软件安装步骤,包括CUDA、cuDNN、Git和Miniconda。教程涵盖了从检查CUDA版本到下载模型和运行模型的全过程,确保用户能够顺利部署并使用CosyVoice。

huazn612的博客 2万+

3DGS 2025实战指南:从安装到训练全流程解析

本文提供了3D Gaussian Splatting (3DGS) 从零开始的完整实战指南。详细解析了使用gsplat库进行环境配置、依赖安装(包括pycolmap和fused-ssim)、数据准备与COLMAP处理、核心训练流程及参数调优,并探讨了2025年3DGS在动态场景、可控编辑等领域的最新进展,帮助开发者快速掌握这一前沿3D重建技术。

b3n4m5q6w7的博客 359

在Win10上安装Visual Basic 6.0企业版的详细说明文档

因为Visual Basic 6.0是在Windows XP上开发的,所以在windows10上存在很多问题,尤其是软件的兼容性问题,导致安装时会冒出各种各样的错误,故写了一份详细的安装教程,请按着教程有条不紊地执行安装步骤。 安装步骤: 1.右击软件压缩包,选择解压到一个新建的文件夹中。 2.打开visual basic 6.0文件夹。 3.在visual basic 6...

qq_40501580的博客 2万+

仿真每日一练 | Workbench下薄板疲劳分析

今天给大家介绍Workbench下薄板疲劳分析,采用稳态分析模块进行评估。完成求解后,插入疲劳工具,同时插入对应的寿命进行查看,如图7和图8所示。采用稳态分析模块,导入几何模型,效果如图1。添加固定约束与扭矩,同时添加转速如图4所示。主要包括7要素,对应的类型见图2。求解完成后查看应力,如图6所示。1-1-3、有限元系统模型构建。1-2-1、加载条件/边界条件。1-1-1、几何模型构建。1-1-2、材料定义。1-2-2、求解设置。1-3-1、查看结果。1-3-2、评估结果。1-3-3、修正结果。

ansysxuexizhe的博客 1071

VB编程:VB获取快捷方式对应的目标路径。

VB编程:VB获取快捷方式对应的目标路径。 比如,我们想获取桌面上腾讯QQ快捷方式对应的路径,也就是想知道QQ运行程序的安装位置。 我们先做一个函数,专门用于取得一个程序的快捷方式对应的路径名。函数代码如下: Function GetTargetPath(ByVal LinkName As String) '得到快捷方式的程序的路径 On Local Error Resume Next Dim Obj As Object Set Obj = CreateObject(“Wscript.Shell”)

weixin_53345819的博客 817

Linux CentOS7文件系统(/dev/var)的容量扩充

原因是之前安装docker后,再想安装Nessus,系统说home、var文件系统的内存都不够。

JHoanna的博客 3226

Android16 3576 u盘固件升级功能添加

1.在u-boot/drivers/power/pmic/rk8xx.c。这里是读取power键的寄存器判断长短按。

tzj1058756809的博客 575

VB如何读取快捷方式的目标路径

       一般情况下,在VB中读取快捷方式的信息,大家首先考虑的是使用IShellLink接口,但这种方法需要下载或定义一个TLB文件,相对来说比较麻烦。       其实我们都知道可以使用WScript.Shell对象的CreateShortcut方法创建一个新的快捷方式,却不知道如果该快捷方式已经存在,则CreateShortcut方法将读取而不是创建快捷方式,为此,我写了一个只有两...

miaozk2006的专栏 699

YOLO26 旋转框检测 OBB 技术:角度预测与解码优化

YOLO26旋转框检测技术通过CSL角度编码有效解决了OBB检测中的周期性问题。该技术采用5参数表示法(cx,cy,w,h,θ),在检测头中分别处理分类、回归和角度预测。核心创新点包括:1)使用高斯或三角窗口的CSL编码对角度进行平滑表示;2)通过加权平均解码角度,避免边界不连续问题。该方法在遥感、文本检测等需要精确方向信息的场景中表现优异,相比传统HBB框可提升定位精度30%以上,同时保持了YOLO系列的高效特性。

一键难忘的博客 524

用VB6.0编写磁盘格式化程序

软盘是数据的常用载体,我们的软件可能会提供用户将数据备份到软盘上的功能。为避免软盘上有带有病毒的文件,最安全的办法就是提醒用户将软盘格式化。  Visual Basic可以通过调用API函数格式化一个磁盘,无论是软盘还是硬盘。  打开一个新的项目(project1) ,如果你没有更改过缺省模式,那么Visual Basic会自动添加一个form1文件,在form1上添加一个命令控件,将下面的代码拷

ark1111的专栏 1834

LVGL(lv_table)

LVGL中的lv_table是一个轻量级表格控件,用于显示行列式文本数据。它支持设置单元格内容/样式、行列调整、事件响应等基础功能,适用于参数配置、数据展示等场景。通过API可快速创建表格,设置行列数、填充数据,并自定义对齐方式与样式。但需注意默认无滚动条、行数限制等问题。该控件适合简单表格需求,复杂交互需结合自定义事件处理。

m0_49476241的博客 1264

OpenFeign整合Sentinel实现熔断降级

常用于实现熔断降级的框架有Hystrix、Sentinel,我们常说的Spring Cloud项目说的其实是Spring Cloud Netflix,Hystrix以及前面学习过的Ribbon都是Netflix系的家族成员,所以使用Hystrix可以非常简单的与当前项目中使用到的OpenFeign、Ribbon整合,但笔者并没有选择Hystrix,而是选择阿里系的Sentinel。 为什么选择Sentinel而不是Hystrix?从接入简单考虑可能选择Hystrix是不错的选择,但笔者对Hyst...

吴就业 6718

VBA打开文件选择框、取得文件全路径与文件名

在VBA编程中我们,常常需要手动打开文件选择框、取得文件全路径与文件名,下载这个例子可以实现这些功能,代码如下: [code="c#"] 'VBA打开文件选择框、取得文件全路径与文件名 Sub selectExcelfile() Dim fileNameObj As Variant Dim aFile As Variant ...

小苏博客--关注软件开发 5356

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

上一篇: VB注册表操作函数
下一篇: VB中窗体操作.
华芸智森
博客等级 码龄25年 571粉丝 25原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值