vb 获取已安装的程序名和路径

vb 获取已安装的程序名和路径,第1张

GetSetting 函数

从 Windows 注册表中的应用程序项目返回注册表项设置值。

语法

GetSetting(appname, section, key[, default])

VB6本身自带了一个打包程序可以用来生成安装程序,虽然功能有些简单,界面也很简陋,但因为是自身自带的,所以兼容性最好,可以把你的程序运行需要的所有文件(包括VB运行库文件)都包含进去。

如果用VB来自己写安装程序,那么首先要避免一个尴尬情况:就是如果你要安装的电脑不支持VB编译的程序运行的话(尽管这种情况现在已经很少发生),那么你的安装程序自身都无法运行,更不用说释放里面的文件了。安装程序的一个最基本的特点就是一定要能绿色运行,对系统和其他软件的依赖性越小越好。如果你写的安装程序能保证做到这一点,那么你就可以把你要安装的程序文件、数据文件等都放到资源文件中,编译后就会合成为一个文件了,安装的时候再把这些文件释放到指定目录即可。

其实,完全可以利用一些压缩软件(如WINRAR)的生成自解压文件的功能来生成安装程序,不但体积小,功能也很完善的。

如果我理解正确的话,应该是这样的。有个程序的安装文件,如果点击安装的话,需要点击下一步、下一步,比较麻烦,楼主是想用VB写个程序,打开VB的程序,安装文件就会自动安装了,不用去点击。是这样吗?如果这样比较好做。首先用shell"setupexe"。然后自动点击按钮的方法实现。代码因机子上没vb,所以没写。可以在网上搜索下。如果实在找不到,给我留言,我抽空帮你写下!

检测某程序是需要检测进程吧,FindWindow是查找窗口别人把窗口隐藏了你找什么去~~~~~

先把找进程的贴出来,再贴查版本的

进程查找:(我是把代码全搬出来了,有些其他你不要的函数自己清理下)

(模块)

声明:

'进程-查找

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long

Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long

Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long

Private Type PROCESSENTRY32

dwSize As Long

cntUsage As Long

th32ProcessID As Long

th32DefaultHeapID As Long

th32ModuleID As Long

cntThreads As Long

th32ParentProcessID As Long

pcPriClassBase As Long

dwFlags As Long

szExeFile As String 1024

End Type

Private Const TH32CS_SNAPHEAPLIST = &H1

Private Const TH32CS_SNAPPROCESS = &H2

Private Const TH32CS_SNAPTHREAD = &H4

Private Const TH32CS_SNAPMODULE = &H8

Private Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)

Private Const TH32CS_INHERIT = &H80000000

Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long

Private WM_TASKBARCREATED As Long

'------------------------------------------------------------------------------

'进程 *** 作部分:--------此部分只作为主程序的专有部分,其他子程序暂无 *** 作进程功能-------------------------

'查找函数

Public Function FindPro(ByVal sExePro As String, ByRef lProID As Long) As Integer '1找到该进程,0没找到

Dim my As PROCESSENTRY32

Dim l As Long

Dim l1 As Long

Dim mName As String

Dim i As Integer

Dim PID

FindPro = 0

sExePro = LCase(sExePro)

l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)

If l Then

mydwSize = 1060

If (Process32First(l, my)) Then '遍历开始

Do

i = InStr(1, myszExeFile, Chr(0))

mName = LCase(Left(myszExeFile, i - 1))

If mName = sExePro Then

PID = myth32ProcessID

'pname = mName

Dim mProcID As Long

mProcID = OpenProcess(1&, -1&, PID)

lProID = mProcID

'MsgBox pname

'TerminateProcess mProcID, 0&

FindPro = 1 '找到进程

Exit Function

End If

Loop Until (Process32Next(l, my) < 1)

End If

l1 = CloseHandle(l)

End If

End Function

'结束进程(查找进程,如存在则结束,不存在则无 *** 作)

Public Function SetEndPro(ByVal sExePro As String) As Integer '1成功结束,-1无此进程,0结束进程失败

Dim lProID As Long

Dim tmBack As Long

lProID = -1

If FindPro(sExePro, lProID) = 1 Then

tmBack = TerminateProcess(lProID, 0&)

If tmBack <> 0 Then

SetEndPro = 1 '成功结束进程

Else

SetEndPro = 0 '失败

End If

CloseHandle lProID

Exit Function

Else

SetEndPro = -1 '不存在

End If

End Function

'--------------------------------------------------------

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'(完了再贴检测版本,你自己组合下函数就好了仍然有很多你不要的函数声明,自己清理下)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''Ver for AOSexe'''''''''''''''''''

Type VS_FIXEDFILEINFO

dwSignature As Long

dwStrucVersionl As Integer ' eg = &h0000 = 0

dwStrucVersionh As Integer ' eg = &h0042 = 42

dwFileVersionMSl As Integer ' eg = &h0003 = 3

dwFileVersionMSh As Integer ' eg = &h0075 = 75

dwFileVersionLSl As Integer ' eg = &h0000 = 0

dwFileVersionLSh As Integer ' eg = &h0031 = 31

dwProductVersionMSl As Integer ' eg = &h0003 = 3

dwProductVersionMSh As Integer ' eg = &h0010 = 1

dwProductVersionLSl As Integer ' eg = &h0000 = 0

dwProductVersionLSh As Integer ' eg = &h0031 = 31

dwFileFlagsMask As Long ' = &h3F for version "042"

dwFileFlags As Long ' eg VFF_DEBUG Or VFF_PRERELEASE

dwFileOS As Long ' eg VOS_DOS_WINDOWS16

dwFileType As Long ' eg VFT_DRIVER

dwFileSubtype As Long ' eg VFT2_DRV_KEYBOARD

dwFileDateMS As Long ' eg 0

dwFileDateLS As Long ' eg 0

End Type

Declare Function GetFileVersionInfo Lib "Versiondll" Alias _

"GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal _

dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long

Declare Function GetFileVersionInfoSize Lib "Versiondll" Alias _

"GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _

lpdwHandle As Long) As Long

Declare Function VerQueryValue Lib "Versiondll" Alias _

"VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, _

lplpBuffer As Any, puLen As Long) As Long

Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _

(dest As Any, ByVal Source As Long, ByVal Length As Long)

Public Function GetVer(Optional ExePath) As String

' Get Version Info

If Not IsMissing(ExePath) Then

fullfilename = ExePath

Else

fullfilename = AppEXEName + "exe"

End If

Dim FileVer As String

Dim rc As Long

Dim lDummy As Long

Dim sBuffer() As Byte

Dim lBufferLen As Long

Dim lVerPointer As Long

Dim udtVerBuffer As VS_FIXEDFILEINFO

Dim lVerbufferLen As Long

' Get size

lBufferLen = GetFileVersionInfoSize(fullfilename, lDummy)

If lBufferLen < 1 Then

'MsgBox "该文件没有版本信息!", vbInformation

Exit Function

End If

' Store info to udtVerBuffer struct

ReDim sBuffer(lBufferLen)

rc = GetFileVersionInfo(fullfilename, 0&, lBufferLen, sBuffer(0))

rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)

MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)

' Determine File Version number

FileVer = Format$(udtVerBufferdwFileVersionMSh) & "" & _

Format$(udtVerBufferdwFileVersionMSl) & "" & _

Format$(udtVerBufferdwFileVersionLSh) & "" & _

Format$(udtVerBufferdwFileVersionLSl) '倒数第二句Format$(udtVerBufferdwFileVersionLSh) & ""

GetVer = FileVer

End Function

以上就是关于vb 获取已安装的程序名和路径全部的内容,包括:vb 获取已安装的程序名和路径、VB编写安装程序问题、vb制作自动安装程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9737465.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存