Click here to Skip to main content
16,016,425 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900