﻿<rss version="2.0"><channel><title>ot4xb.examples (readonly)</title><link>http://news.xb2.net/ot4xb.examples</link><description>ot4xb.examples (readonly)</description><lastBuildDate>Fri, 21 Nov 2008 18:35:42 GMT</lastBuildDate><generator>MPNews http://www.messagepixels.com</generator><ttl>10</ttl><item><guid isPermaLink="true">http://news.xb2.net/ot4xb.examples/1/Retrieving+the+computer+name+from+the+NETBIOS.html</guid><title>Retrieving the computer name from the NETBIOS</title><pubDate>Fri, 13 Jun 2008 11:11:23 +0200</pubDate><link>http://news.xb2.net/ot4xb.examples/1/Retrieving+the+computer+name+from+the+NETBIOS.html</link><comments>http://news.xb2.net/ot4xb.examples/1/Retrieving+the+computer+name+from+the+NETBIOS.html</comments><author>pbn_NOSPAM_@pablob.com</author><description>&lt;pre&gt;#include &amp;quot;ot4xb.ch&amp;quot;
// ---------------------------------------------------------------------------
function Main()
? cPrintf( &amp;quot;Computer Name : [%s]&amp;quot;, cGetComputerName() )
inkey(0)
return NIL
// ---------------------------------------------------------------------------
function cGetComputerName()
local cn := ChrR(0,256)
local cb := 255
@kernel32:GetComputerNameA(@cn,@cb)
return TrimZ(cn)
// ---------------------------------------------------------------------------&lt;/pre&gt;</description><enclosure url="http://news.xb2.net/ot4xb.examples/1/attachments/0/ComputerName.zip" length="758" type="application/octet-stream" /><comment xmlns="http://wellformedweb.org/CommentAPI/">http://news.xb2.net/comment.api/ot4xb.examples/1</comment></item><item><guid isPermaLink="true">http://news.xb2.net/ot4xb.examples/2/Retrieving+a+list+of+services+with+the+status+Active.html</guid><title>Retrieving a list of services with the status Active</title><pubDate>Sun, 13 Jul 2008 17:41:12 +0200</pubDate><link>http://news.xb2.net/ot4xb.examples/2/Retrieving+a+list+of+services+with+the+status+Active.html</link><comments>http://news.xb2.net/ot4xb.examples/2/Retrieving+a+list+of+services+with+the+status+Active.html</comments><author>pbn_NOSPAM_@pablob.com</author><description>&lt;pre&gt;function aGetActiveServices()
local hSc :=  @advapi32:OpenSCManagerA(0,0,SC_MANAGER_ENUMERATE_SERVICE)
local lResult
local pData,cbData
local nRH      := 0  // Resume Handle
local cbNeeded := 0
local nSvcCnt  := 0
local lLoop    := .T.
local aSvc     := {}
local n,ns

if( hSc == 0 ) ; return {} ; end

cbData := 0x10000 ; pData  := _xgrab(cbData)

while lLoop
   nSvcCnt  := 0
   lResult := ( @advapi32:EnumServicesStatusExA( hSc,SC_ENUM_PROCESS_INFO,;
                nOr(SERVICE_DRIVER,SERVICE_WIN32),SERVICE_ACTIVE,pData,cbData,;
                @cbNeeded,@nSvcCnt,@nRH,0) != 0 )
                
   lLoop := (nFpGetLastError() == ERROR_MORE_DATA)
   if( lResult .or. lLoop )
      ns := 0
      for n := 1 to nSvcCnt
         aadd( aSvc , PeekDWord(pData,@ns, 11) )
         aSvc[-1][1] := PeekStr(aSvc[-1][1],,-1)
         aSvc[-1][2] := PeekStr(aSvc[-1][2],,-1)
      next
   end
   if lLoop .and. ( cbNeeded &amp;gt; cbData )
       _xfree( pData ); cbData := cbNeeded ; pData  := _xgrab(cbData)
   end
end
_xfree( pData )
@advapi32:CloseServiceHandle(hSc)
return aSvc&lt;/pre&gt;</description><enclosure url="http://news.xb2.net/ot4xb.examples/2/attachments/0/ListActiveServices.zip" length="2050" type="application/octet-stream" /><comment xmlns="http://wellformedweb.org/CommentAPI/">http://news.xb2.net/comment.api/ot4xb.examples/2</comment></item><item><guid isPermaLink="true">http://news.xb2.net/ot4xb.examples/3/Generating+random+strings+(+ot4xb+build+1.5.2.79).html</guid><title>Generating random strings ( ot4xb build 1.5.2.79)</title><pubDate>Fri, 12 Sep 2008 22:52:31 +0200</pubDate><link>http://news.xb2.net/ot4xb.examples/3/Generating+random+strings+(+ot4xb+build+1.5.2.79).html</link><comments>http://news.xb2.net/ot4xb.examples/3/Generating+random+strings+(+ot4xb+build+1.5.2.79).html</comments><author>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</author><description>&lt;pre&gt;Minimum ot4xb build 1.5.2.79
cGenRndStr() is introduced in ot4xb build 1.5.2.54 but was produced about 10% of duplicates
was fixed in 1.5.2.79
----------------------------------------------------------------------
I've run the test in my computer ( Intel Core Duo 3Ghz, 2Gb RAM)
with the following results
Elapsed Time: 3 Seconds
1000000 Items 0 Duplicates
----------------------------------------------------------------------

#include &amp;quot;ot4xb.ch&amp;quot;
#define MAX_LOOP  1000000
// ---------------------------------------------------------------------------
function Main()
local nSeconds := Seconds()
local pHt      := _HDICT_NEW(,MAX_LOOP)
local n
for n := 1 to MAX_LOOP
   _HDICT_SETPROP(pHt,cBin2Hex(cGenRndStr(8,.T.)), 0) 
   // cBin2Hex() is needed here as the hash table is case insensitive
next
? cPrintf(&amp;quot; Elapsed Time: %i Seconds&amp;quot;,Seconds() - nSeconds)
? cPrintf(&amp;quot; %i Items  %i Duplicates&amp;quot;,MAX_LOOP , MAX_LOOP - _HDICT_COUNT(pHt) )
inkey(0)
return NIL
// ---------------------------------------------------------------------------&lt;/pre&gt;</description><enclosure url="http://news.xb2.net/ot4xb.examples/3/attachments/0/TestRndStr.zip" length="431" type="application/octet-stream" /><comment xmlns="http://wellformedweb.org/CommentAPI/">http://news.xb2.net/comment.api/ot4xb.examples/3</comment></item><item><guid isPermaLink="true">http://news.xb2.net/ot4xb.examples/4/Retrieving+Drive+Information.html</guid><title>Retrieving Drive Information</title><pubDate>Fri, 26 Sep 2008 21:45:24 +0200</pubDate><link>http://news.xb2.net/ot4xb.examples/4/Retrieving+Drive+Information.html</link><comments>http://news.xb2.net/ot4xb.examples/4/Retrieving+Drive+Information.html</comments><author>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</author><description>&lt;pre&gt;function ShowDriveInfo(cRoot , cStr )
local oInfo  := GetDriveInfo(cRoot)

cStr += CRLF + PadC( &amp;quot;| &amp;quot; + cRoot + &amp;quot; |&amp;quot;,78,&amp;quot;-&amp;quot;)
if oInfo == NIL
   cStr += CRLF + &amp;quot;Error: Unable to retrieve the volume information.&amp;quot;
   cStr += CRLF + cPrintf( &amp;quot;Type of Drive:[%s]&amp;quot;,_n2dt_(nGetDriveType(cRoot)) )
else
   cStr += CRLF + cPrintf( &amp;quot;Label: [%s] Serial:[%lX]&amp;quot; ,  oInfo:cLabel , oInfo:nSerial )
   cStr += CRLF + cPrintf( &amp;quot;MaxFileNameLen:[%i] FileSystem:[%s] Type:[%s]&amp;quot;,;
                  oInfo:nMaxCompLen,oInfo:cFileSystem,_n2dt_(oInfo:nDriveType) )
end
return cStr&lt;/pre&gt;</description><enclosure url="http://news.xb2.net/ot4xb.examples/4/attachments/0/TestDriveInfo.zip" length="1279" type="application/octet-stream" /><comment xmlns="http://wellformedweb.org/CommentAPI/">http://news.xb2.net/comment.api/ot4xb.examples/4</comment></item><item><guid isPermaLink="true">http://news.xb2.net/ot4xb.examples/5/Forced+Administrative+Privileges.html</guid><title>Forced Administrative Privileges</title><pubDate>Tue, 30 Sep 2008 21:25:27 +0200</pubDate><link>http://news.xb2.net/ot4xb.examples/5/Forced+Administrative+Privileges.html</link><comments>http://news.xb2.net/ot4xb.examples/5/Forced+Administrative+Privileges.html</comments><author>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</author><description>&lt;pre&gt;This sample will check first if the current user have administrative privileges

if lIsUserAdmin()
   ? &amp;quot;Current user has administrative privileges&amp;quot;

If no sufficient privileges will show you a screen to get a user/pwd with admin privileges
will try to run the same exe with the provided user/pwd account
and close itself if succesfull

So you will get a new instance of the same exe but this time running with the privileges of the provided account.

function lLogonAsAdmin()    
local cUser      := Space(60)
local cPwd       := Space(60)
local aSI        := AFill(Array(17),0)
local aPI        := AFill(Array(4),0)
local cWApp      := cSzAnsi2Wide(AppName(.F.)) 
local result     := .F.
aSI[1] := 68       
if !lLogOnDialog(@cUser,@cPwd) ; return .F. ; end 

cUser := cSzAnsi2Wide(cUser)
cPwd  := cSzAnsi2Wide(cPwd)

result := ( @AdvApi32:CreateProcessWithLogonW(cUser,cSzAnsi2Wide(&amp;quot;.&amp;quot;),cPwd,1,cWApp,0,0,0,0,aSI,@aPI) != 0 )
if result 
   if aPI[1] != 0 ; @kernel32:CloseHandle(aPI[1]) ; end
   if aPI[2] != 0 ; @kernel32:CloseHandle(aPI[2]) ; end     
end
return result&lt;/pre&gt;</description><enclosure url="http://news.xb2.net/ot4xb.examples/5/attachments/0/TestRunAs.zip" length="1367" type="application/octet-stream" /><comment xmlns="http://wellformedweb.org/CommentAPI/">http://news.xb2.net/comment.api/ot4xb.examples/5</comment></item><item><guid isPermaLink="true">http://news.xb2.net/ot4xb.examples/6/Taskbar+Icon.html</guid><title>Taskbar Icon</title><pubDate>Wed, 8 Oct 2008 13:40:24 +0200</pubDate><link>http://news.xb2.net/ot4xb.examples/6/Taskbar+Icon.html</link><comments>http://news.xb2.net/ot4xb.examples/6/Taskbar+Icon.html</comments><author>pb_no_spam_@_remove_all_betwen_underscores_xbwin.com</author><description>&lt;pre&gt;#include &amp;quot;ot4xb.ch&amp;quot;
// ---------------------------------------------------------------------------
#define IDI_APPLICATION     32512
#define IDI_HAND            32513
#define IDI_QUESTION        32514
#define IDI_EXCLAMATION     32515
#define IDI_ASTERISK        32516
#define IDI_WINLOGO         32517
// ---------------------------------------------------------------------------
#define NIIF_NONE       0x00000000
#define NIIF_INFO       0x00000001
#define NIIF_WARNING    0x00000002
#define NIIF_ERROR      0x00000003
// ---------------------------------------------------------------------------
proc dbesys ; return
// ---------------------------------------------------------------------------
proc main()
local nKey := 0
local oTbi := TNotifyIcon():New(0,IDI_EXCLAMATION, &amp;quot;Using a system icon&amp;quot;)
local oCrt := SetAppWindow()

oTbi:bOnContextMenu  := {|| QOut(&amp;quot;OnContextMenu&amp;quot;)}
oTbi:bOnLDblClick    := {|| QOut(&amp;quot;OnLDblClick  &amp;quot;)}
oTbi:bOnLClick       := {|| QOut(&amp;quot;OnLClick     &amp;quot;)}
oTbi:bOnMouseMove    := {|| QOut(&amp;quot;OnMouseMove  &amp;quot;)}


? &amp;quot;Press a key to show icon from system in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Show()
oTbi:ShowInfo(,&amp;quot;From System&amp;quot;,1)

? &amp;quot;Press a key to show icon from file in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Modify(&amp;quot;0.ico&amp;quot;,NIL,&amp;quot;Using a Icon From File&amp;quot;)
oTbi:ShowInfo(,&amp;quot;From File&amp;quot;,2)

? &amp;quot;Press a key to show icon from EXE resource in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Modify(NIL,2,&amp;quot;Using a Icon From Resource in EXE&amp;quot;)
oTbi:ShowInfo(,&amp;quot;From resource in EXE&amp;quot;,3)

? &amp;quot;Press a key to show icon from DLL resource in the taskbar ... &amp;quot; ; Inkey(0)
oTbi:Modify(&amp;quot;test.dll&amp;quot;,3,&amp;quot;Using a Icon From resource in DLL&amp;quot;)
if oTbi:ShowInfo(,&amp;quot;From resource in DLL&amp;quot;,1)
   ? &amp;quot;Press a key to hide the ballon ... &amp;quot; ; inkey(0)
   oTbi:HideInfo()
end
? &amp;quot;Press a key to start the icon animation&amp;quot; ; Inkey(0)
oTbi:StartAnimation({{,1,&amp;quot;&amp;quot;},{,2},{,3},{,4},{,5},{,6},{,7},{,8},{,9},{,10}}, 200 )

? &amp;quot;Press a key to stop the icon animation&amp;quot; ; Inkey(0)
oTbi:StopAnimation()

? &amp;quot;Press ESC to close ... &amp;quot; ; while (nKey := Inkey(0)) != 27 ; end
oTbi:Destroy()
return&lt;/pre&gt;</description><enclosure url="http://news.xb2.net/ot4xb.examples/6/attachments/0/TaskBarIcon.zip" length="5747" type="application/octet-stream" /><comment xmlns="http://wellformedweb.org/CommentAPI/">http://news.xb2.net/comment.api/ot4xb.examples/6</comment></item></channel></rss>