FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour net use n: \\myserver\apps
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
net use n: \\myserver\apps
Posted: Thu Jul 01, 2010 01:25 PM

Hi,
this batch file works fine:

net use n: \dbserver\apps /user:marco mypassword
n:
cd\testprog
test.exe
c:
net use n: /delete

Is it possible to use fivewin/xHarbour program?

Thanks
marco

Marco Boschi
info@marcoboschi.it
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: net use n: \\myserver\apps
Posted: Thu Jul 01, 2010 02:28 PM
Use this mode.
If after running test.exe remove the unit n, test.exe may collapse, test.exe should generate a return variable or a file flag, to establish whether test.exe terminates, then remove the unit n.
is to be tested
Code (fw): Select all Collapse
...
..
.
cRVar := " \\dbserver\apps /user:marco mypassword"

 cOrden := "net use " + cRVar
 cOrden := "COMMAND.COM /C " + cOrden
 WaitRun(cOrden, 0)   // ejecutor externo

WinExec("test.exe")
If file("n:oktest.flg")
   cOrden := "net use n: /delete"
   cOrden := "COMMAND.COM /C " + cOrden
   WaitRun(cOrden, 0)   // ejecutor externo
EndIf
.
..
...
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: net use n: \\myserver\apps (solved)
Posted: Thu Jul 01, 2010 02:29 PM

I Log to server with this fivewin app from c:\myfolder

include "fivewin.ch"

FUNCTION MAIN( )

Waitrun( "net use n: \dbserver\apps /user:marco mypassword" , 0 )

lChdir( "n:\testprog" )

Winexec( "test.exe" , 1)

RETURN NIL

At the end of test.prg

lChdir( "c:\myfolder" )
WinExec( "net use n: /delete" , 0 )

RETURN NIL

thanks you all for your attention

Marco

Marco Boschi
info@marcoboschi.it
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: net use n: \\myserver\apps
Posted: Fri Jul 02, 2010 07:31 AM
Another way to do the following tasks. :-)

1. Map a network drive
2. Remove a mapped network drive
3. Check whether a drive letter is already mapped or not.

Code (fw): Select all Collapse
#include "Fivewin.ch"

//--------------------------//
Function Main()
    Local oDlg,oBtn1,oBtn2,oBtn3 
    Local cDriveLetter:="M:", cRemotePath:="\\Server\ShareName"
    
    DEFINE DIALOG oDlg FROM 5,5 to 25,65 TITLE "Network Drive mapping"
    
    @3,2 BUTTON oBtn1 PROMPT "Map a Network Drive" SIZE 60,20;
         ACTION (MapDrive( cDriveLetter, cRemotePath))
         
    @3,15 BUTTON oBtn2 PROMPT "Remove Mapped Drive" SIZE 60,20;
         ACTION RemoveMapDrive( cDriveLetter)
         
    @3,28 BUTTON oBtn2 PROMPT "Is Drive Mapped ?" SIZE 60,20;
         ACTION MsgInfo(if(IsDriveMapped( cDriveLetter),"Mapped to "+ cDriveLetter,"Not mapped"))         
         
    
    ACTIVATE DIALOG oDlg 

Return NIL

//-----------------------------------------------------------------------//
Function MapDrive(cDriveLetter,cRemotePath,lPermanent,cUserName,cPassword)
    Local oNetwork,oError
    DEFAULT lPermanent:=.F.
    oNetwork:=CreateObject("WScript.Network") 
    TRY
        oNetwork:MapNetworkDrive(cDriveLetter, cRemotePath,lPermanent,cUserName,cPassword)
    CATCH 
        MsgInfo("Unable to map "+cDriveLetter+ " to "+cRemotePath)
    END
Return NIL

//-----------------------------------------------------------------------//
Function RemoveMapDrive(cDriveLetter)
    Local oNetwork
    oNetwork:=CreateObject("WScript.Network") 
    TRY
        oNetwork:RemoveNetworkDrive(cDriveLetter)
    CATCH
        MsgInfo("Unable to remove "+cDriveLetter)
    END
Return NIL

//-----------------------------------------------------------------------//
Function IsDriveMapped(cDriveLetter)
    Local oNetwork,oNetworkDrives,i,lAlreadyConnected:=.F.
    oNetwork:=CreateObject("WScript.Network") 
    oNetworkDrives:=oNetwork:EnumNetworkDrives() 

    For i:=0 to oNetworkDrives:Count - 1 STEP 2
        if Upper(oNetworkDrives:Item(i)) == Upper(cDriveLetter)
            lAlreadyConnected:=.T.
        Endif
    Next
Return lAlreadyConnected


Regards
Anser
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: net use n: \\myserver\apps
Posted: Mon Jul 05, 2010 08:40 AM

Thanks,
but I have this error
Application
===========
Path and name: c:\za2\connec.exe (32 bits)
Size: 1,903,616 bytes
Time from start: 0 hours 0 mins 1 secs
Error occurred at: 07/05/10, 10:39:53
Error description: Error WScript.Network/3 DISP_E_MEMBERNOTFOUND: MAPNETWORKDRIVE
Args:
[ 1] = C n:
[ 2] = C \dbserver\apps
[ 3] = L .F.
[ 4] = U
[ 5] = U

Stack Calls

Called from: source\rtl\win32ole.prg => TOLEAUTO:MAPNETWORKDRIVE(0)
Called from: connec.prg => MAPDRIVE(28)
Called from: connec.prg => (b)MAIN(11)
Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK(176)
Called from: control.prg => TBUTTON:HANDLEEVENT(1427)
Called from: .\source\classes\WINDOW.PRG => _FWH(3347)
Called from: => SENDMESSAGE(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND(407)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT(928)
Called from: => DIALOGBOXINDIRECT(0)
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE(273)
Called from: connec.prg => MAIN(20)

Marco Boschi
info@marcoboschi.it
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM
Re: net use n: \\myserver\apps
Posted: Mon Jul 05, 2010 09:20 AM
Hello Marco,
I use this code to connect to network:

Code (fw): Select all Collapse
   LOCAL RemoteName   := GetPvProfString( "SETUPDATEN", "ServerName",    "\\DEMO\lwc", ".\INI\TOUCH.INI" )
   LOCAL UserName     := GetPvProfString( "SETUPDATEN", "User",          "test",       ".\INI\TOUCH.INI" )
   LOCAL Password     := GetPvProfString( "SETUPDATEN", "ServerPasswort","whdemo",     ".\INI\TOUCH.INI" )
   LOCAL LocalName    := GetPvProfString( "SETUPDATEN", "ServerLW",      "S:",         ".\INI\TOUCH.INI" )

   nRetCode := WNetAddConnection2( RemoteName, Password, UserName, LocalName )

   if nRetCode <> 0

      if nRetCode = 85
         //bereits verbunden

      elseif nRetCode = 67
         msginfo( "RemoteName " + RemoteName + CRLF +;
            "Password  " + Password  + CRLF +;
            "UserName  " + UserName  + CRLF +;
            "LocalName " + LocalName + CRLF +;
            CRLF +;
            "System error 67 - The network name cannot be found" )

      elseif nRetCode = 1219
         msginfo( "RemoteName " + RemoteName + CRLF +;
            "Password " + Password + CRLF +;
            "UserName " + UserName + CRLF +;
            "LocalName " + LocalName + CRLF +;
            CRLF +;
            "System error 1219 - Multiple connections to a server" )
      endif

   endif


Best regards,
Otto
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: net use n: \\myserver\apps
Posted: Mon Jul 05, 2010 09:47 AM

Ok
Thank you Anser
Thank you Otto
It works

Marco Boschi
info@marcoboschi.it
Posts: 1076
Joined: Fri Oct 07, 2005 10:41 PM
Re: net use n: \\myserver\apps
Posted: Mon Jul 05, 2010 04:48 PM

MarcoBoschi,

Exist in xHarbour this:

NetRedir( <cLocal> , ;
<cServer> , ;
[<cPassword>], ;
[<lShowError>] ) --> lSuccess

Regards

William, Morales

Saludos



méxico.sureste
Posts: 94
Joined: Tue Mar 28, 2006 04:09 PM
Re: net use n: \\myserver\apps
Posted: Wed Jul 07, 2010 03:29 PM

? cDrvMapToLetter( "\desarrollo_pc\utilerias" ) // Nos muestra la Letra de la unidad de red
? cLetterToDrvMap( "Z:" ) // Nos muestra la unidad de Red de la letra
? NETREDIR( "LPT1", "\desarrollo_pc\LX-300") // Mapeamos una unidad de red a una Letra, puede ser datos o impresoras
? NETRMTNAME( "LPT1" ) // Nos regresa la unidad de red completa en base al puerto o unidad elegido
? NETCANCEL( "LPT1" ) // eliminar puertos de red

Luis Fernando Rubio Rubio
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: net use n: \\myserver\apps
Posted: Thu Jul 08, 2010 06:54 AM

Thanks to all

marco

Marco Boschi
info@marcoboschi.it

Continue the discussion