Page 1 of 1

Terminal Services

Posted: Thu Dec 28, 2006 11:21 am
by Davide
Hello all,

1) is there a function which tells me if Terminal Services are installed on a server in application mode ?
I know OS_IsWTSClient() to retrieve if the application is running on a Terminal session, but I would need to know it on the server console.

2) When Terminal Services are installed, the GetWinDir() function retrieves a different directory for each user: "C:\Documents and Settings\<user name>\WINDOWS"
Is it possible to retrieve which is the real Windows directory, typically "C:\WINDOWS" ?

Thank you,
Davide.

Re: Terminal Services

Posted: Wed Jan 03, 2007 12:57 am
by Davide
Solved. I hope this could help someone else:
1) is there a function which tells me if Terminal Services are installed on a server in application mode ?
I know OS_IsWTSClient() to retrieve if the application is running on a Terminal session, but I would need to know it on the server console.

Code: Select all

Function IsWtsEnabled()
Return ( GetWinDir() <> GetSystemWindowsDirectory() )
2) When Terminal Services are installed, the GetWinDir() function retrieves a different directory for each user: "C:\Documents and Settings\<user name>\WINDOWS"
Is it possible to retrieve which is the real Windows directory, typically "C:\WINDOWS" ?

Code: Select all

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( GETSYSTEMWINDOWSDIRECTORY )
{
    CHAR Buffer[ MAX_PATH ];

    GetSystemWindowsDirectory( Buffer, MAX_PATH );

    hb_retc( Buffer );
}

#pragma ENDDUMP
Hi,
Davide.

Posted: Wed Jan 03, 2007 6:52 am
by Antonio Linares
Davide,

Thanks,

Posted: Wed Jan 03, 2007 11:56 am
by Davide
As it works only for Terminal Server enabled OS's (no 9x/ME), here is a function which takes care of the different cases.
I do not have a NT4 Terminal Server to test. If you can test it ...

Hi,
Davide.

Code: Select all

Function RealWinDir()
Local cDir,i

If IsWin95()                         // No Terminal Services
  cDir:=GetWinDir()   
Else
  IF ( "NT" $ cWinVersion() )  // Windows NT is different
    cDir:=GetSysDir()
    i:=RAT("\system32",Lower(cDir)) ; cDir:=Left(cDir,i-1)
  Else
    cDir:=GetSysWinDir()  // ok XP,2000,2003 
  Endif
Endif
Return cDir


#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"


HB_FUNC( GETSYSWINDIR )
{
    CHAR Buffer[ MAX_PATH ];

    GetSystemWindowsDirectory( Buffer, MAX_PATH );

    hb_retc( Buffer );
}

#pragma ENDDUMP


Posted: Sat Jan 13, 2007 9:46 pm
by concentra
Davide, did you have success in getting the IP address of the TS client ?

MaurĂ­cio Faria

Posted: Sat Jan 13, 2007 10:51 pm
by Davide
MaurĂ­cio,
concentra wrote:Davide, did you have success in getting the IP address of the TS client ?
I don't need that info. In order to recognize the clients I use NetName(.t.)

Hi,
Davide

Urgent please.

Posted: Fri Mar 09, 2007 11:41 am
by Davide
On Windows 98 the EXE does not start because GetWindowsSystemDirectoryA is not included in Kernel32.dll (even thought in RealWinDir() it's not called in Win98)

How can I do to exclude that part if I'm on 98 (or to use the GetWinDir() instead) ?

Urgent please !

Thanks
Davide

Code: Select all

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

HB_FUNC( GETSYSWINDIR )
{
    CHAR Buffer[ MAX_PATH ];

    GetSystemWindowsDirectory( Buffer, MAX_PATH );

    hb_retc( Buffer );
}

#pragma ENDDUMP


Posted: Fri Mar 09, 2007 12:38 pm
by Antonio Linares
Davide,

Use dynamic linking:

DLL FUNCTION ...

instead of the FW built in function

Posted: Fri Mar 09, 2007 1:12 pm
by Davide
Antonio,
Antonio Linares wrote:Use dynamic linking:

DLL FUNCTION ...
I cannot have it working without an Harbour exception:

Code: Select all

DLL32 Function GetSysWinDir( lpBuffer AS LPSTR , uSize AS DWORD ) AS LPSTR ;
                             PASCAL FROM "GetSystemWindowsDirectoryA" LIB "kernel32.dll"
what's wrong ?

Thanks,
Davide.

Posted: Fri Mar 09, 2007 2:13 pm
by Davide
what's wrong ?
ok, I've found it. Here's the function:

Code: Select all

FUNCTION GetSysWinDir()

     Local cBuffer := Space(261)
     Local nLen

     nLen := GetSystemWindowsDirectory( @cBuffer, Len(cBuffer) )

RETURN Left(cBuffer, nLen)

//----------------------------------------------------------------------------//

DLL32 Function GetSystemWindowsDirectory( lpBuffer AS LPSTR , uSize AS DWORD ) AS DWORD ;
                   PASCAL FROM "GetSystemWindowsDirectoryA" LIB "kernel32.dll"

//----------------------------------------------------------------------------//
I'm going to test it on the different OS's, unless you already see something wrong in it.

Regards,
Davide

Posted: Fri Mar 09, 2007 2:46 pm
by Antonio Linares
Davide,

It looks fine