' LANSTAT.BAS - LANTastic function calls for QB. - Chip Morrow ' converted to PowerBASIC by Dave Navarro, Jr. %ax = 1: %bx = 2: %cx = 3: %dx = 4: %flags = 0 %es = 9: %ds = 8: %di = 6: %si = 5: %bp = 7 DEFINT A - Z 'Everybody's an integer ' Sample implementation of most of these routines follows. ' (Similar to LANTastic's "NET SHOW" command). CLS PRINT "LANStat - your current status on a LANTastic network." PRINT IF NetBios THEN 'Determine if netbios is present. Q = NetName( Machine$ ) 'Get machine name. NetVersion Major, Minor 'Get major and minor version #'s. PRINT " LANTastic version is: "; 'Display results.. PRINT LTRIM$( STR$( Major )); "."; LTRIM$( STR$( Minor )) '... PRINT "Current machine name is: "; Machine$ '... PRINT '... ' --------------------------------------------------------------------- ' First, get a list of devices that you are redirecting to this station. ' --------------------------------------------------------------------- Index = 0 'Always start at zero. DO 'Start looping... GetDevice Index, D$, N$ 'Get current device redirection. IF D$ = "" THEN EXIT DO 'Jump out if nothing on this pass PRINT D$; " is redirected to "; N$ 'Display results from GetDevice. Index = Index + 1 'Increment index. LOOP 'Get next device entry. ' ------------------------------------------------------------------ ' Next, get a list of server names that you're currently logged into. ' ------------------------------------------------------------------ PRINT Index = 0 'Reset our index DO 'Start looping... LoggedIn Index, Logx$ 'Get a server name IF Logx$ = "" THEN EXIT DO 'Jump out if nothing on this pass PRINT "Logged into: "; Logx$ 'Display result from LoggedIn. Index = Index + 1 'Increment index. LOOP 'Get next server name. ' -------------------------------------------------------------------- ' Now get a list of available servers that you haven't yet logged into. ' -------------------------------------------------------------------- PRINT Index = 0 'Reset our index DO 'Start looping... Inactive Index, Logx$ 'Get inactive server name IF Logx$ = "" THEN EXIT DO 'If nothing, jump out PRINT "Available: "; Logx$ 'Display result from Inactive Index = Index + 1 'Increment index LOOP 'Get next server name ELSE 'No netbios present, so get out. PRINT "NetBios not installed." END END IF ' -------------------------------------------------------------------- ' Quickie implementation of Redirect and NetCancel routines. ' Device name to redirect or cancel should be c:, d:, prn, lpt:, etc. ' Server's path should be full path, such as \\node1\cdrive ' -------------------------------------------------------------------- DO PRINT "R)edirect, C)ancel redirection, or Q)uit : "; DO Z$ = UCASE$( INKEY$ ) SELECT CASE Z$ CASE "R", "C", "Q": EXIT DO END SELECT LOOP PRINT Z$ SELECT CASE Z$: CASE "R": 'Redirect PRINT "Drive letter or logical device ---> "; LINE INPUT "", ReDir$ PRINT "Server's path to use -------------> "; LINE INPUT "", SPath$ PRINT "Device type = P)rinter, or D)isk -> "; DO Z$ = UCASE$( INKEY$ ) SELECT CASE Z$ CASE "P", "D": EXIT DO END SELECT LOOP PRINT Z$ SELECT CASE Z$ CASE "P": DevType = 3 '3 = printer CASE ELSE: DevType = 4 '4 = disk END SELECT Redirect DevType, ReDir$, SPath$ 'Do it. IF DevType > 0 THEN 'Devtype = 0 if no error. PRINT "Error"; DevType; PRINT " - no redirection performed." ELSE PRINT "Redirection successful." END IF PRINT CASE "C": 'Cancel PRINT "Drive letter or logical device --> "; LINE INPUT "", DevName$ Z = NetCancel( DevName$ ) 'Do it. IF Z > 0 THEN 'Z = 0 if no error. PRINT "Error"; Z; " - unable to cancel redirection." ELSE PRINT "Redirection successfully cancelled." END IF PRINT CASE "Q", CHR$( 27 ): 'Quit END END SELECT LOOP END ' End sample. Subs & functions follow. ' ************************************************************************** SUB GetDevice( DeviceNum%, DevName$, NetPath$ ) 'Get redirected device entry. ' ' DeviceNum% begins at zero (for first entry). ' DevName$ is returned as the name of the redirected device. ' NetPath$ is returned as the name of the server's network path. ' ' DevName$ is returned as a nul string if DeviceNum is invalid. ' DIM DevNam AS STRING * 16 DIM NetPat AS STRING * 128 REG %ax, &H5F02 REG %bx, DeviceNum% REG %ds, VARSEG( DevNam ) REG %si, VARPTR( DevNam ) REG %es, VARSEG( NetPat ) REG %di, VARPTR( NetPat ) CALL INTERRUPT &H21 Strip DevNam, DevName$ Strip NetPat, NetPath$ END SUB SUB Inactive( EntryNum%, Returned$ ) ' ' Display a list of servers that are available, but that you haven't ' logged into. ' ' EntryNum% is input to the routine, and begins at zero (for first entry). ' Returned$ is returned as the name of the server, or as "" if an invalid ' EntryNum is passed. ' DIM CurrentEntry AS STRING * 16 REG %ax, &H5F84 REG %bx, EntryNum% REG %es, VARSEG( CurrentEntry ) REG %di, VARPTR( CurrentEntry ) CALL INTERRUPT &H21 Strip CurrentEntry, Returned$ IF Returned$ < > "" THEN Returned$ = "(" + Returned$ + ")" END IF END SUB SUB LoggedIn( EntryNum%, Logged$ ) ' ' Display a list of servers that you're currently logged into. ' EntryNum% begins at zero (for first entry). ' Logged$ returns the server name, or a nul string if invalid EntryNum. ' DIM CurrentEntry AS STRING * 16 REG %ax, &H5F80 REG %bx, EntryNum% REG %es, VARSEG( CurrentEntry ) REG %di, VARPTR( CurrentEntry ) CALL INTERRUPT &H21 Strip CurrentEntry, Logged$ END SUB FUNCTION NetBios% 'Determine if NetBios is present. ' ' NetBios = 0 (Not installed), or ' -1 (Installed). ' REG %ax, 0 CALL INTERRUPT &H2A AH = REG( %ax ) \ 256 IF AH = 0 THEN NetBios% = 0 ELSE NetBios% = -1 END IF END FUNCTION FUNCTION NetCancel%( DevName$ ) 'Cancel device redirection. ' ' Cancel redirection of a device. ' DevName$ is device name to cancel redirection for, ' NetCancel% returns an error code if unsuccessful, zero otherwise. ' REG %ax, &H5F04 REG %ds, STRSEG( DevName$ ) REG %si, STRPTR( DevName$ ) CALL INTERRUPT &H21 IF REG( %flags ) AND 1 THEN NetCancel% = REG( %ax ) ELSE NetCancel% = 0 END IF END FUNCTION FUNCTION NetName%( Machine$ ) 'Get current machine name. ' ' This routine takes no inputs. It returns: ' ' NetName% is the machine number (or zero if error) ' Machine$ is the current machine name. ' DIM MName AS STRING * 16 REG %ax, &H5E00 REG %ds, VARSEG( MName ) REG %dx, VARPTR( MName ) CALL INTERRUPT &H21 IF REG( %flags ) AND 1 THEN 'Carry flag is set. (Error) NetName% = 0 LSET MName = "N/A" Strip MName, Machine$ EXIT FUNCTION END IF CH = REG( %cx ) \ 256 IF CH = 0 THEN NetName = 0 EXIT FUNCTION END IF NetName = REG( %cx ) - ( CH * 256 ) 'CL Strip MName, Machine$ END FUNCTION SUB NetVersion( Major%, Minor% ) 'Determine LANTastic version. ' ' Nothing is input to the routine. ' Major% and Minor% are returned as the version numbers. ' (Version 2.57 would be returned as Major = 2, Minor = 57) ' REG %ax, &HB809 CALL INTERRUPT &H2F Major% = REG( %ax ) \ 256 'AH Minor% = REG( %ax ) - ( Major * 256 ) 'AL END SUB SUB Redirect( DevType%, DevName$, NetPath$ ) 'Redirect a device ' ' Inputs: ' ' DevType% = 3 for Printer device, or ' 4 for %disk device. ' DevName$ = "C:", "D:", "LPT1:", etc. ' NetPath$ = Server's network path to redirect, in the format: ' \\server_name\device_name ' ----------------------------------------------------------------------- ' OutPut: ' ' DevType% returns zero if no error, or error number if one occurred. ' DIM DevNam AS STRING * 16 DIM NetPat AS STRING * 128 LSET DevNam = DevName$ + CHR$( 0 ) LSET NetPat = NetPath$ + CHR$( 0 ) REG %ax, &H5F03 REG %bx, DevType REG %cx, 0 REG %ds, VARSEG( DevNam ) REG %si, VARPTR( DevNam ) REG %es, VARSEG( NetPat ) REG %di, VARPTR( NetPat ) CALL INTERRUPT &H21 DevType = 0 IF REG( %flags ) AND 1 THEN 'Carry flag indicates error. DevType = REG( %ax ) END IF END SUB SUB Strip( BYVAL A$, B$ ) 'Kludge to trim down fixed-length ' strings. B$ = EXTRACT$( A$, ANY CHR$( 0, 32 )) END SUB