NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
LelandDurrette
Posts: 18
0 Kudos

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.

Member
KyleP
Posts: 129
0 Kudos

Re: Unable to write to registry keys

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
Member
LelandDurrette
Posts: 18
0 Kudos

Re: Unable to write to registry keys

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?

Member
LelandDurrette
Posts: 18

Re: Unable to write to registry keys

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.

Member
KyleP
Posts: 129
0 Kudos

Re: Unable to write to registry keys

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
Member
LelandDurrette
Posts: 18
0 Kudos

Re: Unable to write to registry keys

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

Trusted Enthusiast
RobertoBozzolo
Posts: 4,534
0 Kudos

Rif.: Unable to write to registry keys

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.




Using LW/CVI from 3.1 on.

My contributions to the Developer Zone Community
________________________________________
If I have helped you, why not giving a kudos?
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page