Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 21st, 2007, 06:02 AM
Authorized User
 
Join Date: Aug 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Password protected files

I have created approx 500 workbooks containing sensitive data and passworded them with individual passwords (contained in a password table). I have sent these workbooks out to users who will complete and return these workbooks to me. I intend to process these workbooks upon their return using an Excel VBA macro.
Assuming the user does not change the filename i am able to open the returned file by looking up the filename in my password table. All good so far.
My problem occurs when a user changes the filename meaning that my macro can not find a matching password and so can not open or process the file.

Where can i store a unique file reference in a passworded file that i can read without knowing the password and which will then enable me to lookup the password from my table? And what would the code to do this look like?
Reply With Quote
  #2 (permalink)  
Old August 21st, 2007, 02:17 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I changed the title of a workbook under Properties (which I could only do while it was unprotected). In VBA I was able to use:
Code:
    Dim w As Workbook
    Set w = _
            Application. _
            Workbooks. _
            Open("C:\Documents and Settings\" & _
                 "<Me >\Desktop\" & _
                 "ProtectedBook.xls")
                 I was then able to read
Code:
    w.BuiltinDocumentProperties("Title").value
to read the title. So you could open the files found in a certain location, then use the documents properties to uniquely identify the specific file that you are working with, and use that property to find the right password in your list.
Reply With Quote
  #3 (permalink)  
Old August 22nd, 2007, 04:40 AM
Authorized User
 
Join Date: Aug 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian but your solution requires the file to be opened before reading the Title property.
I can not do this as i won't know the password before opening it. What i need is some way of reading the Title property (or any other file property where i can store a password "hint") without opening the passworded file first.

I appreciate that this may not be possible but remain hopeful.
Thanks for trying though.

Reply With Quote
  #4 (permalink)  
Old August 22nd, 2007, 04:43 AM
Authorized User
 
Join Date: Aug 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just had a thought - perhaps i was not clear in that the workbooks are not just "protected" but the files themselves are "passworded" against being opened without a password. This makes it an altogether tougher problem.

Would really appreciate an help anyone can give....

Reply With Quote
  #5 (permalink)  
Old August 22nd, 2007, 04:01 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Quote:
quote:Thanks Brian but your solution requires the file to be opened before reading the Title property.
I can not do this as i won't know the password before opening it.
I tried this before I posted the message. I was able to get that property information without using any password info. I think the file properties are outside the password fence.

(Perhaps you are using a different password mechanism provided by Excel than the one I used though...)
Reply With Quote
  #6 (permalink)  
Old August 22nd, 2007, 04:04 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

OK, I answered the one post, then read what was after it...

Tell me how you established the password protection, and let me see what I can do with a horse of that stripe.
Reply With Quote
  #7 (permalink)  
Old August 22nd, 2007, 05:11 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

OK, I believe I have your answer

I created a .xls file, and saved it. While saving, I used the Save dlg's ability to password protect, and protected to open (not merely to modify).

Then I created a VBA project.
I added a reference to "Microsoft Shell Controls and Automation"
(C:\Winnt\System32\shell32.dll)

Then I added the following code, and ran it from the Debug window
Code:
Public Sub ab()

    Dim i       As Integer
    Dim sh      As New Shell   ' This class comes rom Shell32
    Dim FldrItm As FolderItem  ' This class comes rom Shell32
    Dim fldr    As Folder      ' This class comes rom Shell32

    Set fldr = sh.NameSpace("C:\ . . . \My Documents\")
    Set FldrItm = fldr.ParseName("Book1.xls")

    For i = 0 To 30
        Debug.Print i, fldr.GetDetailsOf(FldrItm, i)
    Next i

End Sub
The result I got was as follows (bold items are ones that I added in the File|Properties... in Excel before saving)
Code:
  0           Book1.xls
  1           14 KB
  2           Microsoft Excel Worksheet
  3           8/22/2007 14:17
  4           A
  5           These are the Comments
  6           8/22/2007 14:15
  7           8/22/2007 14:17
  8           NADSUSWE\brian.wren
  9           
 10           brian.wren
 11           This is the Title
 12           This is the Subject
 13           This is the Category
 14           
 15           
 16           
 17           
 18           
 19           
 20           
 21           
 22           
 23           
 24           
 25           
 26           
 27           
 28           
 29           
 30
Obviously, you can choose where you would like to stash your identifying data, but you can read these properties without having the password for the file...
Reply With Quote
  #8 (permalink)  
Old August 23rd, 2007, 04:53 AM
Authorized User
 
Join Date: Aug 2007
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for this Brian. It works perfectly - sheer genius.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Protected IE mrzoab C# 2 September 7th, 2007 07:47 AM
Password protected directory somnath.kartic ASP.NET 1.0 and 1.1 Basics 1 April 18th, 2006 01:49 PM
Connect to password protected Database abhisheksud ASP.NET 1.0 and 1.1 Basics 2 October 7th, 2005 04:43 PM
Password Protected Forums spooky012017 Dreamweaver (all versions) 4 July 24th, 2004 02:19 AM
Password protected message board thutt Dreamweaver (all versions) 4 March 19th, 2004 05:00 AM



All times are GMT -4. The time now is 06:49 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.