Hola a todos.
Estoy buscando alguna funcion que me devuelva el nombre de todas las pc que esten en la red local, encuentro NetName() del viejo clipper pero solo me da el nombre de la PC local. Gracias.
Jorge Jaurena
// PRUEBA LISTADO DE PCS DE UNA RED //
Function DemoNetView()
Local aPCs:={}
WAITRUN( "cmd.exe /c net view > C:\PCs.txt" , .t.)
cTexto :=MEMOREAD( "C:\PCs.txt" )
nLinea :=MLCOUNT(cTexto)
FOR Q=4 TO nLinea // Arranca de la línea 4 (De todos modos probalo)
cLinea:=MEMOLINE(cTexto,255,Q)
IF LEFT(clinea,2)="\\"
AADD(aPCs,ALLTRIM(LEFT(cLinea,23)))
MsgInfo(ALLTRIM(LEFT(cLinea,23)))
ENDIF
NEXT
FErase("C:\PCs.txt")
Return nil
//
FUNCTION ListPC()
LOCAL oAdoCommand,oAdoConnection,oRs
oAdoCommand:=CreateObject("ADODB.Command")
oAdoConnection:=CreateObject("ADODB.Connection")
oAdoConnection:Provider:="ADsDSOObject"
oAdoConnection:Open("Active Directory Provider")
oAdoCommand:ActiveConnection:=oAdoConnection
oAdoCommand:CommandText:="Select name from 'LDAP://DOMINIO' Where objectCategory='computer'" //COLOCAR EL DOMINIO O EL GRUPO DE LA RED
oRs:=oAdoCommand:Execute()
oRs:MoveFirst()
DO WHILE !oRs:Eof()
xPC:=Alltrim(oRs:Fields("Name"):Value)
aAdd(aPcs,xPC)
oRs:MoveNext()
ENDDO
RETURN NIL
Application
===========
Path and name: C:\FWH1306\samples\TESTE.exe (32 bits)
Size: 2,467,328 bytes
Compiler version: xHarbour 1.2.3 Intl. (SimpLex) (Build 20140725)
Error description: Error ADODB.Command/6 DISP_E_UNKNOWNNAME: EXECUTE
Args:
Stack Calls
===========
Called from: => TOLEAUTO:EXECUTE( 0 )
Called from: TESTE.prg => LISTPC( 24 )
Called from: TESTE.prg => MAIN( 7 )
Linea 24:
oRs:=oAdoCommand:Execute()
Function qualmaq
Local oDlg101,oWnd,ncodigo,cestacao,nquantas,ocoment,odlg2
local volta:="",obrw,area:=select()
nquantas :=0
ferase("carimp.dbf")
DbCreate( "CARIMP", { { "QUANTAS" , "N", 04, 0 },;
{ "NOME_IMP" , "C", 14, 0 },;
{ "ESTACAO" , "C", 23, 0 },;
{ "COMENTARIO", "C", 30, 0 } } )
if OpenFile( "carimp","carimp", 1, .F. )
endif
WAITRUN("COMMAND.COM /C net view > estacao.txt" )
DbCreate( "CARTES", { { "TEXTO", "C", 100, 0 } } )
if OpenFile( "cartes","cartes", 1, .F. )
endif
APPEND FROM estacao.txt SDF
dbselectarea("CARTES")
dbgotop()
Do while !eof()
if substr(CARTES->texto,1,2)#'\\'
dbskip(1)
loop
endif
dbselectarea('CARIMP')
cestacao :=substr(CARTES->texto,1,23)
ferase("ESTACAO.TXT")
WAITRUN("COMMAND.COM /C net view "+cestacao+" > estacao1.txt" )
DbCreate( "CARTIM", { { "TEXTO", "C", 100, 0 } } )
if OpenFile( "cartim","cartim", 2, .F. )
endif
APPEND FROM estacao1.txt SDF
dbselectarea("CARTIM")
dbgotop()
Do while !eof()
if substr(CARTIM->texto,14,4)#'Disc'.AND.substr(CARTIM->texto,14,4)#'Impr'
dbskip(1)
loop
else
if substr(CARTIM->texto,14,4)<>'Disc'
ocoment:="Impressora"
else
ocoment:="Disco"
endif
endif
dbselectarea('CARIMP')
append blank
nquantas++
replace CARIMP->quantas with nquantas
replace CARIMP->estacao with substr(CARTES->texto,1,23)
replace CARIMP->nome_imp with ''+substr(CARTIM->texto,1,13)
replace CARIMP->comentario with ocoment
dbselectarea('CARTIM')
dbskip(1)
Enddo
dbselectarea('CARTIM')
dbclosearea('CARTIM')
ferase('CARTIM.DBF')
dbselectarea('CARTES')
dbskip(1)
Enddo
dbselectarea('CARTES')
dbclosearea('CARTES')
ferase('CARTES.DBF')
ferase('ESTACAO.TXT')
ferase('ESTACAO1.TXT')
dbselectarea('CARIMP')
go top
DEFINE DIALOG oDlg2 RESOURCE "REDE" TITLE "COMPONENTES DA REDE"
odlg2:lhelpicon:=.f.
REDEFINE LISTBOX obrw FIELDS carimp->NOME_IMP, ;
carimp->ESTACAO, ;
carimp->COMENTARIO ;
HEADERS OemToAnsi( "NOME" ), ;
OemToAnsi( "ESTACAO" ), ;
OemToAnsi( "DESCRICAO" ) ;
COLOR CLR_BLACK, rgb(238,221,130) ;
ID 101 ;
OF oDlg2 ;
ON DBLCLICK (volta:=rtrim(carimp->estacao)+rtrim(carimp->nome_imp),odlg2:end())
obrw:bKeyChar := {|nK| if( nK==VK_RETURN, (volta:=rtrim(carimp->estacao)+rtrim(carimp->nome_imp),odlg2:end()) ,NIL)}
activate dialog odlg2 centered
dbclosearea("carimp")
select(area)
Return volta
if OpenFile( "carimp","carimp", 1, .F. )
endif
#include "FiveWin.ch"
Function qualmaq
Local oDlg101,oWnd,ncodigo,cestacao,nquantas,ocoment,odlg2
local volta:="",obrw,area:=select()
nquantas :=0
ferase("carimp.dbf")
DbCreate( "CARIMP", { { "QUANTAS" , "N", 04, 0 },;
{ "NOME_IMP" , "C", 14, 0 },;
{ "ESTACAO" , "C", 23, 0 },;
{ "COMENTARIO", "C", 30, 0 } } )
if OpenFile( "carimp","carimp", 1, .F. )
endif
WAITRUN("COMMAND.COM /C net view > estacao.txt" )
DbCreate( "CARTES", { { "TEXTO", "C", 100, 0 } } )
if OpenFile( "cartes","cartes", 1, .F. )
endif
APPEND FROM estacao.txt SDF
dbselectarea("CARTES")
dbgotop()
Do while !eof()
if substr(CARTES->texto,1,2)#'\\'
dbskip(1)
loop
endif
dbselectarea('CARIMP')
cestacao :=substr(CARTES->texto,1,23)
ferase("ESTACAO.TXT")
WAITRUN("COMMAND.COM /C net view "+cestacao+" > estacao1.txt" )
DbCreate( "CARTIM", { { "TEXTO", "C", 100, 0 } } )
if OpenFile( "cartim","cartim", 2, .F. )
endif
APPEND FROM estacao1.txt SDF
dbselectarea("CARTIM")
dbgotop()
Do while !eof()
if substr(CARTIM->texto,14,4)#'Disc'.AND.substr(CARTIM->texto,14,4)#'Impr'
dbskip(1)
loop
else
if substr(CARTIM->texto,14,4)<>'Disc'
ocoment:="Impressora"
else
ocoment:="Disco"
endif
endif
dbselectarea('CARIMP')
append blank
nquantas++
replace CARIMP->quantas with nquantas
replace CARIMP->estacao with substr(CARTES->texto,1,23)
replace CARIMP->nome_imp with ''+substr(CARTIM->texto,1,13)
replace CARIMP->comentario with ocoment
dbselectarea('CARTIM')
dbskip(1)
Enddo
dbselectarea('CARTIM')
dbclosearea('CARTIM')
ferase('CARTIM.DBF')
dbselectarea('CARTES')
dbskip(1)
Enddo
dbselectarea('CARTES')
dbclosearea('CARTES')
ferase('CARTES.DBF')
ferase('ESTACAO.TXT')
ferase('ESTACAO1.TXT')
dbselectarea('CARIMP')
go top
// FALTA O .RC deste dialogo William - poste por favor.
DEFINE DIALOG oDlg2 RESOURCE "REDE" TITLE "COMPONENTES DA REDE"
odlg2:lhelpicon:=.f.
REDEFINE LISTBOX obrw FIELDS carimp->NOME_IMP, ;
carimp->ESTACAO, ;
carimp->COMENTARIO ;
HEADERS OemToAnsi( "NOME" ), ;
OemToAnsi( "ESTACAO" ), ;
OemToAnsi( "DESCRICAO" ) ;
COLOR CLR_BLACK, rgb(238,221,130) ;
ID 101 ;
OF oDlg2 ;
ON DBLCLICK (volta:=rtrim(carimp->estacao)+rtrim(carimp->nome_imp),odlg2:end())
obrw:bKeyChar := {|nK| if( nK==VK_RETURN, (volta:=rtrim(carimp->estacao)+rtrim(carimp->nome_imp),odlg2:end()) ,NIL)}
activate dialog odlg2 centered
dbclosearea("carimp")
select(area)
Return volta
FUNCTION OpenFile( cFile, cAlias, nModo, lRetenta )
DEFAULT cAlias TO Subs( cFile, rAt( '', cFile )+1), nModo TO 2 // erro lin 136
DEFAULT lRetenta TO nModo > 1 // erro lin 137
Do While .T.
SYSREFRESH()
DO CASE; Case nModo == 1
USE (cFile) ALIAS (cAlias) NEW EXCLUSIVE
Case nModo == 2
USE (cFile) ALIAS (cAlias) NEW SHARED
Other
USE (cFile) ALIAS (cAlias) NEW SHARED READONLY
End
If neterr()
If lRetenta .AND. MsgRetryCancel( 'Arquivo ' + cFile + ;
' sendo usado em outra estacao!', 'Alerta')
loop
else
retu .f.
endif
Endif
exit
Enddo
return .T.
#Include "FiveWin.ch"
#Include "Common.cH"
Function PcRede() //qualmaq
Local oDlg101,oWnd,ncodigo,cestacao,nquantas,ocoment,odlg2
local volta:="",obrw,area:=select()
nquantas :=0
ferase("carimp.dbf")
DbCreate( "CARIMP", { { "QUANTAS" , "N", 04, 0 },;
{ "NOME_IMP" , "C", 14, 0 },;
{ "ESTACAO" , "C", 23, 0 },;
{ "COMENTARIO", "C", 30, 0 } } )
if OpenFile( "carimp","carimp", 1, .F. )
endif
WAITRUN("COMMAND.COM /C net view > estacao.txt" )
DbCreate( "CARTES", { { "TEXTO", "C", 100, 0 } } )
if OpenFile( "cartes","cartes", 1, .F. )
endif
APPEND FROM estacao.txt SDF
dbselectarea("CARTES")
dbgotop()
Do while !eof()
if substr(CARTES->texto,1,2)#'\\'
dbskip(1)
loop
endif
dbselectarea('CARIMP')
cestacao :=substr(CARTES->texto,1,23)
ferase("ESTACAO.TXT")
WAITRUN("COMMAND.COM /C net view "+cestacao+" > estacao1.txt" )
DbCreate( "CARTIM", { { "TEXTO", "C", 100, 0 } } )
if OpenFile( "cartim","cartim", 2, .F. )
endif
APPEND FROM estacao1.txt SDF
dbselectarea("CARTIM")
dbgotop()
Do while !eof()
if substr(CARTIM->texto,14,4)#'Disc'.AND.substr(CARTIM->texto,14,4)#'Impr'
dbskip(1)
loop
else
if substr(CARTIM->texto,14,4)<>'Disc'
ocoment:="Impressora"
else
ocoment:="Disco"
endif
endif
dbselectarea('CARIMP')
append blank
nquantas++
replace CARIMP->quantas with nquantas
replace CARIMP->estacao with substr(CARTES->texto,1,23)
replace CARIMP->nome_imp with ''+substr(CARTIM->texto,1,13)
replace CARIMP->comentario with ocoment
dbselectarea('CARTIM')
dbskip(1)
Enddo
dbselectarea('CARTIM')
dbclosearea('CARTIM')
ferase('CARTIM.DBF')
dbselectarea('CARTES')
dbskip(1)
Enddo
dbselectarea('CARTES')
dbclosearea('CARTES')
ferase('CARTES.DBF')
ferase('ESTACAO.TXT')
ferase('ESTACAO1.TXT')
dbselectarea('CARIMP')
go top
DEFINE DIALOG oDlg2 RESOURCE "REDE" TITLE "COMPONENTES DA REDE"
odlg2:lhelpicon:=.f.
REDEFINE LISTBOX obrw FIELDS carimp->NOME_IMP, ;
carimp->ESTACAO, ;
carimp->COMENTARIO ;
HEADERS OemToAnsi( "NOME" ), ;
OemToAnsi( "ESTACAO" ), ;
OemToAnsi( "DESCRICAO" ) ;
COLOR CLR_BLACK, rgb(238,221,130) ;
ID 101 ;
OF oDlg2 ;
ON DBLCLICK (volta:=rtrim(carimp->estacao)+rtrim(carimp->nome_imp),odlg2:end())
obrw:bKeyChar := {|nK| if( nK==VK_RETURN, (volta:=rtrim(carimp->estacao)+rtrim(carimp->nome_imp),odlg2:end()) ,NIL)}
activate dialog odlg2 centered
dbclosearea("carimp")
select(area)
Return volta
FUNCTION OpenFile( cFile, cAlias, nModo, lRetenta )
DEFAULT cAlias TO Subs( cFile, rAt( '', cFile )+1), nModo TO 2 // erro
DEFAULT lRetenta TO nModo > 1 // erro
Do While .T.
SYSREFRESH()
DO CASE; Case nModo == 1
USE (cFile) ALIAS (cAlias) NEW EXCLUSIVE
Case nModo == 2
USE (cFile) ALIAS (cAlias) NEW SHARED
Other
USE (cFile) ALIAS (cAlias) NEW SHARED READONLY
End
If neterr()
If lRetenta .AND. MsgRetryCancel( 'Arquivo ' + cFile + ;
' sendo usado em outra estacao!', 'Alerta')
loop
else
retu .f.
endif
Endif
exit
Enddo
return .T.
/*
O resource rede: pcrede.rc
rede DIALOG 23, 24, 421, 172
STYLE 0x4L | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
FONT 8, "MS Sans Serif"
{
CONTROL "", 101, "TWBrowse", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP, 6, 8, 408, 152
}
*/
***************************
#Include "FiveWin.ch"
* teste da fun‡Æo para mostrar
* os dispositivos da rede
function main
local gg
gg:=listarede()
if gg[1]
msgalert(oemtoansi("Esta‡Æo: ")+gg[2]+CRLF+"Nome: "+gg[3]+CRLF+"Tipo: "+gg[4] )
else
msgalert(oemtoansi("Nenhum dispositivo selecionado !"))
endif
return nil
**************************************************
* Nome...: ListaRede()
* Fun‡ao.: Listar os dispositivos do grupo
* de trabalho da rede
* Retorno: array[4] .T. ou .F. (selecionou ou nÆo)
* Nome da esta‡Æo
* Nome do dispositivo
* Tipo (disco ou impressora)
* Adaptado por William Adami em 13/11/2014
**************************************************
Function ListaRede
Local ncodigo,cestacao,nquantas,ocoment,odlg2
local vol:={.f.,"","",""},obrw,area:=select(),vldbf,cComando,ob[2]
nquantas :=0
* cria arquivo dbf temporario na memoria
vldbf:= {}
AAdd(vldbf, {"quantas", "n", 4, 0 })
AAdd(vldbf, {"nome_imp", "c", 14, 0})
AAdd(vldbf, {"estacao", "c", 23, 0})
AAdd(vldbf, {"comentario", "c", 30, 0})
select 77
Hb_DbCreateTemp("CARIMP", vldbf)
cComando = "net view > estacao.txt"
myrun(cComando)
* cria arquivo dbf temporario na memoria
vldbf:= {}
AAdd(vldbf, {"texto", "c", 100, 0})
select 78
Hb_DbCreateTemp("CARTES", vldbf)
APPEND FROM estacao.txt SDF
dbselectarea("CARTES")
dbgotop()
Do while !eof()
if substr(CARTES->texto,1,2)#'\\'
dbskip(1)
loop
endif
dbselectarea('CARIMP')
cestacao :=substr(CARTES->texto,1,23)
ferase("ESTACAO.TXT")
cComando = "net view "+cestacao+" > estacao1.txt"
myrun(cComando)
* cria arquivo dbf temporario na memoria
vldbf:= {}
AAdd(vldbf, {"texto", "c", 100, 0})
select 79
Hb_DbCreateTemp("CARTIM", vldbf)
APPEND FROM estacao1.txt SDF
dbselectarea("CARTIM")
dbgotop()
Do while !eof()
if substr(CARTIM->texto,27,4)#'Disc'.AND.substr(CARTIM->texto,27,4)#'Impr'
dbskip(1)
loop
else
if substr(CARTIM->texto,27,4)<>'Disc'
ocoment:="Impressora"
else
ocoment:="Disco"
endif
endif
dbselectarea('CARIMP')
append blank
nquantas++
replace CARIMP->quantas with nquantas
replace CARIMP->estacao with substr(CARTES->texto,1,23)
replace CARIMP->nome_imp with ''+substr(CARTIM->texto,1,13)
replace CARIMP->comentario with ocoment
dbselectarea('CARTIM')
dbskip(1)
Enddo
dbselectarea('CARTIM')
CARTIM->(DBCLOSEAREA())
dbdrop("MEM:CARTIM")
dbselectarea('CARTES')
dbskip(1)
Enddo
dbselectarea('CARTES')
CARTES->(DBCLOSEAREA())
dbdrop("MEM:CARTES")
if file('ESTACAO.TXT')
ferase('ESTACAO.TXT')
endif
if file ('ESTACAO1.TXT')
ferase('ESTACAO1.TXT')
endif
dbselectarea('CARIMP')
go top
DEFINE DIALOG oDlg2 FROM 5, 2 TO 30, 55 TITLE "LISTA DE DISPOSITIVOS DA REDE"
odlg2:lhelpicon:=.f.
@ 1 , 0.8 LISTBOX obrw VAR cItem ;
FIELDS carimp->NOME_IMP, ;
carimp->ESTACAO, ;
carimp->COMENTARIO ;
HEADERS OemToAnsi( "NOME" ), ;
OemToAnsi( "ESTACAO" ), ;
OemToAnsi( "Tipo" ) ;
OF odlg2 SIZE 200, 140 ;
COLOR CLR_WHITE, CLR_GREEN ;
ON DBLCLICK (vol:={ .t.,rtrim(carimp->estacao), rtrim(carimp->nome_imp),rtrim(carimp->comentario) },odlg2:end())
obrw:bKeyChar := {|nK| if( nK==VK_RETURN,(vol:={ .t., rtrim(carimp->estacao), rtrim(carimp->nome_imp),rtrim(carimp->comentario) },odlg2:end()) ,NIL)}
@ 9, 8 BUTTON ob[1] PROMPT "&Ok" OF oDlg2 SIZE 40, 12 ACTION (vol:={ .t.,rtrim(carimp->estacao), rtrim(carimp->nome_imp),rtrim(carimp->comentario) },odlg2:end())
@ 9, 18 BUTTON ob[2] PROMPT "&Sair" OF oDlg2 SIZE 40, 12 ;
ACTION (oDlg2:End() )
activate dialog odlg2 centered
CARIMP->(DBCLOSEAREA())
dbdrop("MEM:CARIMP")
select(area)
Return vol
FUNCTION myRUN( cComando, nStyle, lWait, lShowResult )
local oShell, RET
IF valtype( nStyle ) != "N"
nStyle := 0
ENDIF
IF ValType( lWait ) != "L"
lWait := .T.
ENDIF
IF ValType( lShowResult ) != "L"
lShowResult := .F.
ENDIF
oShell := CreateObject( "WScript.Shell" )
IF !GetEnv( "OS" ) == "Windows_NT"
cComando += "start " + cComando
ENDIF
TRY
RET := oShell:Run( "%comspec% /c " + cComando, nStyle, lWait )
CATCH
msgstop("ERRO NO ENVIO DO COMANDO !","ERRO")
END
IF lShowResult .AND. RET > 0 .and. RET <= 32
msginfo( "Erro Win_Run(): " + ltrim( Str( RET ) ), " OK " )
ENDIF
oShell := NIL
Return IF( RET = 0, .T., .F. )
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 44 guests