|
Member 4052115 wrote: I thought that when I create the subKey and set the access as follows…
regKey.CreateSubKey("Software\Liebert\RegistryTest", RegistryKeyPermissionCheck.ReadWriteSubTree)
...that this would give Read/Write access to all users…
Wrong. What you specified was your REQUEST for access to Read/Write the subtree. You didn't GRANT those permissions.
To normal users, the entire LOCAL_MACHINE key is read-only by default. To PowerUsers and Admins, it's Read/Write. During your applications installation, you can create the root key for your app, then you have to specifically grant Read/Write permissions to that key to whatever group you want, even the built-in Everyone group.
The CreateSubTree method has a third overload where you specify the key path, the requested access control (what you specified), and then a RegistrySecurity object that sets the security on the new key. But, normal users won't have access to create the key, nor set the access permissions. Only an Admin or PowerUser can create the root key and set access permissions.
Lookup "RegistrySecurity" in MSDN Help for examples on how to use it.
|
|
|
|
|
Dave,
Thanks for the response!
I think that what I need to do is (as an Admin user) is to install the application, start it and let the code see that the registry entries do not exist which will cause them to be created and then set them to the actual values I want for all users. Then when a normal user logs on and uses the PC, the registry entries will exist and he will be able to use the application. I can see that there are a few lines to tweak, but hopefully, not a big deal.
Thanks again for your help... it is most appreciated!
|
|
|
|
|
Dave,
After reading your response, I went back and did some digging and reqrote my code. However, i still seem to be having the same basic problem. I feel like I'm dancing all around the solution, but I just am not finding it. Here is the new code...
Imports Microsoft.Win32<br />
<br />
Public Class frmMain<br />
<br />
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
<br />
' Set regKey to point to HKEY_LOCAL_MACHINE<br />
regKey = Registry.LocalMachine<br />
' Create regSubKey to point to HKEY_LOCAL_MACHINE\Software\Liebert\RegistryTest<br />
regSubKey = regKey.OpenSubKey("Software\Liebert\RegistryTest", True)<br />
' Check if registry SubKey exists<br />
If (regSubKey Is Nothing) Then ' create SubKey<br />
regSubKey = regKey.CreateSubKey("Software\Liebert\RegistryTest")<br />
regSubKey.SetValue("pName", txtInitPortName.Text)<br />
regSubKey.SetValue("pBaud", txtInitPortBaud.Text)<br />
' Restart the application to make use of the new value pName<br />
MsgBox("Registry entries created!" & vbCrLf & "Application needs restarted!", MsgBoxStyle.OkOnly)<br />
End<br />
Else ' pName exists already, use it !<br />
txtPortName.Text = regSubKey.GetValue("pName")<br />
txtPortBaud.Text = regSubKey.GetValue("pBaud")<br />
End If<br />
<br />
End Sub<br />
<br />
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click<br />
<br />
End<br />
<br />
End Sub<br />
End Class
Again, I want my windows application to be run by myself the first time (as Admin on the machine). The application will check for the existence of the registry SubKey and if it does not exist (which it won't), it will create the SubKey (and also a couple of sample values just to see that it works. After creating the SubKey, the application will force a exit and I restart the application. This time, the registry SubKey exists and all the code does is to get the two values.
txtPortName.Text = regSubKey.GetValue("pName")
txtPortBaud.Text = regSubKey.GetValue("pBaud")
This all works fine for me as the user (Admin).
Now, I logoff and have someone else logon as a normal user. He then starts the application (the registry exists. He gets the following exception and does not read the values.
Note: I actually wanted to paste the messagebox in here for the exception, but couldn't figure out how.
Application attempted to perform an operation not allowed by the security policy. To grant this application the required permission, contact your system administrator, or use the Microsoft .NET Framework configuration tool.
If you click continue, the application will ignore the error and attampt to continue. If you click Quit, the application will quit immedately.
Requested registry access is not allowed.
In your previousmessage response, I thought that you implied that the normal user would be able to read the SubKey's values. Obviously, I'm missing something.
|
|
|
|
|
Your problem is that you're initially opening the subkey with write permissions by supplying the True argument to OpenSubKey :
' Create regSubKey to point to HKEY_LOCAL_MACHINE\Software\Liebert\RegistryTest
regSubKey = regKey.OpenSubKey("Software\Liebert\RegistryTest", True)
' Check if registry SubKey exists
If (regSubKey Is Nothing) Then ' create SubKey
and THEN you're checking to see if anything was returned. When a normal user runs that line of code, it'll fail because the user cannot open the key for write access.
Remove the True argument from that line and it'll run. Of course, you'll have to rewrite the code to find out if the key exists, then try and create the key path and values.
|
|
|
|
|
That makes sense! Hopefully, a little re-write and everything will be fine!
Thanks for all your help Dave!
|
|
|
|
|
I want to draw a graph in VB.NET.
I use visual studio 2005.
My problem is that I want to draw graph dynamically for every second
For Example: There is a person on bicycle who is going at different speeds at different times. And that data is simulated in VB
Now I want to draw a graph of speed vs time something like for fisrt second what is the speed (to be plotted on the graph) and for next second what is it and so on.
Could anyone please help me on this front.
Thank You
Edit/Delete Message
|
|
|
|
|
Google for "ZedGraph". The rest is easy, merely setting up the graph to look the way you want, then passing in the data every second. The graph draws itself.
|
|
|
|
|
Hi,
i want help in writing a savefunction in vb.net.
requirement is:
An array of hat objects is passed into the function. The hat in each object is then saved to the database table.The following properties are set in each hat object :objectID,date,quantity.
Table used is hat1
Parameter passed into the function is arrayhat which is an array of hat objects.
using .net2.0/vb.net/oracle.
Thanks
|
|
|
|
|
So what's the question?
You iterate over the collection of hat objects passed in, get the ID from the object, and check to see if it's in the database. If not, INSERT a new record in the database using the data supplied for that record. If it does exist, UPDATE the existing record. Better yet, this would probably be better suited as a stored procedure in the database. All you would have to do is pass in the 3 parameters to the procedure and it should do the appropriate checks and updates.
|
|
|
|
|
|
Hi:
My boss had selected a contractor. This was to be a "help" in my VB.Net 2005 project. The contractor was supposed to develop a sample GUI for control of an embedded box with a USB interface along with a user library. My boss requested me to provide a specification which i did.
The contractor IMHO ignored a few items in the specification. My exposure to VB.net has been part time during the past few years. What i was trying to specify was that i did not want code developed as DLL's because the delivered source code would be linkable into the main program code space and the VS.net debugger could be used to check values from the main application. I saw this as a method for development. My experience has been that the VS.Net debugger cannot directly examine the DLL code space. The contractor said we could use it this way but i have not been able to do this, does anyone have a method to do this?
Also the contractor said that the specification was confusing and that he developed the code as a DLL by mistake and that it will cost a lot of money for us to fix this. the specification section is below. (OPAL KELLY makes a USB prototype board as a commercial product and is not involved with the contract)
---------------------------------------------------------------------------------
Structure: Software routines shall be called to handle the functions locally. Software functions shall be defined in a local library for linking with discrete programs. DLL calls will be made only for linking to OPAL Kelly software or preexisting Software. The intent is to have subroutines defined that can be used with a Microsoft debugger and have “step into” capability which is not possible for DLL’s as released SW.
-----------------------------------------------------------------------------------
what are your opnions on this. I suspect i might have used better terminology but i think the intent is clear?
charlie
|
|
|
|
|
Yes, the debugger can step into .DLL code. A .DLL is just loaded as part of the process. It's no different than if the code was directly part of the .EXE's code. So long as the .DLL is a Debug build, with the debugging information shipped along with it, the debugger can step into the code with no problems.
A "local library for linking with discrete programs" screams .DLL to me. I don't see how an .EXE would fit this picture since .EXE's don't normally export library functions.
What language is this library written in?
Or did I misunderstand the situation??
|
|
|
|
|
Hi:
The Application code i am using is VB.net 2005, However the library is written in C.
From what you mentioned it looks like the debugger should be able to reference lines of code and values on that line for a "C" library.
Thanks for responding.
Charlie
|
|
|
|
|
The debugger can step into the C code base, but without debug information or the source code, you'll see the machine language representation of the code, not the original C source.
|
|
|
|
|
My project seemed simple.
1. Load a .dll into a separate appdomain
2. Use and unload it
3. Allow the user to modify the .dll via system.reflection
4. Repeat
Simply can't do it... any help appreciated. I'm working now with something like this, but it's very strange. This will not load from "c:\ma.dll" but always loads from the .dll in the current active directory instead. Also, simply cannot release the file after the unload.
Help greatly appreciated.
Dim SubDomain As AppDomain = AppDomain.CreateDomain("New Domain")
Dim s1 As FileStream = New FileStream("C:\ma.dll", FileMode.Open, FileAccess.Read)
Dim ms As MemoryStream = New MemoryStream(s1.Length)
Dim br As BinaryReader = New BinaryReader(s1)
Dim bytesRead As Byte() = br.ReadBytes(s1.Length)
ms.Write(bytesRead, 0, s1.Length)
Dim assembly As Assembly = Reflection.Assembly.ReflectionOnlyLoad(ms.ToArray)
Dim IndicatorClass = SubDomain.CreateInstanceAndUnwrap(assembly.FullName, "Indicators.Indicator")
AppDomain.Unload(SubDomain)
s1.Close()
br.Close()
ms.Dispose()
|
|
|
|
|
I've got an icon in a dropdownbox item, but it isn't in my image list. It was originally loaded from disk, but i've lost that original file. Is there any way to extract it so I can use it somewhere else?
Thanks!
|
|
|
|
|
I'm assuming all you have is the .EXE you want to pull the icon out of. Google for "ResEdit" or "Resource Editor".
|
|
|
|
|
No, I have the code itself. Should be easy I suppose, I just don't know how.
|
|
|
|
|
The image the project gets is from the image file itself. It's not stored anywhere else except cached by the IDE. If you close VS and reopen the project, the thumbnail image is reloaded from the original source file. There's no way to save the icon from the cached image you see inside the IDE.
|
|
|
|
|
Hi all,
I am using the following code:
<br />
Dim connectionString As String = "Initial Catalog=DATABASEName;Data Source=INSTANCENameIthink;Integrated Security=SSPI;"<br />
Dim cn As SqlConnection = New SqlConnection(connectionString)<br />
Dim sqlCommand As SqlCommand = New SqlCommand("SELECT * FROM StagingEmployer ORDER BY StagingDate", cn)<br />
cn.Open()<br />
Dim TestRowset As SqlDataReader = sqlCommand.ExecuteReader()<br />
<br />
While TestRowset.Read()<br />
If (Convert.ToString(TestRowset(35)) = "U") Then<br />
Dim sqlCommand2 As SqlCommand = New SqlCommand("UPDATE stagingEmployerTest SET" _<br />
+ " [Employer_Number] = '" + Convert.ToString(TestRowset(0)) _<br />
+ "', [Name] = '" + Convert.ToString(TestRowset(1)) _<br />
+ "', [Trading_Name] = '" + Convert.ToString(TestRowset(2)) _<br />
+ "', [Business_Number] = '" + Convert.ToString(TestRowset(3)) _<br />
+ "', [Company_Number] = '" + Convert.ToString(TestRowset(4)) _<br />
+ "', [Tax_File_Number] = '" + Convert.ToString(TestRowset(5)) _<br />
+ "', [Street_Address_1] = '" + Convert.ToString(TestRowset(6)) _<br />
+ "', [Street_Address_2] = '" + Convert.ToString(TestRowset(7)) _<br />
+ "', [Street_Address_3] = '" + Convert.ToString(TestRowset(8)) _<br />
+ "', [Street_Suburb] = '" + Convert.ToString(TestRowset(9)) _<br />
+ "', [Street_State] = '" + Convert.ToString(TestRowset(10)) _<br />
+ "', [Street_Postcode] = '" + Convert.ToString(TestRowset(11)) _<br />
+ "', [Street_Country] = '" + Convert.ToString(TestRowset(12)) _<br />
+ "', [Postal_Address_1] = '" + Convert.ToString(TestRowset(13)) _<br />
+ "', [Postal_Address_2] = '" + Convert.ToString(TestRowset(14)) _<br />
+ "', [Postal_Address_3] = '" + Convert.ToString(TestRowset(15)) _<br />
+ "', [Postal_Suburb] = '" + Convert.ToString(TestRowset(16)) _<br />
+ "', [Postal_State] = '" + Convert.ToString(TestRowset(17)) _<br />
+ "', [Postal_Postcode] = '" + Convert.ToString(TestRowset(18)) _<br />
+ "', [Postal_Country] = '" + Convert.ToString(TestRowset(19)) _<br />
+ "', [Contact_Name] = '" + Convert.ToString(TestRowset(20)) _<br />
+ "', [Contact_Title] = '" + Convert.ToString(TestRowset(21)) _<br />
+ "', [Contact_Salutation] = '" + Convert.ToString(TestRowset(22)) _<br />
+ "', [Phone] = '" + Convert.ToString(TestRowset(23)) _<br />
+ "', [Fax] = '" + Convert.ToString(TestRowset(24)) _<br />
+ "', [Email] = '" + Convert.ToString(TestRowset(25)) _<br />
+ "', [Broker] = '" + Convert.ToString(TestRowset(26)) _<br />
+ "', [Underwriter] = '" + Convert.ToString(TestRowset(27)) _<br />
+ "', [Diplomatic_Indemnity] = '" + Convert.ToString(TestRowset(28)) _<br />
+ "', [Status] = '" + Convert.ToString(TestRowset(29)) _<br />
+ "', [Image] = '" + Convert.ToString(TestRowset(30)) _<br />
+ "', [Created] = '" + Convert.ToString(TestRowset(31)) _<br />
+ "', [Created_By] = '" + Convert.ToString(TestRowset(32)) _<br />
+ "', [Modified] = '" + Convert.ToString(TestRowset(33)) _<br />
+ "', [Modified_By] = '" + Convert.ToString(TestRowset(34)) _<br />
+ "', [Action] = '" + Convert.ToString(TestRowset(35)) _<br />
+ "', [StagingDate] = '" + Convert.ToString(TestRowset(36)) + "'" _<br />
+ " WHERE [Employer_Number] = '" + Convert.ToString(TestRowset(0)) + "'")<br />
sqlCommand2.ExecuteScalar()<br />
End If<br />
MsgBox("Result :" + Convert.ToString(TestRowset(35)))<br />
End While<br />
<br />
<br />
' Close Reader and Connection.<br />
TestRowset.Close()<br />
cn.Close()<br />
Now the first section works fine... (the first select statement.) it returns 3 rows of data into my TestRowset.
Now why would the second section (the Update - SqlCommand2.ExecuteScalar() ) give the following error:
ExecuteScalar: Connection property has not been initialized.
???
what does this mean?
I have never done anything like this from scratch so this would be my first attempt.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
The error is pretty self-explanitory. When you created your first SqlCommand object, you told it what the SQL statement was it was supposed to execute AND you told it which SqlConnection object to use. When you created your second SqlCommand object, you never told it which SqlConnection to use, which I believe you called cn .
|
|
|
|
|
okay, thanks.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
hi all i have this function in my DAl that returns a dataset like this
Public Function Get_Data_Straight(ByVal strNumkey As String) As DataSet
Dim strSQl As String = "SELECT Primary_ID, Boundary_area, Attrib_Code, Lis_Key, Func_Key, Actual_Extent, Improved_Value, Site_Value, Purchase_price, Purchase_date, prop_id, confidence_score, fin_ls_prediction, new_lis_key, new_func_key, Tshwane_Prediction, matchflag, source, flagtype, Locked FROM Property_mass WHERE (SUBSTRING(Lis_Key, 1, 4) = @Lis_key) AND (Locked IS NULL)"
Dim constr As String = "user id=sde;Password=@@@@@@;Server=@@@@@@@@;persist security info=False;initial catalog=Tshwane_Valuations_Train"
Dim cmb As SqlCommandBuilder
Dim con As SqlConnection
Dim da As SqlDataAdapter
Dim cmd As SqlCommand
Dim ds As DataSet
Try
ds = New DataSet
con = New SqlConnection(constr)
con.Open()
'Inituializing the Connection Object
cmd = New SqlCommand(strSQl)
'Telling the connection object where is the Database
cmd.Connection = con
'Initializing the adapter
da = New SqlDataAdapter
'we tell the adapter which object we are using
da.SelectCommand = cmd
da.SelectCommand.Parameters.Add("@Lis_key", strNumkey)
' da.SelectCommand.Parameters.Add(New SqlParameter("@Lis_Key", strNumkey))
ds.Clear()
da.Fill(ds, "Property_Mass")
Catch ex As SqlClient.SqlException
MsgBox(ex.Message)
End Try
Return ds
End Function
and i display the results into the datagrid. well everything is working well. do i want to update the Grid when a change has been made. As Commandbuilder will generate a update query for me, i want to know, how am i going to use the commandbuilder in another function in the Dal that will be used to save the changes. is it ok, the way i have declared the command builder locally into the function, or should i make it a shared object so that the other function can access it when it want to update, or the other function is Supposed to create its own command builder.
The below is my update Function in my DAL
Public Sub UpdateLis_search_Straight(ByVal dsData As DataSet)
'update data in the actual database
Dim strSQl As String = "SELECT Primary_ID, Boundary_area, Attrib_Code, Lis_Key, Func_Key, Actual_Extent, Improved_Value, Site_Value, Purchase_price, Purchase_date, prop_id, confidence_score, fin_ls_prediction, new_lis_key, new_func_key, Tshwane_Prediction, matchflag, source, flagtype, Locked FROM Property_mass WHERE (SUBSTRING(Lis_Key, 1, 4) = @Lis_key) AND (Locked IS NULL)"
Dim constr As String = "user id=sde;Password=@@@@@@;Server=@@@@@@;persist security info=False;initial catalog=Tshwane_Valuations_Train"
Dim cmb As SqlCommandBuilder
Dim con As SqlConnection
Dim da As SqlDataAdapter
Dim cmd As SqlCommand
Try
da.UpdateCommand = cmb.GetUpdateCommand
da.Update(dsData)
'adpAccess.Update(dtbschemaDatabases)
Catch ex As SqlClient.SqlException
MsgBox(ex.Message)
End Try
End Sub
PLease help
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Your question doesn't make any sense. A CommandBuilder object will not work with the WHERE clause (as I've said before) you've specified. You're going to have to write the remaining SqlCommand objects (DELETE, INSERT, UPDATE) yourself (as I've said before) and add them to the DataAdapter.
I suggest writing a seperate method that does nothing but creates and builds this DataAdapter and returns it to the caller.
|
|
|
|
|
Am sorry Dave, i will write all myself, forget the short cut and Wizard\
Thanks for Pushing
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|