Jump to content

Problema a aceder à registry de máquina remota


zephirus
 Share

Recommended Posts

Olá,

Tenho o seguinte código para obter o valor da registry de uma máquina remota.

	Sub Button1Click(sender As Object, e As EventArgs)
	Dim environmentKey As RegistryKey
        ' Open HKEY_CURRENT_USER\Environment on a remote computer.
        environmentKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, txtIpAddress.Text).OpenSubKey("SOFTWARE\Siemens\TNMS\CurrentVersion")
        
	label2.Text = environmentKey.GetValue("DiskLabel")

        ' Close the registry key.
        environmentKey.Close()
End Sub

Para uma máquina que tentei funciona, mas para outras que tento dá este erro:

System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.

  at Microsoft.Win32.RegistryKey.Win32ErrorStatic

  at Microsoft.Win32.RegistryKey.OpenRemoteBaseKey

  at remoteGet.MainForm.Button1Click in \My Documents\SharpDevelop Projects\remoteGet\remoteGet\MainForm.vb:line 29

  at System.Windows.Forms.Control.OnClick

  at System.Windows.Forms.Button.OnClick

  at System.Windows.Forms.Button.OnMouseUp

  at System.Windows.Forms.Control.WmMouseUp

  at System.Windows.Forms.Control.WndProc

  at System.Windows.Forms.ButtonBase.WndProc

  at System.Windows.Forms.Button.WndProc

  at ControlNativeWindow.OnMessage

  at ControlNativeWindow.WndProc

  at System.Windows.Forms.NativeWindow.DebuggableCallback

  at ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop

  at ThreadContext.RunMessageLoopInner

  at ThreadContext.RunMessageLoop

  at System.Windows.Forms.Application.Run

  at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun

  at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel

  at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run

  at remoteGet.My.MyApplication.Main in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81

Ambas as máquinas estão no mesmo workgroup. Alguém sabe qual é o problema?

Obrigado

Link to comment
Share on other sites

UPDATE: verifiquei agora que já tinha acedido às pastas partilhadas da máquina remota a que consegui aceder ao registo e nas outras nunca o tinha feito. Basicamente o que isto quer dizer é que eu já tinha inserido o user e password da máquina remota e daí conseguir obter a informação.

De qualquer forma faz-me alguma confusão visto que há por ai muitos programas que até fazem o discovery de máquinas na rede e obtém toda a informação que querem. Como é que o fazem? Não é suposto ser preciso dar credenciais?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.