LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Distibution Build

Dear All,

I have made an install for an application developped with CVI Labwindows 2013.

The intalled application works fine, but when I try to read a file on the insttaled application, the file is read even that it is not exsisting in that directory.

I explain:

The installed direcotry is located in "C:\Program Files (x86)\Install:"

and the file name is data.dat

so the full path of the file is fullPath="C:\Program Files (x86)\Install\data.dat"

I get the full name of the file with GetProjectDir function.

 

I check  the avalability of that  file with:

file_exist=FileExists(fullPath, &fileSize);

 

Mysterious, the file exists even that I could not find it in the install direcotry: "C:\Program Files (x86)\Install:"

The file is not hidded, as I displayed all the hidden files.

 

I realy would like to know how is the file is read from the path even that it does not exist.

 

Best regards.

 

 

0 Kudos
Message 1 of 6
(4,994 Views)

Hello hapiest!

 

I suspect that the reason why the functions you are using are not able to correctly determine whether the file exists or not is due to the manner in which you declared your path string. In C, if you add a backslash ('\') character in a string, this will escape the next character, meaning that it will indicate that it is a special character (e.g. '\t' means tabs, '\n' means newline, etc.). So if you want to write a string path containing the actual slashes that are found in paths, you have to escape them as well: '\\'. So your path should really be written like this:

char *fullPath="C:\\Program Files (x86)\\Install\\data.dat";

 

I also think that you should change the title of this post if possible, since your issue is linked to checking for file paths rather than distribution builds.

 

Best regards!

- Johannes

0 Kudos
Message 2 of 6
(4,980 Views)

Thank you for your answer, but:

my application works fine on a local, and the issue is produced in the distribution build. It is why I did the title "Distribution Build", but I can change it. (Done).

 

I get the name of the file by using functions, and I did not use it manually. So, I did this following code to get the full name of the file:

fileName = "data.dat";
    if (GetProjectDir (projectDir) < 0){
        FmtOut ("Project is untitled\n");
    }else{
         MakePathname (projectDir, fileName, fullPath);// where fullPath has the following format: c:\myproject\data.dat

    }

 

I followed the instruction given in: http://zone.ni.com/reference/en-XX/help/370051P-01/cvi/libref/cvigetprojectdir/

 

The issue is that the function file_exist=FileExists(fullPath, &fileSize); tells me that the file exists, even that I could not see it or open it on the target directory. The file is not hidden.

 

 

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

Hi,

I think your problem is related to system protection of program files folder.

New version of windows Windows (i think from win7 or Vista) protect the program files folder to be read only for normal applications. If application write to this folder without elevated access rights, the file write is redirected to somewhere in "c:\ProgramData" folder.

This can lead to serious problems:invisible file, two files with the same name-one is read, second is used for write only, acess rights problem.

(problems occurs especialy when you sometimes run the application with and without elevated rights - "run as administrator")

 

Anyway, application should not store read/write data in program files directory. This is less known rule but its there minimaly from WinX or maybe older).

Reccomended way is to use SHGetFolderPath WinApi function to get the right path to store application data.

 

If you cannot change this in source code of application, you can easily bypass this protection by installing the application to nonsystem folder, for example "c:\MyPrograms\AppName"

 

I hope this help.

Message 4 of 6
(4,956 Views)

Thnak you for your suggestion.

I would use the SHGetFolderPath function, but I I think this function is includede in the shell32.lib.

Is this function exisit in CVI 2015, because I could not find it in National Insturment folders?

Is there a location which I shoud look to include this library?

0 Kudos
Message 5 of 6
(4,943 Views)

Thank you for your explanation, and your suggestion, it is definitly the problem of the right access.

My application is still in the Program Files Folder, and to bypass the issue fo right access, as you have said, I have created the file in "C:/App" folder, and as I have rights on that folder, I can read/write the files in the "C:/App" folder.


Now, I would like to know if there is a possibility to delete this folder "C:/App" and its files when the applications is installed or unistalled?

I would like to delete all the files and folders created by my application when this applications is installed or when it is unistalled.

 

Best regards

0 Kudos
Message 6 of 6
(4,934 Views)