473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Need to turn on file extension in windows within Access VBA

489 256MB
I'm using the ImportZippedFile to unzip files from within my Access application, however I've run into a problem that I don't know if I can fix.
In the ImportZippedFile it looks for the extension of the file in order to unzip the it. I had a client that the extension in windows was turned off so the unzip didn't work. I'm wondering is there a way to turn file extensions on from within my application. If you need the full code for the ImportZippedFile let me know and I'll post it.

Thanks for any help.
Sep 27 '17 #1

✓ answered by ADezii

  1. This one is a little tricky, Tom. You can accomplish this by using the WshShell Object which enables you to interact with various aspects of the Windows Shell.
  2. The Logic is as follows:
    1. You must query a specific Registry Key is see if the Hide extensions for known file types is ON or OFF (1 or 0). You can use the RegRead() Method of the WshShell Object.
    2. If this Option is ON (1), then you must turn it OFF via the RegWrite() Method of the WshShell Object.
    3. After enabling File Extension and performing your operations(s), you may wish to return it to its prior state.
  3. Enough rambling on, the Code to do this is listed below:
    Expand|Select|Wrap|Line Numbers
    1. Dim WshShell As Object
    2. Dim strRegKey As String
    3.  
    4. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt"
    5.  
    6. Set WshShell = CreateObject("WScript.Shell")
    7.  
    8. If WshShell.RegRead(strRegKey) Then
    9.   WshShell.RegWrite strRegKey, 0, "REG_DWORD"
    10. End If
  4. Good Luck with your Project.

15 2227
NeoPa
32,556 Expert Mod 16PB
Can you be a little more precise. I know of configuring extensions but 'turning them on' means nothing to me.
Sep 28 '17 #2
PhilOfWalton
1,430 Expert 1GB
This may help.

Basically I think you have to change

HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\Advanced registry subkey.

In the registry.

There are lots of examples of how to do this on the web.

Phil
Sep 28 '17 #3
ADezii
8,834 Expert 8TB
  1. This one is a little tricky, Tom. You can accomplish this by using the WshShell Object which enables you to interact with various aspects of the Windows Shell.
  2. The Logic is as follows:
    1. You must query a specific Registry Key is see if the Hide extensions for known file types is ON or OFF (1 or 0). You can use the RegRead() Method of the WshShell Object.
    2. If this Option is ON (1), then you must turn it OFF via the RegWrite() Method of the WshShell Object.
    3. After enabling File Extension and performing your operations(s), you may wish to return it to its prior state.
  3. Enough rambling on, the Code to do this is listed below:
    Expand|Select|Wrap|Line Numbers
    1. Dim WshShell As Object
    2. Dim strRegKey As String
    3.  
    4. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt"
    5.  
    6. Set WshShell = CreateObject("WScript.Shell")
    7.  
    8. If WshShell.RegRead(strRegKey) Then
    9.   WshShell.RegWrite strRegKey, 0, "REG_DWORD"
    10. End If
  4. Good Luck with your Project.
Sep 28 '17 #4
CD Tom
489 256MB
Well that works sometimes, I don't know why. Here's what I did, I went into Explorer and turned off the file extension. Then I ran my program and your code turned the file extension On, I have your code in the ImportZippedfile routing at the very beginning. I still get the unzip problem because the extension is still off. When I look in the Windows Explorer I see that the file extension is turned On but the file extension of the files don't show. If I turn the file extension off and then on again it works.
Any ideas what I'm doing wrong.
Sep 28 '17 #5
Rabbit
12,516 Expert Mod 8TB
You probably need to kill and restart the explorer process.
Sep 28 '17 #6
ADezii
8,834 Expert 8TB
A simple Refresh of the Explorer Window (F5) should do the trick. There should be no need to close and re-open Explorer, I think (LOL).
Sep 28 '17 #7
CD Tom
489 256MB
is there a way to do a refresh from with the Access VBA.
Sep 28 '17 #8
ADezii
8,834 Expert 8TB
You would probably have to retrieve the Window Handle of Windows Explores and send it a Message to Close. Will look into this tomorrow if I have a chance.
Sep 28 '17 #9
CD Tom
489 256MB
Thanks, looking forward to seeing how this could be done.
Sep 28 '17 #10
ADezii
8,834 Expert 8TB
  1. This was a little tougher than I realized, but I do believe that I have come up with a solution. It involves the following Steps:
    1. If Hide file extensions is turned ON, then Reset this Option to OFF.
    2. Find the Explorer Window and retrieve it's Handle.
    3. MAXIMIZE the Explorer Window.
    4. Send the F5 Keystroke (Refresh) to the Explorer Window.
  2. Required Declarations:
    Expand|Select|Wrap|Line Numbers
    1. Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
    2. Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
    3. Public Const SW_SHOWMAXIMIZED = 3
  3. Code Definition:
    Expand|Select|Wrap|Line Numbers
    1. Dim WshShell As Object
    2. Dim strRegKey As String
    3. Dim lngHnd As LongPtr
    4. Dim lngRetVal As Long
    5.  
    6. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt"
    7.  
    8. Set WshShell = CreateObject("WScript.Shell")
    9.  
    10. If WshShell.RegRead(strRegKey) Then
    11.   WshShell.RegWrite strRegKey, 0, "REG_DWORD"   'Enable File Extensions
    12.  
    13.   lngHnd = FindWindow("CabinetWClass", vbNullString)      'Find Windows Explorer
    14.   lngRetVal = ShowWindow(lngHnd, SW_SHOWMAXIMIZED)        'MAXIMIZE Windows Explorer
    15.  
    16.   WshShell.SendKeys "{F5}"        'Pass the F5 Key to Windows Explorer
    17. End If
    18.  
    19. Set WshShell = Nothing
Sep 29 '17 #11
CD Tom
489 256MB
This would seem to work except I get an error on the LongPtr do I need some new reference?
Sep 29 '17 #12
CD Tom
489 256MB
I still can't get this to work here's the code
Expand|Select|Wrap|Line Numbers
  1. Dim WshShell as Object
  2. Dim strRegKey as String
  3. Dim lngHnd As longPtr
  4. dim lngRetVal as long
  5.  
  6. strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt"
  7. Set WshShell = CreateObject("WScript.Shell")
  8. If WshShell.RegRead(strRegKey) then
  9. WshShell.RegWrite strRegKey, 1, "REG_DWORD"
  10. lngHnd = FindWindow("CabinetWClass", vbNullString)
  11. lngRetVal = ShowWindow(lnghnd, SW_SHOWMAXIMIZED)
  12. WshShell.Sendkeys "(F5)"
  13. endif
  14. Set WshShell = nothing
  15.  
  16.  
I have set the extension in Explorer to 0 manually to test this
As I walk through the program (F8) it seems to go through everything until I get to the WshShell.SendKeys "(F5)" that command just writes a F5 on the next line of the code. If I look at the options in Explorer the hideFileExt still shows 0. No change.
I also get an error on the LongPtr I've changed it to just Long
I'm about ready to give up on this.
What do you think.
Sep 29 '17 #13
ADezii
8,834 Expert 8TB
The correct Syntax for SendKeys is
Expand|Select|Wrap|Line Numbers
  1. WshShell.SendKeys "{F5}" 
not
Expand|Select|Wrap|Line Numbers
  1. WshShell.SendKeys "(F5)" 
Let me know how this works out, we're almost there. It works fine on my end, so must be a small adjustment on yours.
Sep 29 '17 #14
CD Tom
489 256MB
Well that was some difference I didn't notice the difference at first and was about to tell you it didn't work. when I looked closer I could see they were not ( but { when I made that change it worked. Thank you so much.
Sep 29 '17 #15
ADezii
8,834 Expert 8TB
You are quite welcome, Tom. This was a tough one, gonna take a break now (LOL).
Sep 29 '17 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Terence | last post by:
A curious observation: I have my apache web server configured for the PHP apache module to parse files ending in the .php extension. nothing unusual about that, but I also noticed that if I...
1
by: knutsample | last post by:
Hello! I'm trying to associate a file extension to my wxPython script so that all I have to do is double click on the file and my python script will load up with the path of that file. For...
1
by: bailee220 | last post by:
I have included the following code to open an Access database form from within an exsisting Access database. But when I run the code, it appears that it opens the database because in windows...
3
by: Les Desser | last post by:
In A97 I am trying to determine some attributes of files in a folder - Date, time, file size and file name. To this end I have managed to create a batch file to do a Dir to a work file (and then...
3
by: David | last post by:
Should you be able to map a any file extension to the ASP.NET dll and have it execute ASP.NET script, just like an .aspx page, when it is requested by a browser. If not, why bother giving us the...
1
by: Brett Romero | last post by:
I'm trying to associate a file extension to a program I've created. I have browsed for the program in Windows Explorer | Tools | Options and set it there. However, Windows always keeps Notepad...
2
by: JDeats | last post by:
When a user double clicks on file item in Windows Explorer, Windows tries to open the document with whatever application is related to it's file extension. In my WinForms application I would...
2
by: dazzler | last post by:
I need to open PDF file with my python application, and I'm using os.startfile(filename.pdf) command, I would need open command act 100% like clicking the file in the windows explorer python...
5
by: argonautical | last post by:
We are using some Access databases in v2003 format where the file extension is not the default .mdb. We've customized the extension and have registered that with Access so it will open when...
16
by: accessnewbie90 | last post by:
I tried to run SoundRecorder.exe (located in C:\Windows\System32\SoundRecorder.exe) in windows 7 using a command box in access but for some strange reason I get a Run time 53 error saying that the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.