LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to write to registry keys

Greetings:

I'm using LabWindows v8.5.0 installed on a Windows 7 machine.  In my application, I can read from both String and number registry key using RegReadString and RegReadULong, but when I try to write to the keys using RegWriteString and RegWriteULong, the function returns a zero indicating it was successful, but the data is not in the registry.  I've changed permissions on the key to allow full control to all users listed, but it still doesn't work.  Am I missing something?

 

int RegWriteNum(char *key, unsigned long int val)
{
  int ret;
  char *err;
  char buf[128];
 
  ret = RegWriteULong (REGKEY_HKLM, "Software\\Me\\Test", key, val, 0);

  if (ret < 0)
  {
    err = GetGeneralErrorString(ret);
    sprintf(buf, "Registry Read error (%s): %s", key, err);
    LogEntry(MOD_SVC, buf);
  }
 
  return(ret);
}

When I put a breakpoint on the function call, 'key' and 'val' are correct.  The function returns '0', but data is not in the registry.

 

Thanks.

0 Kudos
Message 1 of 7
(5,021 Views)

Hi LelandDurette,

 

When you open LabWindows/CVI, have you tried right-clicking on the shortcut and selecting "Run As Administrator"?

 

Cheers,

KyleP
Applications Engineer
National Instruments
0 Kudos
Message 2 of 7
(5,014 Views)

Thanks, Kyle.  That indeed worked.  I would not have thought about trying that for two reasons:  (1) I changed the permissions on the key to allow full control for all users, and (2) my login account is an administrator account.  It doesn't make sense that either of those would still not allow a registry key to be modified.  Any idea what the difference in "run as administrator" and being logged in as administrator is?

0 Kudos
Message 3 of 7
(5,002 Views)

You can disregard the previous question; I read an article online that somewhat answered my lack of understanding.  It would help if I could encounter an article somewhere that explained, briefly, what to look out for in the different versions of Windows.  I do have another question though:  I read where the OS allows for applications to request a higher privilege; can you point me toward a library function in LabWindows 8.5 that I can incorporate in my application?  Thanks for your help.

Message 4 of 7
(4,999 Views)

I found an article which describes you can set a program to be Ran As Administrator by default. If that's not sufficient for what you're looking for, could you give me some documentation on the higher privilege request that you're referring to? I'm not familiar.

 

Cheers,

KyleP
Applications Engineer
National Instruments
0 Kudos
Message 5 of 7
(4,987 Views)

I'm sure there is a property on the shortcut for running as Admin, and I can do that.  The article I read mentioned that the recent change (with Vista) was that when an Administrator account logs in, there are two security tokens:  one is the normal level that any non-Admin login account gets, and the other is the higher-priviledge token for being an Administrator.  The lower level token is the one used by default, and when Run as Administrator is selected, the higher-level token is used.  It had verbage that indicated the program itself could request the higher-priviledge token, and I recall running some apps that create a popup relating to the higher priviledge token, so they indeed request the higher-level token themselves.  I was wondering if LabWindows had a Library function that would do that.

 

I appreciate the help; I'll sign-off on this one.  Till next time ...

-Leland

0 Kudos
Message 6 of 7
(4,977 Views)

I Leland, I read you are running under WIn7 so I thought sharing this discussion with you can be of help: the key point is that starting from Vista on direct acces to the registry is discouraged by Microsoft, which provides different locations where to put data your application needs. This discussion also can clarify some concept.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 7
(4,974 Views)