From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a file with a password

Solved!
Go to solution

Hi all,

 

In my application I create Excel files using the "Open/create/replace file" vi.

These files contain data from my tests.

I want to protect these files with a password, so that an unauthorized person will not be able to open them OUTSIDE OF LABVIEW.

 

Can this be done ?

Otherwise, is there any way to make sure unauthorized persons can only open these files as "read only" + can not save them with a different name and then change them ?

 

Thanks in advance,

Mentos.

0 Kudos
Message 1 of 12
(9,828 Views)

Hi,

 

This can be done in Windows scripting using the workbookobject savas method see here

so I expect that it can be done useing either ActiveX or .Net however I suspect this is not a trival exersise.

 

Some other method

 

1) download a free password protect program (maybe winzip), there are plenty about and after saving your file, run said program using system_exec.vi to protect your excel file

 

2) There is an Openg LabVIEW  ZIP toolkit  that will allow you to zip up your file while adding a password and you just unzip it when you want to read it back.

 

3) if you are not worried about people reading the file but only really need to ensure nobody else has change it, you could look at using the OpenG MD5 toolkit  and save the MD5 sigunture somewhere. There is also a NI MD5 option

 

cheers 

 

Dannyt

 

Danny Thomson AshVire Ltd
0 Kudos
Message 2 of 12
(9,807 Views)

Hi Danny,

 

Thanks for the prompt reply.

 

a) Zipping the files with a password is a nice idea. However, in my application I'm adding a new line to my data files about every 15 seconds. So unzipping the file in order to write a new line and then zipping it again each time doesn't seem so adequate for this kind of application.

 

b) Regarding the MD5 option: I'm not familiar with it but if I understand correctly it's used to get a file checksum. I guess I can use it to see if my files has been modified, but what I want to do is that unauthorized persons will not be able to save the file after they changed something. I don't care if they open and see it, I just need the file the be kept unchanged.

 

c) It will be great if you can be more specific regarding the first method (Activate-X or .Net) which I'm not really familiar with.

 

Thanks,

Mementos.

0 Kudos
Message 3 of 12
(9,780 Views)

Hi Danny,

you shoult think about writing your data into a database. You can create user accounts with different rights and the 15 seconds shouldn't be a problem.

 

Mike

0 Kudos
Message 4 of 12
(9,777 Views)

Hi,

 

I'd like to try a different approach:

 

1) Manually save an Excel file with a password, containing titles only without any data

2) Open this password  protected file from Labview using Invoke node methods as seen in the left sequence on the attached VI

3) Programmatically write new data to this open file using the "write text file vi", as seen in the right sequence on the attached VI.

 

The problem is I can't connect the automation reference out from the invoke node to the regular files vi ("set file position" etc). I also can't use the open/create/replace file vi because the file is already opened.

 

Does any one know how can I combine these two parts ?

Otherwise, how can I write to the open file using the method reference out instead of using the regular file VIs ?

 

Thanks,

Mementos.

0 Kudos
Message 5 of 12
(9,729 Views)

You can't use Write Text File because an Excel workbook is not a textfile.  It is a proprietary format binary file.

 

1.  Open Excel.

2.  Use ActiveX methods and properties to manipulate the open workbook.

3.  Save the work book.

4.  Close Excel.

 

Pay attention to the order you close your references.  You need to close them in the reverse order you open them.  Write now you are closing your application reference about simultaneously with trying to open the Excel workbook.  Even if the write to text file stuff would have worked, it wouldn't because you are closing the Excel  workbook before you get to the sequence frame that has the Write to Text file code.

0 Kudos
Message 6 of 12
(9,724 Views)

I'm not too familiar with ActiveX methods.

 

Can you please attach an example of how to open, then write something to the opened workbook, and then close  it ?

 

 

0 Kudos
Message 7 of 12
(9,712 Views)

I've attached a speedily compiled library of some fairly general VIs I use for communicating with Excel using ActiveX. They have been written in LabVIEW 6.1 but even if you can't use them as they are, you should be able to see what I'm doing.

 

Hope it helps somewhat.



Never say "Oops." Always say "Ah, interesting!"

Message 8 of 12
(9,697 Views)

These are great help! thanks.

 

Could you clarify if there's a property node/invoke node for the following actions:

 

1) Checking the number of rows in the opened excel file

2) If I can open a password protected file, isn't there a way to save a NEW file with a password ?

 

 

0 Kudos
Message 9 of 12
(9,671 Views)
Solution
Accepted by topic author Mentos

Hi Mentos,

 

to 1)

http://forums.ni.com/ni/board/message?board.id=170&message.id=333106&query.id=33090#M333106

 

to 2)

You can use the Workbook reference. Use an invoke node with the "save as" method.

 

Mike

Message 10 of 12
(9,666 Views)