在Visual Basic中卸载程序 [英] uninstall programs in visual basic

查看:252
本文介绍了在Visual Basic中卸载程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,有些问题
正在尝试使用编程语言Visual Basics进行代码卸载程序
我对其进行了编码,以列出计算机上的所有安装程序,并尝试编写代码以将其卸载
到目前为止,我有这个
导入microsoft.win32
导入system.IO


Dim RegistryKeyObj作为RegistryKeyDim CurrentRegKeyObj作为RegistryKeyDim IsMyAppBool作为Boolean = False
RegistryPath =
昏暗的ProcessInfoObj作为ProcessStartInfoDim UnInstallCmdStr作为字符串= String.EmptyDim ProcessObj作为新的ProcessDim TempBachFile作为StreamWriterSub Main()"SOFTWARE \ MICROSOFT \ Windows \ CurrentVersion \ Installer \ UserData \ S-1-5-18 \ Products"
RegistryKeyObj = Registry.LocalMachine.OpenSubKey(RegistryPath)

试试

CurrentRegKeyObj = RegistryKeyObj.OpenSubKey(ApplicationObj).OpenSubKey(

对于每个ApplicationObj,作为RegistryKeyObj.GetSubKeyNames"InstallProperties"中的字符串,如果不是CurrentRegKeyObj则不然
如果String.Compare(CurrentRegKeyObj.GetValue("DisplayName").ToString,MyAppStr)= 0然后
UnInstallCmdStr = CurrentRegKeyObj.GetValue(
TempBachFile =
TempBachFile.WriteLine(UnInstallCmdStr)
TempBachFile.Close()
ProcessInfoObj =
ProcessInfoObj.RedirectStandardOutput =
"UninstallString").ToStringNew StreamWriter("Uninstall.bat")New ProcessStartInfo("Uninstall.bat")True
ProcessInfoObj.UseShellExecute = False

ProcessInfoObj.CreateNoWindow = False

ProcessObj.StartInfo = ProcessInfoObj
ProcessObj.Start()
ProcessObj.WaitForExit()
IsMyAppBool =
真实
退出

如果结束

如果结束

下一个

如果IsMyAppBool = False,那么
Console.WriteLine(

应用程序:&MyAppStr&"尚未安装在系统中.")如果结束

Console.WriteLine(ex.Message)

赶上ExceptionEnd Try
Console.ReadKey()

结束


我真的需要帮助.

hey am having some problems
am trying to code to uninstall a program in the programming language visual basics
i coded it to list all install program which is on the computer and am trying to code to uninstall it
so far i have this
Imports microsoft.win32
Imports system.IO


Dim RegistryKeyObj As RegistryKeyDim CurrentRegKeyObj As RegistryKeyDim IsMyAppBool As Boolean = False
RegistryPath =
Dim ProcessInfoObj As ProcessStartInfoDim UnInstallCmdStr As String = String.EmptyDim ProcessObj As New ProcessDim TempBachFile As StreamWriterSub Main()"SOFTWARE\MICROSOFT\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
RegistryKeyObj = Registry.LocalMachine.OpenSubKey(RegistryPath)

Try

CurrentRegKeyObj = RegistryKeyObj.OpenSubKey(ApplicationObj).OpenSubKey(

For Each ApplicationObj As String In RegistryKeyObj.GetSubKeyNames"InstallProperties")If Not CurrentRegKeyObj Is Nothing Then
If String.Compare(CurrentRegKeyObj.GetValue("DisplayName").ToString, MyAppStr) = 0 Then
UnInstallCmdStr = CurrentRegKeyObj.GetValue(
TempBachFile =
TempBachFile.WriteLine(UnInstallCmdStr)
TempBachFile.Close()
ProcessInfoObj =
ProcessInfoObj.RedirectStandardOutput =
"UninstallString").ToStringNew StreamWriter("Uninstall.bat")New ProcessStartInfo("Uninstall.bat")True
ProcessInfoObj.UseShellExecute = False

ProcessInfoObj.CreateNoWindow = False

ProcessObj.StartInfo = ProcessInfoObj
ProcessObj.Start()
ProcessObj.WaitForExit()
IsMyAppBool =
True
Exit For

End If

End If

Next

If IsMyAppBool = False Then
Console.WriteLine(

"Application : " & MyAppStr & " had not installed in the system.")End If

Console.WriteLine(ex.Message)

Catch ex As ExceptionEnd Try
Console.ReadKey()

End


i really need help

推荐答案

缺少一些代码.

您也不需要编写临时批处理文件.

作为更好的替代方法,您应该从WMI和 ^ ]类.每个实例都有一个称为卸载"的方法.与编写愚蠢的批处理文件相比,这将使卸载任何软件都容易得多.
There are pieces of the code that are missing.

You also do NOT need to write a temporary batch file.

As a bmuch better alternative, you should be getting the list of installed software from WMI and the Win32_Product[^] class. Each instance has a method called, of course, Uninstall. This will make uninstalling any piece of software much easier than writing a stupid batch file.


这篇关于在Visual Basic中卸载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆