1
I need to get information related to the network to list in an application I’m doing, but I have a problem accessing the Registry Windows because of project preference.
Path: Right-click the class, click properties, and then compiler.
Note that below the Target CPU field, has a Checkbox (Prefer 32-bit)
If this option is ticada my code does not work on 64 bit system, however if I disable my application does not work on 32 bit machine. If I comment on all procedures that seek values in regedit, the application works on both.
I wonder if I can access the registry key in both 64bit and 32 bit.
Follows the code:
Public Sub ObterTipoDaRede(ByVal NomeConfiguracao As String, ByVal _
NomeConfiguracaoDois As String)
Dim NomeDaRede As String
Dim regKey
Dim lDatas As New List(Of KeyValuePair(Of String, DateTime))
'If Environment.Is64BitOperatingSystem Then
'Else
regKey = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles")
'End If
Try
For Each SubK In regKey.GetSubKeyNames
Dim value = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\" + SubK)
Dim data = My.Computer.Registry.GetValue(value.ToString, "DateLastConnected", Nothing)
Dim dt As DateTime = ObterDataDoUltimoAcesso(data)
lDatas.Add(New KeyValuePair(Of String, Date)(SubK, dt))
Next
lDatas = lDatas.OrderByDescending(Function(x) x.Value).ToList
Dim t = lDatas.First
Dim chave = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\" + t.Key)
Dim nomeRede As String = My.Computer.Registry.GetValue(chave.ToString, "ProfileName", Nothing)
Dim tipoRede As String = My.Computer.Registry.GetValue(chave.ToString, "Category", Nothing)
NomeDaRede = nomeRede
Select Case tipoRede
Case 0
Me.PerfilDaRede = "Publica"
Case 1
Me.PerfilDaRede = "Privada"
Case 2
Me.PerfilDaRede = "Dominio"
End Select
Me.PreencherGriddgvDadosComputador(NomeConfiguracao, NomeDaRede, "Ok")
Me.PreencherGriddgvDadosComputador(NomeConfiguracaoDois, Me.PerfilDaRede, "Ok")
Catch ex As Exception
MsgBox("Teste", vbInformation)
End Try
End Sub
Se essa opção estiver ticada meu código não funciona, porém se eu desabilitar minha aplicação não funciona na máquina 32 bits.
If I understand correctly your code does not work regardless of whether the option is enabled or not.– Oralista de Sistemas
If it’s not keyed, it works on 64-bit systems, but on 32-bit systems it doesn’t work.Any procedure I create to access regedit to get a value I can’t run on both systems.
– jnmoura