FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour StringFromCLSID
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
StringFromCLSID
Posted: Tue Sep 16, 2014 10:18 AM
What's wrong with this code?

Code (fw): Select all Collapse
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
LPSTR hb_oleWideToAnsi( BSTR wString );
HB_FUNC( STRINGFROMCLSID )
   {
   LPOLESTR pOleStr;
   LPSTR * psz;
   StringFromCLSID( ( REFCLSID ) hb_parnl( 1 ), &pOleStr );
   hb_retc( psz = hb_oleWideToAnsi( pOleStr ) );
   hb_xfree( psz );
   }
#pragma ENDDUMP


Getting the error: Operands of = have illegal types 'char * *' and 'char *'.

TIA
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: StringFromCLSID
Posted: Tue Sep 16, 2014 01:48 PM

Frank,

Please try this:

StringFromCLSID( ( REFCLSID ) hb_parnl( 1 ), pOleStr );

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: StringFromCLSID
Posted: Tue Sep 16, 2014 01:50 PM

This seems to be the right fix:

hb_retc( psz = hb_oleWideToAnsi( pOleStr ) );

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: StringFromCLSID
Posted: Tue Sep 16, 2014 03:09 PM

Antonio,

same error as before :-(

Nothing changed in your second reply?

Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: StringFromCLSID
Posted: Wed Sep 17, 2014 07:28 AM
Frank,

Code (fw): Select all Collapse
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>

LPSTR hb_oleWideToAnsi( BSTR wString );

HB_FUNC( STRINGFROMCLSID )
   {
   LPOLESTR pOleStr;
   LPSTR * psz;
   StringFromCLSID( ( REFCLSID ) hb_parnl( 1 ), &pOleStr );
   hb_retc( ( char * ) psz = hb_oleWideToAnsi( ( BSTR ) pOleStr ) );
   hb_xfree( psz );
   }
#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: StringFromCLSID
Posted: Wed Sep 17, 2014 11:28 AM
Antonio,

ok, no more error :-)

I want to retrieve the <objectSID> from a LDAP directory:

Code (fw): Select all Collapse
FUNCTION Retrieve_Ldap()
   ...
   cobjectSID := STRINGFROMCLSID( oRecordset:Fields( "objectSID" ) :Value
   ...
RETURN NIL


But the resulting value is always '???????????????'!

Perhaps you have once again an idea whats wrong?
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: StringFromCLSID
Posted: Wed Sep 17, 2014 01:30 PM

Frank,

What value do you have here ?

MsgInfo( oRecordset:Fields( "objectSID" ):Value )

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: StringFromCLSID
Posted: Wed Sep 17, 2014 02:25 PM
Antonio,

the value is always empty!

I tried to solve it via a Recordset, enhancing the sample code from Carles from here: http://forums.fivetechsupport.com/viewtopic.php?p=50298 by simple adding the two fields <objectGUID> and <objectSID> in the SELECT-Statement:

Code (fw): Select all Collapse
      cString    := "SELECT "                    + ;
                    " userPrincipalName,"        + ;
                    " displayName,"              + ;
                    " memberOf,"                 + ;
                    " distinguishedName,"        + ;
                    " mail,"                     + ;
                    " objectGUID,"               + ;
                    " objectSID,"                + ;
                    " telephoneNumber,"          + ;
                    " mobile,"                   + ;
                    " facsimileTelephoneNumber," + ;
                    " otherTelephone,"           + ;
                    " department,"               + ;
                    " userAccountControl,"       + ;
                    " sAMAccountname"


It doesn't work, what a pity :-)
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: StringFromCLSID
Posted: Thu Sep 18, 2014 11:51 AM
Antonio,

just found this code:
Code (fw): Select all Collapse
Dim X as IADs
Dim con As New Connection, rs As New Recordset
Dim MyUser As IADsUser
 
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider", "CN=Test,CN=Users,DC=Fabrikam,DC=COM,O=INTERNET", "Password"
Set rs = con.Execute("<LDAP://MyMachine/DC=MyDomain,DC=Fabrikam,DC=com>;(objectClass=User);ADsPath;onelevel")
 
While Not rs.EOF
    ' Bind to the object to make changes 
    ' to it because ADO is currently read-only.
    MyUser = GetObject(rs.Fields(0).Value)
    MyUser.AccountDisabled = True
    MyUser.SetInfo
    rs.MoveNext
Wend

here: http://msdn.microsoft.com/en-us/library/aa746471%28v=vs.85%29.aspx

So, maybe it's possible to do something like this in FiveWin:
Code (fw): Select all Collapse
oMyUser := GetObject(rs:Fields(0).Value)
cobjectSID := STRINGFROMCLSID( oMyUser:objecSID() )

But how to translate 'GetObject()' at this point???
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: StringFromCLSID
Posted: Thu Sep 18, 2014 05:34 PM

Frank,

what are you trying to do from your code ?

Are you trying to check the existing ADO connections and choose one to open it ?

If so, please check FWH\samples\fivedbu.prg the way it lets you do that.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: StringFromCLSID
Posted: Thu Sep 18, 2014 05:47 PM
Antonio,

I'm only trying to read out the 'objectSID' from users within a LDAP directory, getting an ADO connection and a RecordSet is not the problem!

It's very easy with Powershell, for example: http://stackoverflow.com/questions/19904086/powershell-script-for-ad-users-sid, but looking for a solution within my app :-)
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: StringFromCLSID
Posted: Fri Sep 19, 2014 09:35 AM
Is this what you are looking for ?

http://msdn.microsoft.com/en-us/library/aa366106(v=vs.85).aspx

Could you please try it ? thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: StringFromCLSID
Posted: Fri Sep 19, 2014 02:15 PM

Frank

Check out Francisco's LDAP code from a recent thread.

Rick Lipkin

viewtopic.php?f=3t=29279

&

Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: StringFromCLSID
Posted: Mon Sep 22, 2014 07:57 AM
Rick,

this function returns an array with all account names and their associated SID's:
Code (fw): Select all Collapse
FUNCTION WMI_Win32_Account()
   // The Win32_Account abstract WMI class contains information about user accounts and group accounts known to the Windows system. 
   // User or group names recognized by a Windows NT domain are descendents (or members) of this class. The Win32_Account class is not included in a default hardware inventory operation.
   LOCAL oWMI
   LOCAL objWMI
   LOCAL oAccounts
   LOCAL aAccounts := {}
   LOCAL objWMIService
   LOCAL objItem
   oWMI := WMI_Check()
   IF !HB_IsNIL( oWMI )
      objWMI:= oWMI:ConnectServer()
      CursorWait ()
      oAccounts:= objWMI:ExecQuery( "SELECT * FROM Win32_Account" )
      FOR EACH objItem IN oAccounts
         AAdd ( aAccounts, { cValToChar( objItem:NAME ), cValToChar( objItem:SID ) } )
      NEXT
      CursorArrow()
      ASort( aAccounts,,, { |x,y| x[ 1 ] < y[ 1 ] } )
   ELSE
      ? "WMI not installed"
   ENDIF
RETURN ( aAccounts )


Solved :-)
Many thanks to Antonio, Rick, Francisco and Stefan
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: StringFromCLSID
Posted: Mon Sep 22, 2014 01:45 PM

Frank

Thanks for your example !!!

Rick Lipkin