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
Related
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 1 year ago.
Improve this question
I have a power on-off device to control. If the device is connected to the network, my code works fine. I remove the device from the network on purpose to test it as if the device malfunctions (like power off). And I find out that the System hangs.
I trace that the socket.accept does not execute - 'accept is ok' is not written to a log file. ex.message does not write as well.
My purpose is to send a message to support if there is any device malfunction.
Using gSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
WriteLog("Start. ")
Dim remoteSocket As Socket
Try
gSocket.SendTimeout = 5000
gSocket.ReceiveTimeout = 5000
gSocket.Bind(vEndPoint) ' vEndpoint is the local machine
WriteLog("bind is ok. ")
gSocket.Listen(10)
WriteLog("listen is ok. ")
remoteSocket = gSocket.Accept
WriteLog("accept is ok. ")
Catch ex As Exception
WriteLog(ex.Message)
Finally
End Try
How can I solve this?
I use BeginAccept to solve it.
Dim acceptResult As IAsyncResult = gSocket.BeginAccept(Nothing, Nothing)
Dim Success As Boolean = acceptResult.AsyncWaitHandle.WaitOne(vTimeout, True)
If Success Then
remoteSocket = gSocket.EndAccept(acceptResult)
WriteLog("beginaccept is ok. ")
Else
gSocket.Close()
WriteLog("beginaccept failed. ")
End If
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Why isn't this working. I tried this on a school computer (fully reimaged and running on a network) and it worked fine
Yet, when I try it on my home pc (newly installed visual studio 2019)
it throws the exception:
Computer is not a member of projectname. My
Code is here:
Imports System
Module Program
Sub Main(args As String())
Dim fileReader As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader("D:\\story1.txt")
Dim stringReader As String = ""
Dim i As Integer = 1
Dim TotalString As String = ""
While stringReader <> "*"
stringReader = fileReader.ReadLine()
If i Mod 2 = 0 Then
TotalString += stringReader
End If
End While
Console.WriteLine(TotalString)
Console.ReadKey()
End Sub
End Module
Sorry about this - I was using the wrong type of application. I used type Console app .NET core instead of Console app .NET Framework
I apologize for any inconvenience.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I wrote a database for a soil drilling company. When a user adds a new project, they enter the number of borings that are supposed to be drilled for that project. After clicking the Add Project button, the project is added and a procedure should run that will add the number of borings to the Borings table and generate the boring numbers too (B-1, B-2, B-3, etc). Then the form is supposed to close and the Main form is supposed to open.
However, I keep getting the "Procedure declaration does not match description of event or procedure having same name" error whenever I update the Project Number or Boring Count text boxes. On the After Update event of those boxes, I have the values set to temporary variables (tmpProjectID and tmpBoringCount) which are then supposed to be passed to the procedure...right?
This is the procedure for the OnClick event of the Add Project button:
Private Sub btnAddProject_Click(tmpBoringCount As Integer, tmpProjectID As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Integer
Dim tmpBoringNumber As String
Set db = CurrentDb
Set rs = db.OpenRecordset("Borings")
i = 1
tmpBoringNumber = "B-" & i
Do While i <= tmpBoringCount
rs.AddNew
rs!ProjectID = tmpProjectID
rs!PointID = tmpBoringNumber
rs.Update
i = i + 1
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
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.
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.