How to get hardware print? - hardware

Can someone tell me how to get the hardware print of my computer, on VB 2010 express, or where and how is that stored? Thanks in advance.

The best way to figure out what hardware is attached to your computer is to use WMI to get the information. Microsoft has created a tool that will create C#, VB.Net and VBScript sample code which you can run with the program and see what the values are, you can then add it to your program. This tool is called the WMI Code Creator. I would start out by exploring the Classes starting with Win32_
Now that I know what you are trying to do I can be a little more specific. The WMI NameSpace you are needing is root\CIMV2 the Class is Win32_DiskDrive or Win32_PhysicalMedia and the Property is SerialNumber. I made a small console test app in Vb.net. It will print out the drive serialnumbers on your PC, if you need it in c# I can modify. There are also numerous other SO Questions about the same subject.
Imports System
Imports System.Management
Module Module1
Sub Main()
For Each sn As String In GetDriveSerialNumber()
Console.WriteLine(sn.Trim)
Next
Console.ReadLine()
End Sub
Function GetDriveSerialNumber() As List(Of String)
Dim snList As List(Of String) = New List(Of String)
Try
Dim searcher As New ManagementObjectSearcher("root\CIMV2", "SELECT * FROM Win32_DiskDrive")
For Each queryObj As ManagementObject In searcher.Get()
snList.Add(queryObj("SerialNumber").ToString())
Next
Catch err As ManagementException
Throw
End Try
Return snList
End Function
End Module

Related

VB.net Process.Start starts process but leaves variable as nothing

To start I would only rate myself as a novice programmer as I only know the concepts I've needed to learn to accomplish specific tasks at my work. That being said I'm using Process.Start to open the built-in Windows to camera program but when I do it leaves the process variable empty (nothing). Because of this I can't use Process.WaitForExit() as the code causes an error during execution.
Imports System.Diagnostics
Sub Main()
Dim camTimeout as integer = 5 * 60000
Dim camProcess as new System.Diagnostics.Process
camProcess = System.Diagnostics.Process.Start("microsoft.windows.camera:")
If Not camProcess.WaitforExit(camTimeout) then
MsgBox("timeout")
Else
MsgBox("picture")
End if
End Sub
During execution the camera app opens but I get a "NullReferenceException" at camProcess.WaitForExit. This is because camProcess is Nothing and I don't understand why that is. Can someone explain why camProcess isn't set properly when the camera app starts or point me to some novice-level reference material. Thanks!
Edit: This code is in a Windows Form Application.

SolidWorks API, Macro working in VSTA but not from dll

Really appreciate who can spend couple of minutes to help me out, so thanks in advance !
Got myself into situation where running macro in VSTA works (vb.net), but running dll files from solid works does not work. Probably forgetting something very simple. Principle is that text file is in same folder as dll files and by default read from that folder without long location "string"
This works in VSTA and after building dll (very simple)
Partial Class SolidWorksMacro
Public Sub main()
Dim Model As ModelDoc2 = swApp.ActiveDoc
Dim LayerName As String = "Stamp"
MsgBox(LayerName)
End Sub
Public swApp As SldWorks
End Class
No I want to do same thing in a way that layer name is read from text file. It works when running from VSTA, but after building to dll and running from solid works it gives error: cannot open
"Location"\macro.dll.
Partial Class SolidWorksMacro
Public Sub main()
Dim Model As ModelDoc2 = swApp.ActiveDoc
Dim LayerName As String = "Stamp"
Dim FileName As String = "LayerName.txt"
Dim LayerName As String
Dim sr As New StreamReader(FileName)
LayerName = sr.ReadLine
MsgBox(LayerName)
End Sub
Public swApp As SldWorks
End Class
How are you planning on running the code? You will have to build out additional functionality to create a button/taskpane/property page through the API for SOLIDWORKS to know what you want to do. It is a little more complicated than running a macro. What references did you add to your project? You will need to add at least:
SolidWorks.Interop.sldworks
SolidWorks.Interop.swpublished
Are you properly implementing the ISwAddin interface? Also, I have not had much luck merely opening a DLL with SOLIDWORKS, I use regasm.exe to register the COM DLL or create a wix installer to create the registry entries if distributing to multiple machines.
The Getting Started page in the API help will be a good reference to see some examples and how to configure your environment.

Writing Queries in sqlite with vb.net & uwp

I have searched most of SO, and spent countless hours googling, so I'm going to post in the hopes that someone can help or just tell me it can't be done!
I am trying to make my vb.net uwp application be able to query a local sqlite database with a test query, but I am at a complete loss trying to find an example or any sort of documentation that isn't in c# without a clear parallel to how to translate to vb.net.
I have a base test class that can successfully connect with my database file, but I can't find anywhere how to do a query - all the resources online just link me to either vb.net without uwp or c# with uwp! I'll paste my code, but links to any resources or any advice would be so so helpful :)
Public Class dtbTest
Private conn As SQLiteConnection
Private sqcommand As SQLiteCommand
Private query As String = "SELECT * FROM userdetails"
Private cnn As SQLiteConnection
Private DBConnection As String = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "test.s3db")
Private tableInfo As List(Of SQLiteConnection.ColumnInfo)
Public Sub New()
Try
conn = New SQLiteConnection(DBConnection)
conn.BeginTransaction()
tableInfo = conn.GetTableInfo("userdetails")
sqcommand.CommandText = query
Catch
End Try
End Sub
End Class
In case people are interested, I got it working by trying the new Microsoft.Data.SQL package, so would recommend checking that if anyone is having similar problems!

Excel UDF 'not a valid addin' error

I am trying to create a custom vb.net Excel 2007 function (UDF) using VS 2010 and have gotten to this stage (borrowing heavily from Eric Carter's example at http://blogs.msdn.com/b/eric_carter/archive/2004/12/01/273127.aspx):
Namespace AutomationAddin
<Guid("1aeeb1b5-e099-4f7f-aeb0-3e9f19b64f62")>
<ClassInterface(ClassInterfaceType.AutoDual)>
<ComVisible(True)>
Public Class MyFunctions
Public MyFunctions()
Public Function MultiplyNTimes(ByVal number1 As Double, ByVal number2 As Double, ByVal timesToMultiply As Double) As Double
Dim result As Double = number1
For i As Integer = 0 To timesToMultiply - 1
result = result * number2
Next
Return result
End Function
<ComRegisterFunctionAttribute()>
Public Shared Sub RegisterFunction(ByVal type As Type)
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type, "Programmable"))
Dim key As RegistryKey = Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type, "InprocServer32"), True)
key.SetValue("", (System.Environment.SystemDirectory + "\mscoree.dll"), RegistryValueKind.String)
End Sub
<ComUnregisterFunctionAttribute()>
Public Shared Sub UnregisterFunction(ByVal type As Type)
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type, "Programmable"), False)
End Sub
Private Shared Function GetSubKeyName(ByVal type As Type, ByVal subKeyName As String) As String
Dim s As System.Text.StringBuilder = New System.Text.StringBuilder
s.Append("CLSID\{")
s.Append(type.GUID.ToString.ToUpper)
s.Append("}\")
s.Append(subKeyName)
Return s.ToString
End Function
End Class
End Namespace
However, when I build it using VS 2010 and try to load it in Excel 2007 using the Addin Manager>Automation I find it listed as AutomationAddin.AutomationAddin.MyFunctions and click OK only to get the error "AutomationAddin.AutomationAddin.MyFunctions is not a valid add-in." I have set the Build settings to Register for COM interop.
I've had a look online and tried following this article How to get COM Server for Excel written in VB.NET installed and registered in Automation Servers list? but to no avail. I checked my registry (after I built my project) and under CLSID/{myGuid}/InprocServer32/Default the data is set to C:\WINDOWS\system32\mscoree.dll and CLSID/{myGuid}/Programmable already exists.
I am not quite sure what I am doing wrong and would appreciate any guidance or suggestions on the topic.
Cheers,
Ben
You might want to check out this article (Build and Deploy a .NET COM Assembly) which might be helpful in your case.
I don't know if this is relevant to the question (especially after all this time) but I originally started with a COM add-in (created using Visual Studio 2010's Excel 2010 add-in project builder). I then added an automation add-in (for UDFs) by hand in the same project using the Eric Carter blog and other examples. The two worked fine independently. It was only after combining the two in the same namespace (for some obsessively tidy reason) that I started getting the "... is not a valid add-in" error. Spent a day tearing my hair out and then separated the namespaces again - problem went away.

Open multiple files using arguments

I'm using this code to load multiple files using windows context menu, but the problem is that the aplication is open many times as files the user has selected.
For example: If I select 14 files, an open them with the application, the aplicacion is opened 14 times and load the form only one.
But there is a way to send all arguments once? Because %1 send only one file, or there is for example a %2 that send all file pats in one argument? If there is I'vent found.
This my actual code:
Public Class Program
Public Shared Sub Main()
Dim FurBase As New Core.clsDatabase
FurBase.Directory = My.Application.Info.DirectoryPath
Dim returnValue As String()
returnValue = Environment.GetCommandLineArgs()
If returnValue.Length > 1 Then
FurBase.AddTemporalFilepath(returnValue(1).ToString)
End If
If Not Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
ShowUploader()
End If
End Sub
Private Shared Sub ShowUploader()
Dim Uploader As New frmUploader
Application.EnableVisualStyles()
Application.Run(Uploader)
End Sub
End Class
Please tell me what think about the code and if ther is any way to improve it.
Regards~
I was reading about that today; seems you'll need to deal with a DDE server.
There are an old question which can help you: What is the best .net alternative to dde for file associations?