资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net获得扩展名,扩展名vbp

vb.net,知道一个文件的扩展名,如何获得该类型文件的默认打开程序。

Public Function GetTypeFilePath(ByVal mType As String)

创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于做网站、成都网站设计、河北网络推广、小程序定制开发、河北网络营销、河北企业策划、河北品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联建站为所有大学生创业者提供河北建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com

mType = mType.Trim

If mType.Substring(0, 1)  "." Then mType = "."  mType

Dim Key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(mType)

Dim Result As String = ""

If Not Key Is Nothing Then

Dim SubKeyValue As Object

Dim Value As String

SubKeyValue = Key.GetValue("")

If Not SubKeyValue Is Nothing Then

Value = SubKeyValue.ToString

Dim SubKey As Microsoft.Win32.RegistryKey, ResultKey As Microsoft.Win32.RegistryKey

SubKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(Value)

If Not SubKey Is Nothing Then

ResultKey = SubKey.OpenSubKey("shell\open\command\", False)

If Not ResultKey Is Nothing Then

Result = ResultKey.GetValue("").ToString

End If

End If

End If

End If

Return Result

End Function

vb.net,知道一个文件的扩展名,如何通过这个扩展名获得该文件的默认打开方式(即默认打开程序)?

如没有现存的办法的话只能读取注册表,以txt文件为类:

HKEY_CLASSES_ROOT\.txt   '在这个地址有个默认属性值是:txtfile

HKEY_CLASSES_ROOT\txtfile\shell\open\command   '这里的默认属性值txtfile的关联程序:%SystemRoot%\system32\NOTEPAD.EXE %1

我暂不了解vb.net读注册表函数(刚在学),以vbs为类:

Dim WshShell

Set WshShell = WScript.CreateObject("Wscript.Shell")

Dim Ext

ext= WshShell.RegRead ("HKEY_CLASSES_ROOT\.mp3\") '这里的扩展名.mp3可以改成其它的看看

MsgBox WshShell.RegRead ("HKEY_CLASSES_ROOT\"  ext  "\shell\open\command\")

vb.net从文件路径中获取文件名

获取方法,参考实例如下:

'获取路径名各部分: 如: c:\dir1001\aaa.txt

'获取路径路径 c:\dir1001\

Public Function GetFileName(FilePathFileName As String) As String '获取文件名 aaa.txt

On Error Resume Next

Dim i As Integer, J As Integer

i Len(FilePathFileName)

J InStrRev(FilePathFileName, "\")

GetFileName Mid(FilePathFileName, J + 1, i)

End Function

''获取路径路径 c:\dir1001\

Public Function GetFilePath(FilePathFileName As String) As String '获取路径路径 c:\dir1001\

On Error Resume Next

Dim J As Integer

J InStrRev(FilePathFileName, "\")

GetFilePath Mid(FilePathFileName, 1, J)

End Function

'获取文件名但不包括扩展名 aaa

Public Function GetFileNameNoExt(FilePathFileName As String) As String '获取文件名但不包括扩展名 aaa

On Error Resume Next

Dim i As Integer, J As Integer, k As Integer

i Len(FilePathFileName)

J InStrRev(FilePathFileName, "\")

k InStrRev(FilePathFileName, ".")

If k 0 Then

GetFileNameNoExt Mid(FilePathFileName, J + 1, i - J)

Else

GetFileNameNoExt Mid(FilePathFileName, J + 1, k - J - 1)

End If

End Function

'===== '获取扩展名 .txt

Public Function GetFileExtName(FilePathFileName As String) As String '获取扩展名 .txt

On Error Resume Next

Dim i As Integer, J As Integer

i Len(FilePathFileName)

J InStrRev(FilePathFileName, ".")

If J 0 Then

GetFileExtName ".txt"

Else

GetFileExtName Mid(FilePathFileName, J, i)

End If

End Function


文章名称:vb.net获得扩展名,扩展名vbp
网页地址:http://cdkjz.cn/article/dsipgie.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220