Solved

API to find out server info

Posted on 2001-08-21
12
209 Views
Last Modified: 2007-12-19
I'm looking for a way to find out the root file server that I'm connected.  We are currently running on a Novell network, in transition to Windows 2000. If there's a API or OCX that will do the trick for both, that would be ideal. However, I'm guessing that it'll be 2 different ones.
0
Comment
Question by:kcleary
  • 5
  • 3
  • 2
  • +2
12 Comments
 
LVL 1

Expert Comment

by:falkor
ID: 6411101

'try this
Sub main()
    Dim iCtr As Integer
   
    For iCtr = 1 To 28
        Debug.Print iCtr & " = " & Environ$(iCtr)
    Next iCtr
   
    'once you decide on your property, you can call like this:
    'debug.print Envinron$("USERNAME")

End Sub
0
 
LVL 1

Expert Comment

by:falkor
ID: 6411108
It sounds like you'll be looking for this one:

msgbox Environ$("HOMESHARE")
0
 

Author Comment

by:kcleary
ID: 6411167
Works good for an Windows NT computer, but what about for a 9X computer?
0
 
LVL 1

Expert Comment

by:falkor
ID: 6411179
Hmm, Environ does work on 95.  Unfortunatly, the only 95/98 machines I have around right now are not on our network.  I'm curious, what did you get when you tried it?
0
 

Author Comment

by:kcleary
ID: 6411197
I'm using the FILE_SERVER variable/property (I didn't see a HOMESHARE one).  On a Win98 PC, there is no variable for FILE_SERVER, so I'm receiving nothing.
0
 

Author Comment

by:kcleary
ID: 6411200
I'm using the FILE_SERVER variable/property (I didn't see a HOMESHARE one).  On a Win98 PC, there is no variable for FILE_SERVER, so I'm receiving nothing.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:cookre
ID: 6411223
For Novell:
Unless you have:
* a standardized login script that sets an environment variable to what you want, or
* a standard drive letter mapping whose properties you can query, then

it will be a real pain to find out what you want.

Much depends on which version of Novell you're running and whether or not you permit multiple connections.  With bindery connections, things are a little easier, but when logging into NDS, the concept of a login server begins to blur, since you don't neccessarily know before hand which physical server you'll be authenticated through.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6411715
Hi kcleary,

Take a look on link below, maybe you can find something useful:

http://www.mvps.org/vbnet/code/network/index.html

'Hope will help.
0
 

Author Comment

by:kcleary
ID: 6417728
It appears that there's no way to get the info I need all of the time.  Environ$ works on an NT 4.0 PC, but I haven't been able to get it to work elsewhere.  ryancys link has plenty of good code, but nothing that looked like it would take care of the problem.  I beginning to fear that cookre is right.

I will continue to look at some of your comments and hopefully find a solution.
0
 
LVL 22

Accepted Solution

by:
cookre earned 75 total points
ID: 6419541
For Novell, if you're using tree logins (as opposed to bindery), and if you have only one login server per container, you would extract the container name from the fully qualified userid then enumerate the servers in the root of that container, looking for the sole login server, i.e., skipping print servers, NWIPs, etc.

If the tree and its' object name were well designed, the server name itself would help in identifying its' function.

Another approach would be to enumerate all of the client's connections, looking further only when you find an attachment to a server in the user's container.

And, yes, there is an API for all of this. You can download the Netware SDK and NovellWin32 SDK for free at:

http://developer.novell.com/ndk/bykit.htm

If I remember right, it's about 85M.

To give you a small glimpse at Netware API programming, here's some code to map a drive (done this way because we couldn't always rely on the presence of the MAP command):

//////////////////////////////////////////////////////////////////////
//
// Map a drive to the specified server
// Returns:
//          Success: 0
//                   If an existing connection is being used,
//                   the returned DriveNumber will be >0.
//                   If the connection is a new one, the returned
//                   DriveNumber will be negative.
//
// Error returns:
// 1 - Unable to get connection references
// 2 - Unable to get connection handle
// 3 - Attach failure
// 4 - Create context handle failure
// 5 - Unable to get context
// 6 - Unable to authenticate
// 7 - No drive letters available
// 8 - Map drive failure
//

int MapDrive(char * ServerName,char * Path,NWCONN_HANDLE * hCon,int *DriveNumber)
{
NWRCODE           RC;
nuint32           ScanCtr;
int               NumConnections;
nuint32           TempConnRef;
nuint32           ConnRefs[100];
NWCONN_HANDLE     hConn;
char              TempServerName[64];
NWCONN_NUM        ConnNumber;
NWDSContextHandle hContext;
char              ContextStr[255];
int               idx;
char              TempStr[256];
nuint16           BitMask;
int               NewConn;
int               RetryCnt;

// Load up all connection references and look
// for the Primary Server
NewConn=0;
ScanCtr=0;
NumConnections=0;
RC=NWCCScanConnRefs(&ScanCtr,&TempConnRef);
while (RC==0)
      {
      ConnRefs[NumConnections]=TempConnRef;
      NumConnections+=1;
      RC=NWCCScanConnRefs(&ScanCtr,&TempConnRef);
      }
if (NumConnections==0)
   {
   strcpy(GlobalErrMsg,"No connection references(MD)");
   return 1;
   }
hConn=0;
for (idx=0; idx<NumConnections; idx++)
    {
    RC=NWCCGetConnRefInfo(ConnRefs[idx],NWCC_INFO_SERVER_NAME,12,TempServerName);
    if (0!=stricmp(ServerName,TempServerName)) continue;
    // Goodie! We have a connection to the selected server
    // Get connection number for tracking info
    RC=NWCCGetConnRefInfo(ConnRefs[idx],NWCC_INFO_CONN_NUMBER,4,&ConnNumber);
    // Get handle to that connection
    RC=NWCCOpenConnByRef(ConnRefs[idx],NWCC_OPEN_LICENSED,NWCC_RESERVED,&hConn);
    if (RC!=0)
       {
       strcpy(GlobalErrMsg,"Unable to open connection ref(MD)");
       return 2;
       }
    break;
    }
// If we didn't have a connection already, make one
if (hConn==0)
   {
   sprintf(TempStr,"Attaching to %s (Attempt 1 of 6)",ServerName);
   UpdateStatusBar(TempStr);
   RC=NWAttachToFileServer(ServerName,0,&hConn);
   while (RC!=0)
         {
         RetryCnt=2;
         while ((RetryCnt<7) && (RC!=0))
               {
               Pause((double)10000);
               sprintf(TempStr,"Attaching to %s (Attempt %d of 6)",ServerName,RetryCnt);
               UpdateStatusBar(TempStr);
               RC=NWAttachToFileServer(ServerName,0,&hConn);
               RetryCnt+=1;
               }
         }
   if (RC!=0) {sprintf(GlobalErrMsg,"Attach failed(%04x)(MD)",RC); return 3;}

   RC=NWDSCreateContextHandle(&hContext);
   if (RC!=0) {sprintf(GlobalErrMsg,"CreateContextHandle failed(%04x)(MD)",RC); return 4;}
   RC=NWDSGetContext(hContext,DCK_NAME_CONTEXT,ContextStr);
   if (RC!=0) {sprintf(GlobalErrMsg,"Attach failed(%04x)(MD)",RC); return 5;}
   RC=NWDSAuthenticateConn(hContext,hConn);
   if (RC!=0) {sprintf(GlobalErrMsg,"Attach failed(%04x)(MD)",RC); return 6;}
   NewConn=1;
   }
//
// Find a drive letter to map through
*DriveNumber=0;
for (idx=7; idx<27; idx++)
    {
    RC=NWGetDriveStatus((nuint16)idx,1,&BitMask,NULL,TempStr,TempStr,TempStr);
    if (RC!=0) continue;
    if (BitMask==0)
       {
       *DriveNumber=idx;
       break;
       }
    }
if (*DriveNumber==0)
   {
   strcpy(GlobalErrMsg,"No drive letters available(MD)");
   return 7;
   }
RC=NWSetDriveBase((nuint16)*DriveNumber,hConn,(NWDIR_HANDLE)0,Path,0);
if (RC!=0)
   {
   sprintf(GlobalErrMsg,"General MapDrive failure [%04x](MD)",RC);
   return 8;
   }
if (NewConn==1) *DriveNumber=-*DriveNumber;
*hCon=hConn;
return 0;
}
0
 

Author Comment

by:kcleary
ID: 6422241
Thanks to everyone for the help on this question.  It seems there's no easy way to get the information that we need, but you all gave me some valuable info to help solve our problem.

I have submitted a request to split pts. between everyone.

Thanks again for the help.
0
 

Expert Comment

by:ComTech
ID: 6422396
Helll all, a Points slplit has been requested and will go as follows:

75=cookre
75=falkor
50=ryancys

I have refunded 125 point for the split.  I will accept 75 here for cookre.

kcleary, wyou will need to open 2 New questions, one for falkor and one for ryancys.

Entitle each question (IN THIS TOPIC AREA) *Points for <Expert Name>*    In the comment box type *for your help in question #20171853*  Choose the points you wish to aware 1=75 and 1=50 and submit, and you are all done.

Thanks,
ComTech
Communtiy Support

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 65
Validating VB6 Function 19 56
VBA filters 2 51
I need help using System.Web.HttpUtility.HtmlEncode in my VB.Net application 3 61
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now