LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI Security and Windows API functions - ShGetFolder

Solved!
Go to solution

Hi there,

 

Let me explain what I am doing.

 

In order to secure a program and ensure it can be only installed on a single computer; I read the MAC address of the PC, manipulate the MAC address to produce an Activation code.  The user provides me thier MAC address and I provide them the Activation code for them to enter.

 

The issue is where to store the Activation code.  I am using LV 8.0 and Vista but the software could be deployed to machines using XP or 2000.  Previously I had decided to use the Windows registry to store the Activation code.  However, I have since discovered that when I write to the registry in Vista the entry is nowhere to be found.  I can read it ok but cannot find it.  Where is it in Vista?  A search of the registry won't locate it.  I can find it in XP ok.

 

I need a reliable location to place the Activation code once users have entered it.  I have seen suggestions of using the Windows API function ShGetKnownFolderPath (Vista) and ShGetFolder (XP, does it work for 2000?).  These functions would enable me to do what?

 

How can I use the Windows API fnctions such as ShGetFolder?  I have no idea.

 

Please help.

 

Thanks.

0 Kudos
Message 1 of 20
(4,769 Views)

Hi battler.,

you can store the activation code near you application. Maybe in the ini file, which will automatically generate by the application.

 

Mike

Message 2 of 20
(4,759 Views)

Are you running as Administrator under Vista? I believe that Vista has restrictions on registry access (even reading) if you're not running as an admin. I think there's also the issue that even if you're logged in as an admin, Vista tries to run apps using a reduced set of permissions.

 

You should also be aware that LabVIEW 8.0 is not officially compatible with Vista. LabVIEW 8.2.1 was the first one to be marked as such by NI.

Message 3 of 20
(4,748 Views)

Where in the registry did you try to write your key?

As smercurio said, under Vista access to the registry is quite different from XP. Even if you have administrative privileges, you can't write to HKEY_LOCAL_MACHINE (except when explicitely running an application with administrative privileges, like you do with an installer for instance). You can only read from there (to read, make sure you use read-only access when opening the registry key!).

You can write to HKEY_CURRENT_USER though.

 

Hope this helps,

Daniel

 

Message Edited by dan_u on 07-25-2009 11:59 PM
Message 4 of 20
(4,726 Views)
Solution
Accepted by battler.

Continuation of last post...

Probably HKEY_CURRENT_USER will work for you. It's a bit difficult though when different Vista users use the application.

 

Be careful with Mike's suggestion. By default it's not possible to write to the Program Files folder (again, unless you run the application as admin or you grant full access to the folder/file to the user or the "Authenticated Users" group).

 

The application data folder might also be a good location to store it. To get the path you should use the Windows API to return the folder path. An implementation of this can be found on LAVA (post #7).

 

Hope this helps,

Daniel

 

Message 5 of 20
(4,723 Views)

I'm reading/writing to LOCAL MACHINE\Software in Vista.  It seems to be working but I can't find the entry when I use VI registry functions.  When I make registry entries as part of installer it works ok.

 

You say that I cannot write to the Programs folder.  What about the applications folder, isn't that in the Programs folder?  I suppose writing to the apps folder is a safer option.

0 Kudos
Message 6 of 20
(4,715 Views)

This discussion if getting very confusing since it's also being discussed in the new thread.

 

Please pick a place. 

Message 7 of 20
(4,690 Views)

battler. wrote:

I'm reading/writing to LOCAL MACHINE\Software in Vista.  It seems to be working but I can't find the entry when I use VI registry functions.  When I make registry entries as part of installer it works ok.

 


Yes, during installation you can write to HKLM because the installer runs with admin rights. Do you open the key read-only when trying to read it?

 


battler. wrote: 

You say that I cannot write to the Programs folder.  What about the applications folder, isn't that in the Programs folder?  I suppose writing to the apps folder is a safer option.


The application data folder is NOT the program files folder.

In XP by default it is: C:\Documents and Settings\All Users\Application Data\<YOUR_APP>

In Vista: C:\ProgramData\<YOUR_APP>

 

But don't use these fixed paths, use the SHGetFolders (the VI I referred to in my last post does that for you).

 

 

Message 8 of 20
(4,672 Views)

All I know about are the program files folder and that seems to be where programs are installed.

 

Can't I use the VI location function to set a relative path to the installation folder?

 

I even tried joining LAVA to retrieve that ShGetFolder example; can't find it.  It would seem the search function on LAVA is dismal compared to here.  Let me know if you can help. 

0 Kudos
Message 9 of 20
(4,641 Views)

Here's the VI.

Use "COMMON_APPDATA" as CSIDL and append a folder for your application.

 

 

Message 10 of 20
(4,628 Views)