PC Review


Reply
Thread Tools Rate Thread

detect password protected mdb's

 
 
J. Freed
Guest
Posts: n/a
 
      13th Aug 2008
I have a program that reads the contents of MSysObjects from different mdb's
and copies them into another mdb. Since the program will be reading several
thousand mdb's it has to run unattended into the night. Problem: when it hits
a password-protected file it stops to wait for someone to type in a
password/cancel. Is there a way to programmatically detect password-protected
files without actually opening them? TIA.......
 
Reply With Quote
 
 
 
 
Dirk Goldgar
Guest
Posts: n/a
 
      13th Aug 2008
(re-sending because my original reply hasn't appeared)

"J. Freed" <(E-Mail Removed)> wrote in message
news:E52F50E9-4FDD-4C39-A1A0-(E-Mail Removed)...
>I have a program that reads the contents of MSysObjects from different
>mdb's
> and copies them into another mdb. Since the program will be reading
> several
> thousand mdb's it has to run unattended into the night. Problem: when it
> hits
> a password-protected file it stops to wait for someone to type in a
> password/cancel. Is there a way to programmatically detect
> password-protected
> files without actually opening them? TIA.......



You could attempt to open each database in code and trap the error if you
can't. For example,

Dim db As DAO.Database
Dim strDBPath As String

On Error Resume Next

' Demo test of unsecured DB.
strDBPath = "C:\Users\Dirk\Documents\Unsecured.mdb"
Err.Clear
Set db = Application.DBEngine.OpenDatabase(strDBPath, , True)
If Err.Number <> 0 Then
Debug.Print "Can't open '" & strDBPath & _
"'. Error was " & Err.Number & ": " & Err.Description
Else
' Opened okay, so close it.
Debug.Print "Opened '" & strDBPath & "'"
db.Close
End If

' Demo test of DB with password.
strDBPath = "C:\Users\Dirk\Documents\Passworded.mdb"
Err.Clear
Set db = Application.DBEngine.OpenDatabase(strDBPath, , True)
If Err.Number <> 0 Then
Debug.Print "Can't open '" & strDBPath & _
"'. Error was " & Err.Number & ": " & Err.Description
Else
' Opened okay.
Debug.Print "Opened '" & strDBPath & "'"
db.Close
End If

' Demo test of DB with User-Level Security.
strDBPath = "C:\Users\Dirk\Documents\ULS_Secured.mdb"
Err.Clear
Set db = Application.DBEngine.OpenDatabase(strDBPath, , True)
If Err.Number <> 0 Then
Debug.Print "Can't open '" & strDBPath & _
"'. Error was " & Err.Number & ": " & Err.Description
Else
' Opened okay.
Debug.Print "Opened '" & strDBPath & "'"
db.Close
End If

The above code can be expected to display the following lines in the
Immediate window:

Opened 'C:\Users\Dirk\Documents\Unsecured.mdb'
Can't open 'C:\Users\Dirk\Documents\Passworded.mdb'. Error was 3031:
Not a valid password.
Can't open 'C:\Users\Dirk\Documents\ULS_Secured.mdb'. Error was 3033:
You do not have the necessary permissions to use the
''C:\Users\Dirk\Documents\ULS_Secured.mdb' object. Have your system
administrator or the person who created this object establish the
appropriate permissions for you..


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
Chris O''Neill
Guest
Posts: n/a
 
      26th Aug 2008
"Dirk Goldgar" wrote:

> You could attempt to open each database in code and trap the error if you
> can't. For example,


[SNIP!]

This is a related question...

I'm trying to open another database and edit a field in a table. The table
(tblLicense) has been set using ULS to ReadDesign/ReadData/UpdateData
permissions for a special username that I'm using in my code. My code goes
something like this (after all the Dim statements):

'********* Start Code Snippet ***********
Set db = OpenDatabase("c:\Program Files\Balloon Business Management
System\balloons_secured_DATA_DEMO.mdb", , ,
"UID=Username_Here;PWD=Password_Here")
Set rs = db.OpenRecordset("tblLicense", dbOpenDynaset)

With rs
Debug.Print !AppVersion
.Edit
!AppVersion = "1.01"
.Update
Debug.Print !AppVersion
End With
Set rs = Nothing
Set db = Nothing
'********* End Code Snippet ***********

The code runs fine until it gets to the ".Edit" line and then bombs with a
3033 error message, even though it appears to be opening the database with
the right username and password.

What am I doing wrong??? As always, any help and suggestions provided are
greatly appreciated!

Regards, Chris

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      27th Aug 2008
"Chris O''Neill" <(E-Mail Removed)> wrote in message
news:1CA663EC-29C5-4C82-B2A2-(E-Mail Removed)...
> "Dirk Goldgar" wrote:
>
>> You could attempt to open each database in code and trap the error if you
>> can't. For example,

>
> [SNIP!]
>
> This is a related question...
>
> I'm trying to open another database and edit a field in a table. The
> table
> (tblLicense) has been set using ULS to ReadDesign/ReadData/UpdateData
> permissions for a special username that I'm using in my code. My code
> goes
> something like this (after all the Dim statements):
>
> '********* Start Code Snippet ***********
> Set db = OpenDatabase("c:\Program Files\Balloon Business Management
> System\balloons_secured_DATA_DEMO.mdb", , ,
> "UID=Username_Here;PWD=Password_Here")
> Set rs = db.OpenRecordset("tblLicense", dbOpenDynaset)
>
> With rs
> Debug.Print !AppVersion
> .Edit
> !AppVersion = "1.01"
> .Update
> Debug.Print !AppVersion
> End With
> Set rs = Nothing
> Set db = Nothing
> '********* End Code Snippet ***********
>
> The code runs fine until it gets to the ".Edit" line and then bombs with a
> 3033 error message, even though it appears to be opening the database with
> the right username and password.
>
> What am I doing wrong??? As always, any help and suggestions provided are
> greatly appreciated!



Is the database in which you're running this code using the same workgroup
file as the secured database you're trying to open? My guess is not, though
it's possible they're both using system.mdw. In general, to open a database
that has been secured with user-level security, you have to use the DBEngine
or PrivDBEngine object to specify the workgroup file (SystemDB), user, and
password. Something like this:

'----- start of code -----

Dim dbe As New PrivDBEngine
Dim db As DAO.Database

Dim strFolder As String
Dim strDBName As String
Dim strWorkgroup As String

strFolder = C:\Program Files\Balloon Business Management System\"
strDBName = "balloons_secured_DATA_DEMO.mdb"
strWorkgroup = "balloons.mdw"

With dbe
.SystemDB = strFolder & strWorkgroup
.DefaultUser = "Username_Here"
.DefaultPassword = "Password_Here"
Set db = .OpenDatabase(strFolder & strDBName)
End With

Set rs = db.OpenRecordset("tblLicense", dbOpenDynaset)
With rs
Debug.Print !AppVersion
.Edit
!AppVersion = "1.01"
.Update
Debug.Print !AppVersion
.Close
End With
Set rs = Nothing

db.Close
Set db = Nothing
Set dbe = Nothing

'----- end of code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to detect protected sheet IanC Microsoft Excel Programming 4 29th Sep 2009 07:13 PM
Detect IE 7 Protected mode using javascript John Windows Vista Security 0 28th Sep 2008 11:33 AM
Programatically detect Password protected pst files ashwin Microsoft Outlook 1 10th Jan 2007 02:01 PM
IE7 detect protected mode in script Ty Windows Vista Security 2 9th Nov 2006 05:44 AM
Re: Can you detect a password-protected doc? Cindy Meister -WordMVP- Microsoft Word Document Management 0 9th Aug 2003 03:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 AM.