VB checking if object exists before creating [duplicate] - vb.net

This question already has answers here:
Check if the application is already installed
(3 answers)
Closed 9 years ago.
Is their a way to check an application exists before I write in the code to create the object
I know this is install and I can use it but what if I want the program to check first ?
Set objOutlook = GetObject("Outlook.Application")

In fact, you should verify if there is entry in Registry.
You can proceed as follows;
Dim regKey As RegistryKey
regKey = My.Computer.Registry.ClassesRoot.OpenSubKey("Outlook.Application", False).OpenSubKey("CurVer", False)
If not string.IsNullOrEmpty(regKey.GetValue("")) then
// Your code
End if

Related

MS Access VBA Webclient.DownloadFile "=" expected [duplicate]

This question already has answers here:
What are the rules governing usage of parenthesis in VBA function calls?
(8 answers)
ms access - vba: Compile Error: expected: =
(3 answers)
Closed 9 months ago.
This post was edited and submitted for review 9 months ago and failed to reopen the post:
Original close reason(s) were not resolved
I'm writing a MS Access program with a SQL Server database and trying to download a PDF from my SSRS using a VBA script. After checking some forums, I've found the following function: Webclient.DownloadFile(URL,Path).
To test the function for my purposes, I wrote this code:
Dim reportUrl As String
Dim reportPfad As String
ReportUrl = "http://localhost/reportserver?/rechnung&rs:Format=PDF"
reportPfad = "C:\TEMP\"
WebClient.DownloadFile(reportUrl, reportPfad)
If I try to execute the code, I get this message (freely translated to English):
Error while Compiling:
Expected: =
Can you help me out?

shared inbox how do you get vba to go there instead of my own inbox [duplicate]

This question already has answers here:
Get reference to additional Inbox
(3 answers)
Closed 1 year ago.
Set inboxFolder = outNS.GetDefaultFolder(olFolderInbox)
this bit goes to my default inbox but i have a shared inbox how would i get it to take the emails from there . any suggestions be great i have tried a few things my self but no success
Use either Namespace.GetSharedDefaultFolder or (if the mailbox is already open in the current profile), use Namespace.Store collection to find the right store, then use Store.GetDefaultFolder.

Get antivirus name from wscui.cpl with vb.net [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am looking for away to get this value:
I am building a program that will be installed on 100s of computers and servers. And i need to figure out how i can get the name of the anti virus in vb.net.
This can also be a powershell script. It is possible to read the output from a powershell script in vb.net
The problem is: With all the scripts that I could find any where it was not able to even get my own antivirus. There needs to be a way to read the information from the control panel right? Or is that impossible.
So after some searching i found this: with SecurityCenter2. For me this works
Dim IPAddress As String = "127.0.0.1"
Dim connectionOptions As New ConnectionOptions()
connectionOptions.EnablePrivileges = True
connectionOptions.Impersonation = ImpersonationLevel.Impersonate
Dim managementScope As New ManagementScope(String.Format("\\{0}\root\SecurityCenter2", IPAddress), connectionOptions)
managementScope.Connect()
Dim objectQuery As New ObjectQuery("SELECT * FROM AntivirusProduct")
Dim managementObjectSearcher As New ManagementObjectSearcher(managementScope, objectQuery)
Dim managementObjectCollection As ManagementObjectCollection = managementObjectSearcher.[Get]()
Dim antivirus As String = ""
If managementObjectCollection.Count > 0 Then
For Each item As ManagementObject In managementObjectCollection
antivirus = antivirus + item("displayName") + " - "
Next
antivirus = antivirus.Remove(antivirus.Count - 3, 3)
End If

How can I find the destination of a .lnk file in vb.net [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I made a explorer.exe clone, with a treeview and a listview etc.
Now I need to handle clicking a .lnk file, so I need the destination path of a .lnk file..
You can use a WshShell Object:
You create a WshShell object whenever you want to run a program locally, manipulate the contents of the registry, create a shortcut, or access a system folder.
and use its CreateShortcut method:
Creates a new shortcut, or opens an existing shortcut.
The resulting WshShortcut object contains a TargetPath property, which is what you're looking for.
Example:
Dim shell = CreateObject("WScript.Shell")
Dim path = shell.CreateShortcut(path_to_your_link).TargetPath
I'd try;
Public Shared Function GetLnkTarget(lnkPath As String) As String
Dim shl = New Shell32.Shell()
' Move this to class scope
lnkPath = System.IO.Path.GetFullPath(lnkPath)
Dim dir = shl.[NameSpace](System.IO.Path.GetDirectoryName(lnkPath))
Dim itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath))
Dim lnk = DirectCast(itm.GetLink, Shell32.ShellLinkObject)
Return lnk.Target.Path
End Function
You need to reference a COM object; Microsoft Shell Controls And Automation.

Read and write to the registry with VB.NET [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 months ago.
Improve this question
I made a game and I would like to store the high score and other values in the windows registry. It's made in VB.NET. Could someone give me a sample code example of simple reading and writing to the registry.
Thanks
You must open Registry sub Key before read or write. Then you can read or write
Dim regKey As RegistryKey
Dim Value As Object
regKey =My.Computer.Registry.CurrentUser.OpenSubKey("HKEY_CURRENT_USER\Software\VB_and_VBA_Program_Settings", True)
'Here u can read value of AppName
Value = regKey.GetValue("AppName", "Default Value")
'Or u can write the value
value=regkey.setValue("AppName", "myApp")
regKey.Close()
Simply...
Imports Microsoft.VisualBasic
Dim s As String
SaveSetting("(AppName)", "(SectionName)", "(Key)", "(Your Value)")
s = GetSetting("(AppName)", "(SectionName)", "(Key)", "(Default Value)")
Replace (AppName), (SectionName), (Key) with appropriate values. The data will be saved in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\(AppName)
http://www.vbdotnetheaven.com/UploadFile/mahesh/WindowsRegistry04262005045814AM/WindowsRegistry.aspx
http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx
I'm more comfortable with C#, but it's pretty straightforward with VB.NET too. Here's an example of how to write to the registry, and another example of how to read from the registry. Don't forget to import the Microsoft.Win32 namespace.
You can use registry.getvalue and registry.setvalue. Here are a couple of examples used for default file types:
Registry.GetValue("HKEY_CURRENT_USER\software\classes" & "\" & fileFormatExt(i), "", "error")
Registry.SetValue("HKEY_CURRENT_USER\software\classes\" & FileType, "", appTag) ' set new value, overwrite any other, creates key if not there.