Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

network computer...

Status
Not open for further replies.

bigdad

Programmer
Jul 17, 2001
34
0
0
VE
Hi everybody one more time I need your help

My problem is how can I find and get the computer´s name of a network. To be more specific, I did a form to send some messsages between my computers(this is the same that use "net send to mycomputername mymessage" of windows 2000, MSDOS way) and I need to know all its name to send this message but first my procedure need looking for this name in my network.
well I don´t know how Can I do to seek this name. If some one can tellme how thank´s

P.D.: Please excuse me my english but I´m a venezuelan people and only talk spanish, my english is very bad

Thanks
Bigdad
 
LOCAL ARRAY la_temp
IF ANETRESOURCES(la_temp, "Network Name",1) > 0
*-- The array la_Temp will have the names
*-- of all the computers on that network
ENDIF

Satyen
 
SATYEN

LOCAL ARRAY la_temp <---This line throws an error, you need to dimension your array
IF ANETRESOURCES(la_temp, &quot;Network Name&quot;,1) > 0
*-- The array la_Temp will have the names
*-- of all the computers on that network
ENDIF


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
I guess next time I have to try it first to get rid of such syntax errors.

Thanks
Satyen
 
bigdad

The following works on NT Servers:
Code:
DO decl 
#DEFINE NERR_Success                       0 
#DEFINE MAX_PREFERRED_LENGTH              -1 

#DEFINE FILTER_TEMP_DUPLICATE_ACCOUNT      1 
#DEFINE FILTER_NORMAL_ACCOUNT              2 
#DEFINE FILTER_INTERDOMAIN_TRUST_ACCOUNT   8 
#DEFINE FILTER_WORKSTATION_TRUST_ACCOUNT  16 
#DEFINE FILTER_SERVER_TRUST_ACCOUNT       32 

LOCAL lcServer, lnBuffer, lnCount, lnCountEnum, lnCountTotal,; 
    lnResume, lnResult, lcEntry 

* The Null means the local computer 
* replace it with a name of a server, e.g. \\MYSERVER 
lcServer = .Null. 

STORE 0 TO lnBuffer, lnCountEnum, lnCountTotal, lnResume 

lnResult = NetUserEnum(lcServer, 1, 0, @lnBuffer,; 
    MAX_PREFERRED_LENGTH, @lnCountEnum, @lnCountTotal, @lnResume) 

IF lnResult <> NERR_Success 
    *  53 = the network path not found 
    * 123 = incorrect syntax for the name 
    ? &quot;Error code:&quot;, lnResult 
    RETURN 
ENDIF 

*| typedef struct _USER_INFO_1 { 
*|   LPWSTR    usri1_name;          0:4 
*|   LPWSTR    usri1_password;      4:4 
*|   DWORD     usri1_password_age;  8:4 
*|   DWORD     usri1_priv;         12:4 
*|   LPWSTR    usri1_home_dir;     16:4 
*|   LPWSTR    usri1_comment;      20:4 
*|   DWORD     usri1_flags;        24:4 
*|   LPWSTR    usri1_script_path;  28:4 
*| }USER_INFO_1, *PUSER_INFO_1, *LPUSER_INFO_1; bytes=32 
#DEFINE USERINFO_1_SIZE         32 

LOCAL lnCount, lcBuffer, lnBufsize, lcEntry 

lnBufsize = USERINFO_1_SIZE * lnCountEnum 
lcBuffer = Repli(Chr(0), lnBufsize) 
= Heap2String (@lcBuffer, lnBuffer, lnBufsize) 

LOCAL lcUsername, lcUserpwd, lcHomedir, lcComment, lcScrPath,; 
    lnPwdAge, lnPrivLev, lnFlags 

CREATE CURSOR csResult (; 
    username C(20), comment C(50), pwd C(12),; 
    pwdage N(12), priv N(12), flags N(12),; 
    script C(50), homedir C(200)) 

FOR lnCount=1 TO lnCountEnum 
    lcEntry = SUBSTR(lcBuffer,; 
        ((lnCount-1)*USERINFO_1_SIZE)+1, USERINFO_1_SIZE) 

    lcUsername = mem2str(buf2dword(SUBSTR(lcEntry, 1,4))) 
    lcUserpwd  = mem2str(buf2dword(SUBSTR(lcEntry, 5,4))) 
    lcHomedir  = mem2str(buf2dword(SUBSTR(lcEntry, 17,4))) 
    lcComment  = mem2str(buf2dword(SUBSTR(lcEntry, 21,4))) 
    lcScrPath  = mem2str(buf2dword(SUBSTR(lcEntry, 29,4))) 
     
    lnPwdAge  = buf2dword(SUBSTR(lcEntry, 9,4)) 
    lnPrivLev = buf2dword(SUBSTR(lcEntry, 13,4)) 
    lnFlags   = buf2dword(SUBSTR(lcEntry, 25,4)) 
     
    INSERT INTO csResult VALUES (; 
        lcUsername, lcComment, lcUserpwd, lnPwdAge,; 
        lnPrivLev, lnFlags, lcScrPath, lcHomedir) 
ENDFOR 

= NetApiBufferFree(lnBuffer) 
GO TOP 
BROWSE NORMAL NOWAIT 

FUNCTION  mem2str (lnMemBlock) 
* converting allocated in memory Unicode string to a VFP string 
#DEFINE StrBufferLength   250 
    IF lnMemBlock = 0 
        RETURN &quot;&quot; 
    ELSE 
        LOCAL lcBuffer 
        lcBuffer = SPACE(StrBufferLength) 
        = Heap2String (@lcBuffer, lnMemBlock, StrBufferLength) 
        lcBuffer = SUBSTR (lcBuffer, 1, AT(Chr(0)+Chr(0),lcBuffer)-1) 
    ENDIF 
RETURN  STRTRAN(lcBuffer, Chr(0),&quot;&quot;) 

FUNCTION buf2dword (lcBuffer) 
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ; 
       Asc(SUBSTR(lcBuffer, 2,1)) * 256 +; 
       Asc(SUBSTR(lcBuffer, 3,1)) * 65536 +; 
       Asc(SUBSTR(lcBuffer, 4,1)) * 16777216 

PROCEDURE  decl 
    DECLARE INTEGER NetUserEnum IN netapi32; 
        STRING servername, INTEGER level, INTEGER filter,; 
        INTEGER @bufptr, INTEGER prefmaxlen, INTEGER @entriesread,; 
        INTEGER @totalentries, INTEGER @resume_handle 

    DECLARE INTEGER NetApiBufferFree IN netapi32 INTEGER Buffer 

    DECLARE RtlMoveMemory IN kernel32 As Heap2String; 
        STRING @ Destination, INTEGER Source, INTEGER nLength
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
This function is limited to returning the Shares or Printers on a network Computer (and the network name must start with &quot;\\&quot;) in VFP6.

It will do that, or return a list of all Network Names (computers) when given a domain or workgroup name in VFP7.
 
wgcs

This function is limited to returning the Shares or Printers on a network Computer (and the network name must start with &quot;\\&quot;) in VFP6.

Not if it's run directly on the server.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
Which server?

I just tried it on VFP6 and VFP7... (Both running on the same Win2k Pro computer).

VFP6 Only works to give it a computer name in format: &quot;\\computer&quot;
and it returns shares or printers (depending on parameter)

VFP7 Works in the above way, OR you can specify &quot;workgroupname&quot; (I don't have a domain to try that), and then it returns the computer names on the workgroup.

If I specify &quot;Workgroupname&quot; in VFP6, it complains:
&quot;Function argument value, type, or count is invalid.&quot;
 
wgcs

Which server?

I just tried it on VFP6 and VFP7... (Both running on the same Win2k Pro computer).


My problem is how can I find and get the computer´s name of a network

I may have misread the original question. But to me the question, is to get the name of the computer logged into to the network (ie: I assume there is a server).
I have an NT4 server, I log into it thru Citrix Metaframe, so at that point it's as if I'm the server, and I run the API call in VFP6 and I get all the user's computer names logged into the server.
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first
 
The question: My problem is how can I find and get the computer´s name of a network has a typo, I believe he meant:

My problem is how can I find and get the computer´s name off a network

His purpose of getting the computer name is to send a message to that other computer, so the program isn't necessarily running on the server. He basically wants a picklist of all computers visible on the network. ANETRESOURCES(arr,'workgroupname',1) works in VFP7, not in VFP6.

BTW, I'm sorry for the &quot;Which Server&quot;.. it was kind of obtuse.... I meant to explain: WinNT Workstation, WinNT Server, Win2k Pro, Win2k Server, WinXP Home, WinXP Pro. Each of these can make shares available and therefore can be targeted by ANETRESOURCES. I'm testing on Win2k Pro without a Domain (just a workgroup... no &quot;server&quot;).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top