Re: Pocket PC Owner info

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Jeff (jeff_nospam_at_eNetPortals.com)
Date: 06/18/04


Date: Fri, 18 Jun 2004 01:46:31 GMT

Thanks, CTitanic -

I'm getting Option Strict exceptions with the following 2 lines:

vOwner = regkey1.GetValue("Owner")

and

vSOwner = System.Text.Encoding.Unicode.GetString(vOwner, 0,
72).TrimEnd("\0")

I've tried to muddle through these types of issues before, but I think I've
done so incorrectly. Can you please suggest code that will work with Option
Strict On??

Thanks for your help.

- Jeff

"CTitanic" <ctitanic@pc-counselor.8m.com> wrote in message
news:euPkfTNVEHA.2908@TK2MSFTNGP10.phx.gbl...
> Try this:
>
> Dim ObjReg As OpenNETCF.Win32.Registry
> Dim regkey1 As OpenNETCF.Win32.RegistryKey
> Dim vOwner As Byte()
> Dim vSOwner As String
>
> regkey1 = ObjReg.CurrentUser.OpenSubKey("ControlPanel\Owner", True)
> Dim vExist As Boolean = True
> Try
> Dim x As Integer = regkey1.ValueCount()
> If x > 0 Then
> vExist = True
> Else
> vExist = False
> End If
> Catch ex As Exception
> vExist = False
> End Try
>
> If vExist = True Then
> vOwner = regkey1.GetValue("Owner")
> Else
> MessageBox.Show("Owner Info is Empty", "Error Message!", _
> MessageBoxButtons.OK, MessageBoxIcon.Exclamation, _
> MessageBoxDefaultButton.Button1)
> Application.Exit()
>
> End If
>
> regkey1.Close()
> vSOwner = System.Text.Encoding.Unicode.GetString(vOwner, 0,
> 72).TrimEnd("\0")
> vSOwner = Trim(vSOwner)
>
>
> CTitanic
> www.pc-counselor.com
>
>
> Jeff wrote:
>
> >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
> >
> >
> >
> >
>
>
> --
> Frank J. Garcia
> www.pc-counselor.com
> Home of Tweaks2k2


Quantcast