Page 1 of 1

Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 9:26 am
by PatrickWeisser
Hello Everyone,

We distribute a chm help file with our LAN-based FiveWin application. Nothing is installed on the workstations except a desktop launch icon. I know that Microsoft no longer allows chm help files to be opened across a network share for security reasons. From what I've read there are two approaches to supporting network-based chm access. One is to make registry changes for each workstation, and the other is simply to make a copy of the chm file on each workstation's local drive. I think I'm tending toward the second approach because making registry changes on customer's machines just to get our help to work is a bit much. Each time our FiveWin application launches on a workstation it could always check the network share it is running across for a newer chm file than what is on the workstation drive, and update the workstation copy as needed.

Since some network administrators severely limit each user's access to their own machine's hard drive, it would be best to use one of the pre-defined Windows folders meant to store application data files, such as c:\Documents And Settings\. But of course it's not a good idea to hard code folder paths because these folders could be different in the various versions of Windows, or even spelled differently for localized versions of Windows.

Does anyone know if there is a way in FiveWin to query the Window's internals to get literal strings for the pre-defined Windows folders on the current machine? There is a function in Windows called SHGetFolderPath(). If you pass it a constant like CSIDL_COMMON_APPDATA it will return a pointer to a string that is a folder on the local machine which can be used for shared application data. I guess I'm looking for something like that but at the FiveWin/Harbour level.

Thanks!

Re: Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 10:11 am
by IBTC
Hi Patrick,
PatrickWeisser wrote: I guess I'm looking for something like that but at the FiveWin/Harbour level.
Maybe this helps you with Harbour:

Code: Select all

#define CSIDL_PERSONAL       0x0005
#define SHGFP_TYPE_CURRENT   0

FUNCTION GETDOCUMENTSDIR()

   LOCAL sBuffer := SPACE(255)

   IF Os_IsWin2000_Or_Later()
      DllCall( "shell32.dll", DLL_OSAPI, "SHGetFolderPathA", 0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, @sBuffer )
      sBuffer := ALLTRIM( STRTRAN( sBuffer, CHR(0), "" ) )
   ELSE
      sBuffer := "C:\My Documents"
   ENDIF

RETURN( sBuffer )
 

Re: Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 1:05 pm
by StefanHaupt
Patrick,

this may be a solution
http://didierdanse.net/blogs/dev_en/arc ... ntent.aspx
I also experienced this problem, on Windows 7, 64-bit. I had to add the UNC path (\\drive\share) to my Trusted Sites zone and set (in HKLM\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions) MaxAllowedZone to 0x02, not 0x01. I hope that this helps someone else. Source: KB 896054, which has a handy table of which MaxAllowedZone settings enable which zones (higher numbers are more permissive). Another SuperUser question, number 69863, also tells how to turn off the "Open File Security Warning" nag message.
This registry patch may also help

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
"MaxAllowedZone"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions]
"UrlAllowList"=\\\\[server name]\\[share name]\\[path];file://\\\\[server name]\\[share name]\\[path];

Re: Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 4:17 pm
by PatrickWeisser
Hello Ruediger,

Thanks so much for the code -- it looks like what I was thinking of doing. Can you tell me what the value is for the constant DLL_OSAPI? It was not defined in your code sample. Also, DllCall() is undefined, did you mean CallDll()?

Also Stefan thanks very much for your reply. If I decide to go the registry route that looks like a good solution.

-Patrick

Re: Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 4:44 pm
by IBTC
Hi Patrick,
PatrickWeisser wrote: Can you tell me what the value is for the constant DLL_OSAPI?
It is in the Harbour file \contrib\hbxpp\dll.ch

Code: Select all

#define DLL_CDECL                   0x08
#define DLL_STDCALL                 0x20
#define DLL_SYSTEM                  0x04
#if defined( __PLATFORM__WINDOWS )
#define DLL_OSAPI                   DLL_STDCALL
#elif defined( __PLATFORM__OS2 )
#define DLL_OSAPI                   DLL_SYSTEM
#else
#define DLL_OSAPI                   DLL_CDECL
#endif
PatrickWeisser wrote: Also, DllCall() is undefined, did you mean CallDll()?
You have to link e.g. the Harbour file \lib\win\bcc\hbxpp.lib

But you can also use this:

Code: Select all

FUNCTION GETDOCUMENTSDIR()

   LOCAL sBuffer

   IF Os_IsWin2000_Or_Later()
      sBuffer :=  HB_GETDOCUMENTSDIR()
   ELSE
      sBuffer := "C:\My Documents"
   ENDIF

RETURN( sBuffer )

#pragma BEGINDUMP

#include <windows.h>
#include <shlobj.h>
#include <hbapi.h>

#define CSIDL_PERSONAL       0x0005
#define SHGFP_TYPE_CURRENT   0

HB_FUNC( HB_GETDOCUMENTSDIR )
{
   char  sBuffer[ MAX_PATH ];
   char *pBuffer=sBuffer;

   SHGetFolderPath( 0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, sBuffer );

   hb_retc( pBuffer );
}
#pragma ENDDUMP
 

Re: Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 5:01 pm
by kennedyv
Windows maintains a number of environment variables which might prove useful. Use the GetEnv() funtion to access these.

eg

GenEnv("ALLUSERSPROFILE")
GetEnv("APPDATA")
GetEnv("CommonProgramFiles")
GetEnv("HOMEDRIVE")+GetEnv("HOMEPATH")
GetEnv("USERPROFILE")

Re: Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 6:36 pm
by PatrickWeisser
Thanks Ruediger, that second code sample worked perfectly with the FiveWin/Harbour install I have. It's exactly what I was looking for!

And Kennedy thanks for your suggestion about using the GetEnv() function -- that also works great!

-Patrick

Re: Supporting CHM files across a network share

Posted: Wed Feb 09, 2011 7:38 pm
by Carles
P,

Can try this other way...

Code: Select all

#include "FiveWin.ch"
*--------------
FUNCTION Main()
*--------------
     LOCAL oShell := TOleAuto():New( "WScript.Shell" )

     msginfo( oShell:SpecialFolders( 'DESKTOP' ) )
     msginfo( oShell:SpecialFolders( 'MYDOCUMENTS' ) )

RETU .T.