J
Jeff
I'm trying to use the code posted in various forums to get the Owner Name on
a device, and I'm having a bit of trouble. Please help.
(I'm using VB.NET with Option Strict On.)
My code is:
I have a form with a button. The button click event has the following two
lines:
Dim test As String = OwnerName()
MessageBox.Show("[" & test & "]")
OwnerName is the following function:
Public Function OwnerName() As String
Try
Dim ownerbytes As Byte()
ownerbytes =
CType(OpenNETCF.Win32.Registry.CurrentUser.OpenSubKey("ControlPanel\Owner").
GetValue("Owner"), Byte())
OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd(CType("\0", Char))
'Note: I've also tried the following line with the same result:
'OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd("0"c)
Catch nEx As NullReferenceException
MessageBox.Show("Please enter your Owner Name before using this program." &
CL & nEx.ToString & CL & nEx.Message)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
The Owner Name on the device is
Test Name
Stepping through the code, I typed the following into the Command Window
before the 'OwnerName=' assignment:
?System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd(CType("\0", Char))
"Test Name"
I typed the following into the Command Window after the 'OwnerName='
assignment (note the trailing quote is gone from the result):
?ownername
"Test Name
When control returned to my button event, I got the same result with the
variable, test:
?test
"Test Name
And finally, the Messagebox displayed (Note no trailing ']'):
[Test Name
I'm trying to get test = "Test Name", and the Messagebox to show [Test Name]
What am I missing??
Thanks for your help.
- Jeff
a device, and I'm having a bit of trouble. Please help.
(I'm using VB.NET with Option Strict On.)
My code is:
I have a form with a button. The button click event has the following two
lines:
Dim test As String = OwnerName()
MessageBox.Show("[" & test & "]")
OwnerName is the following function:
Public Function OwnerName() As String
Try
Dim ownerbytes As Byte()
ownerbytes =
CType(OpenNETCF.Win32.Registry.CurrentUser.OpenSubKey("ControlPanel\Owner").
GetValue("Owner"), Byte())
OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd(CType("\0", Char))
'Note: I've also tried the following line with the same result:
'OwnerName = System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd("0"c)
Catch nEx As NullReferenceException
MessageBox.Show("Please enter your Owner Name before using this program." &
CL & nEx.ToString & CL & nEx.Message)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Function
The Owner Name on the device is
Test Name
Stepping through the code, I typed the following into the Command Window
before the 'OwnerName=' assignment:
?System.Text.Encoding.Unicode.GetString(ownerbytes, 0,
72).TrimEnd(CType("\0", Char))
"Test Name"
I typed the following into the Command Window after the 'OwnerName='
assignment (note the trailing quote is gone from the result):
?ownername
"Test Name
When control returned to my button event, I got the same result with the
variable, test:
?test
"Test Name
And finally, the Messagebox displayed (Note no trailing ']'):
[Test Name
I'm trying to get test = "Test Name", and the Messagebox to show [Test Name]
What am I missing??
Thanks for your help.
- Jeff