Discussion:
VBA, OCX and system folders
(too old to reply)
Clarence Klopfstein
2005-04-04 16:02:22 UTC
Permalink
If this isn't the right place to ask this, please redirect me to that place.

I have written an OCX component that will scan from a scanner. When I
try to use it within VBA and Microsoft Word it fails.

I have narrowed it down to the fact that it is not being granted access
to certain folders.

So when it tries to access the ds file in the C:\Windows\TWAIN_32 folder
it errors out. Is there a setting that would allow my OCX to be called
from VBA, but still get access to system files?

Another folder that it cannot get access to is the users temporary
folder: C:\Documents and Settings\Administrator\Local Settings\Temp

This puzzles me because that folder is pretty generic.

Thanks,
Clarence
Jean-Guy Marcil
2005-04-05 02:39:22 UTC
Permalink
Post by Clarence Klopfstein
If this isn't the right place to ask this, please redirect me to that place.
Perry, you missed this one!

Please, you asked the same question in 4 different groups, wait, I'll check
in other groups... Sorry, my bad... 5 groups.

Was that really necessary? In case you are new to posting in NG, doing this
means that potentially 5 different people will answer the same question,
meaning you have to follow up on 5 threads. Collectively, it means more work
for everybody, inlcuding yourself. Also, if you are satisfied with the first
one, you may well ignore the other 4... Then what about those 4 people who
gave some of their own time to try to help you?
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
***@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
c***@gmail.com
2005-04-05 21:23:24 UTC
Permalink
Post by Clarence Klopfstein
If this isn't the right place to ask this, please redirect me to that
place.
Post by Clarence Klopfstein
I have written an OCX component that will scan from a scanner. When
I try to use it within VBA and Microsoft Word it fails.
Post by Clarence Klopfstein
I have narrowed it down to the fact that it is not being granted
access to certain folders.
Post by Clarence Klopfstein
So when it tries to access the ds file in the C:\Windows\TWAIN_32
folder it errors out. Is there a setting that would allow my OCX to be
called from VBA, but still get access to system files?
Post by Clarence Klopfstein
Another folder that it cannot get access to is the users temporary
folder: C:\Documents and Settings\Administrator\Local Settings\Temp
Post by Clarence Klopfstein
This puzzles me because that folder is pretty generic.
Thanks,
Clarence
Perry Said:
Eventhough not always performing better than filesearch API's, WMI is a
robust way to get you a listing of files.
Here's some sample code of how to use WMI to get you a listing of files

Change sRootFolder to read the path you'd like to start querying from.
Don't forget to adjust the hardcoded root in sSQL...
Note: Path seperators in WMI are double backslashed.

sCompName = "."
sRootFolder = "c:\\ff"
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")

Set wmiFolders = oWMI.ExecQuery _
("Select * from Win32_Directory where Name Like '" _
& sRootFolder & "%'")

For Each fol in wmiFolders
Debug.Print "Folder: " & fol.Name
sTMP = Replace(Mid(fol.Name,4,Len(fol.Name)),"\","\\")
sSQL = "SELECT * FROM CIM_DataFile WHERE Drive = 'c:' " & _
"AND Path = '\\" & sTMP & "\\'"
Set wmiFiles = oWMI.ExecQuery(strQuery)
On Error Resume Next
For Each oFile in wmiFiles
Debug.Print "File: " & oFile.Name
Next
Next

Krgrds,
Perry

-----------My reply
Sorry for posting incorrectly earlier. My newsgroup program was being
cranky, so I couldn't get it to post all at once. This is actually the
third time I have tried to post this reply. Hopefully Google Groups
will work.

That being said don't understand how this reply is at all an answer to
my question. I am not worried about listing files. I just want access
to call the ds files in the Windows/TWAIN_32 folder. For some reason
VBA is not letting my external OCX "talk" to a lot of files. For
example, I have an INI file in the temp directory. It will not let me
write to that file if it is in the temp directoy. But if I move the
ini to the C:/ drive it works just fine, but I still can't talk to the
ds files, so it makes my scanning application worthless in VBA.

Could it be that my OCX needs to be digitally signed? Could M$ see my
OCX as a security threat?

Thanks,
Clarence
Perry
2005-04-05 21:39:07 UTC
Permalink
Post by c***@gmail.com
That being said don't understand how this reply is at all an answer to
my question.
WMI gets access to system folders where are other filelisting
techniques/mechanisms can't ...
Not getting back the content of particular system folders such as Twain_32
is regular behaviour of
other filelisting techniques. Again, WMI does.

Krgrds,
Perry
Post by c***@gmail.com
Post by Clarence Klopfstein
If this isn't the right place to ask this, please redirect me to that
place.
Post by Clarence Klopfstein
I have written an OCX component that will scan from a scanner. When
I try to use it within VBA and Microsoft Word it fails.
Post by Clarence Klopfstein
I have narrowed it down to the fact that it is not being granted
access to certain folders.
Post by Clarence Klopfstein
So when it tries to access the ds file in the C:\Windows\TWAIN_32
folder it errors out. Is there a setting that would allow my OCX to be
called from VBA, but still get access to system files?
Post by Clarence Klopfstein
Another folder that it cannot get access to is the users temporary
folder: C:\Documents and Settings\Administrator\Local Settings\Temp
Post by Clarence Klopfstein
This puzzles me because that folder is pretty generic.
Thanks,
Clarence
Eventhough not always performing better than filesearch API's, WMI is a
robust way to get you a listing of files.
Here's some sample code of how to use WMI to get you a listing of files
Change sRootFolder to read the path you'd like to start querying from.
Don't forget to adjust the hardcoded root in sSQL...
Note: Path seperators in WMI are double backslashed.
sCompName = "."
sRootFolder = "c:\\ff"
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
Set wmiFolders = oWMI.ExecQuery _
("Select * from Win32_Directory where Name Like '" _
& sRootFolder & "%'")
For Each fol in wmiFolders
Debug.Print "Folder: " & fol.Name
sTMP = Replace(Mid(fol.Name,4,Len(fol.Name)),"\","\\")
sSQL = "SELECT * FROM CIM_DataFile WHERE Drive = 'c:' " & _
"AND Path = '\\" & sTMP & "\\'"
Set wmiFiles = oWMI.ExecQuery(strQuery)
On Error Resume Next
For Each oFile in wmiFiles
Debug.Print "File: " & oFile.Name
Next
Next
Krgrds,
Perry
-----------My reply
Sorry for posting incorrectly earlier. My newsgroup program was being
cranky, so I couldn't get it to post all at once. This is actually the
third time I have tried to post this reply. Hopefully Google Groups
will work.
That being said don't understand how this reply is at all an answer to
my question. I am not worried about listing files. I just want access
to call the ds files in the Windows/TWAIN_32 folder. For some reason
VBA is not letting my external OCX "talk" to a lot of files. For
example, I have an INI file in the temp directory. It will not let me
write to that file if it is in the temp directoy. But if I move the
ini to the C:/ drive it works just fine, but I still can't talk to the
ds files, so it makes my scanning application worthless in VBA.
Could it be that my OCX needs to be digitally signed? Could M$ see my
OCX as a security threat?
Thanks,
Clarence
Clarence Klopfstein
2005-04-05 23:35:51 UTC
Permalink
Post by Perry
Post by c***@gmail.com
That being said don't understand how this reply is at all an answer to
my question.
WMI gets access to system folders where are other filelisting
techniques/mechanisms can't ...
Not getting back the content of particular system folders such as Twain_32
is regular behaviour of
other filelisting techniques. Again, WMI does.
Krgrds,
Perry
I will give it a shot and see what happens.
Clarence Klopfstein
2005-04-06 18:12:57 UTC
Permalink
Post by Clarence Klopfstein
I will give it a shot and see what happens.
Well I implemented it, but get the same error. Here is the code, did I
do it correctly?

Dim sCompName
sCompName = "cknotebook"
sRootFolder = "C:\\WINDOWS\\twain_32\\Lexmark\\4200 Series"
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")

Set wmiFolders = oWMI.ExecQuery _
("Select * from Win32_Directory where Name Like '" _
& sRootFolder & "%'")

For Each fol In wmiFolders
sTMP = Replace(Mid(fol.Name, 4, Len(fol.Name)), "\", "\\")
sSQL = "SELECT * FROM CIM_DataFile WHERE Drive = 'c:' " & _
"AND Path = '\\" & sTMP & "\\'"
Set wmiFiles = oWMI.ExecQuery(sSQL)
On Error Resume Next
For Each oFile In wmiFiles
Debug.Print "File: " & oFile.Name
Next
Next


Set dScan = CreateObject("ARTCOPYSDK.ArtcopySDKCtrl.1")
dScan..... 'Do stuff with the object here.

End Sub
Clarence Klopfstein
2005-04-06 21:36:06 UTC
Permalink
Aha, ok then try to raise the authentication level by
Replace
Post by c***@gmail.com
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
By
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate," _
& "{authenticationLevel=pkt}!\\"
& sCompName & "\root\cimv2")
If this fails, something else must be bugging you ...
Krgrds,
Perry
Perry,
Your code has a couple syntax errors. Can you tell me where the closing
} goes? Also you were missing a (_) on the third line.
Perry
2005-04-07 17:35:35 UTC
Permalink
1) Set oWMI = GetObject("winmgmts:" _
2) & "{impersonationLevel=impersonate," _
3) & "{authenticationLevel=pkt}!\\" _
4) & sCompName & "\root\cimv2")

Line continuation on line 3
Post by Jean-Guy Marcil
Aha, ok then try to raise the authentication level by
Replace
Post by c***@gmail.com
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
By
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate," _
& "{authenticationLevel=pkt}!\\"
& sCompName & "\root\cimv2")
If this fails, something else must be bugging you ...
Krgrds,
Perry
Perry,
Your code has a couple syntax errors. Can you tell me where the closing
} goes? Also you were missing a (_) on the third line.
Clarence Klopfstein
2005-04-08 15:07:52 UTC
Permalink
Post by Perry
1) Set oWMI = GetObject("winmgmts:" _
2) & "{impersonationLevel=impersonate," _
3) & "{authenticationLevel=pkt}!\\" _
4) & sCompName & "\root\cimv2")
Line continuation on line 3
Post by Jean-Guy Marcil
Aha, ok then try to raise the authentication level by
Replace
Post by c***@gmail.com
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
By
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate," _
& "{authenticationLevel=pkt}!\\"
& sCompName & "\root\cimv2")
If this fails, something else must be bugging you ...
Krgrds,
Perry
Perry,
Your code has a couple syntax errors. Can you tell me where the closing
} goes? Also you were missing a (_) on the third line.
But I see two opening brackets "{" and only one closing bracket "}" is
that by design? I understood the continuation syntax issue.
Perry
2005-04-09 01:20:45 UTC
Permalink
Remove the opening { bracket on line 2
Sorry for inconvenience

Krgrds,
Perry
Post by Clarence Klopfstein
Post by Perry
1) Set oWMI = GetObject("winmgmts:" _
2) & "{impersonationLevel=impersonate," _
3) & "{authenticationLevel=pkt}!\\" _
4) & sCompName & "\root\cimv2")
Line continuation on line 3
Post by Jean-Guy Marcil
Aha, ok then try to raise the authentication level by
Replace
Post by c***@gmail.com
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
By
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate," _
& "{authenticationLevel=pkt}!\\"
& sCompName & "\root\cimv2")
If this fails, something else must be bugging you ...
Krgrds,
Perry
Perry,
Your code has a couple syntax errors. Can you tell me where the closing
} goes? Also you were missing a (_) on the third line.
But I see two opening brackets "{" and only one closing bracket "}" is
that by design? I understood the continuation syntax issue.
Perry
2005-04-09 01:26:14 UTC
Permalink
It's far too late:
:-(

Previous message: read Line 3 not Line 2
Post by Perry
Sorry for inconvenience
Remove the opening { bracket on line 2
Sorry for inconvenience
Krgrds,
Perry
Post by Clarence Klopfstein
Post by Perry
1) Set oWMI = GetObject("winmgmts:" _
2) & "{impersonationLevel=impersonate," _
3) & "{authenticationLevel=pkt}!\\" _
4) & sCompName & "\root\cimv2")
Line continuation on line 3
Post by Jean-Guy Marcil
Aha, ok then try to raise the authentication level by
Replace
Post by c***@gmail.com
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
By
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate," _
& "{authenticationLevel=pkt}!\\"
& sCompName & "\root\cimv2")
If this fails, something else must be bugging you ...
Krgrds,
Perry
Perry,
Your code has a couple syntax errors. Can you tell me where the closing
} goes? Also you were missing a (_) on the third line.
But I see two opening brackets "{" and only one closing bracket "}" is
that by design? I understood the continuation syntax issue.
Clarence Klopfstein
2005-04-09 04:21:31 UTC
Permalink
Post by Perry
Remove the opening { bracket on line 2
Sorry for inconvenience
Krgrds,
Perry
Thanks!

I will try this first thing Monday. I do appreciate all your help with
this issue.

ck

Perry
2005-04-06 21:18:02 UTC
Permalink
Aha, ok then try to raise the authentication level by

Replace
Post by c***@gmail.com
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
By
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate," _
& "{authenticationLevel=pkt}!\\"
& sCompName & "\root\cimv2")

If this fails, something else must be bugging you ...

Krgrds,
Perry
Post by c***@gmail.com
Post by Clarence Klopfstein
I will give it a shot and see what happens.
Well I implemented it, but get the same error. Here is the code, did I
do it correctly?
Dim sCompName
sCompName = "cknotebook"
sRootFolder = "C:\\WINDOWS\\twain_32\\Lexmark\\4200 Series"
Set oWMI = _
GetObject("winmgmts:\\" & sCompName & "\root\cimv2")
Set wmiFolders = oWMI.ExecQuery _
("Select * from Win32_Directory where Name Like '" _
& sRootFolder & "%'")
For Each fol In wmiFolders
sTMP = Replace(Mid(fol.Name, 4, Len(fol.Name)), "\", "\\")
sSQL = "SELECT * FROM CIM_DataFile WHERE Drive = 'c:' " & _
"AND Path = '\\" & sTMP & "\\'"
Set wmiFiles = oWMI.ExecQuery(sSQL)
On Error Resume Next
For Each oFile In wmiFiles
Debug.Print "File: " & oFile.Name
Next
Next
Set dScan = CreateObject("ARTCOPYSDK.ArtcopySDKCtrl.1")
dScan..... 'Do stuff with the object here.
End Sub
Loading...