Page 1 of 1

How to get a name of PC?

Posted: Thu Nov 11, 2010 4:00 pm
by huangchenmin
Hello everyone
How to get a name of PC?
Please Help
Best Regards

Re: How to get a name of PC?

Posted: Thu Nov 11, 2010 6:23 pm
by danielmaximiliano
use GEtenv

Code: Select all

FUNCTION MYRUN(cComando,nStyle,lWait,lShowResult)
LOCAL oShell, RET, lRetorno:=.T.
*
IF OS_IsWin9x() .or. OS_IsWin98()
RUN (cComando)
ELSE
IF valtype( nStyle ) != "N"
nStyle := 0
ENDIF
IF ValType( lWait ) != "L"
lWait := .T.
ENDIF
IF ValType( lShowResult ) != "L"
lShowResult := .F.
ENDIF
*
TRY
oShell := CreateObject( "WScript.Shell" )
IF !GetEnv( "OS" ) == "Windows_NT"
cComando += "start " + cComando
ENDIF
RET := oShell:Run( "%comspec% /c " + cComando, nStyle, lWait )
IF lShowResult .AND. RET > 0 .and. RET <= 32
MessageBox(,"Erro Win_Run(): "+ltrim(Str( RET )))
ENDIF
oShell := NIL
lRetorno:=(RET==0)
CATCH oErro
TRY
RUN (cComando)
CATCH oErro
MessageBox(,'Erro ao rodar MYRUN()')
END
END
ENDIF
RETURN lRetorno
Source http://www.harbour-project.org/doc/getenv.htm

Understanding Windows XP's environment variables
http://articles.techrepublic.com.com/51 ... 86211.html

Saludos
DaNiElMaXiMiLiAnO

Re: How to get a name of PC?

Posted: Thu Nov 11, 2010 7:17 pm
by Rathinagiri
Great! Thanks a lot Daniel.

Re: How to get a name of PC?

Posted: Fri Nov 12, 2010 12:32 am
by huangchenmin
danielmaximiliano wrote:use GEtenv

Code: Select all

FUNCTION MYRUN(cComando,nStyle,lWait,lShowResult)
LOCAL oShell, RET, lRetorno:=.T.
.............
[b]DaNiElMaXiMiLiAnO[/b][/quote]
Got it!
Appreciate!
Thanks for your supports.
Best Regards
chen min

Re: How to get a name of PC?

Posted: Sat Nov 13, 2010 9:37 am
by fprijatelj
Hi

Computer name is stored in registry entry:
"HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName"

Here is a code:

#include "hbwin.ch"

PROCEDURE Main()
?ComputerName()
RETURN

function ComputerName()
RETURN hb_ValToStr(win_regRead("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName") )

BRGS

Franček

Re: How to get a name of PC?

Posted: Sat Nov 13, 2010 12:11 pm
by Rathinagiri
Fantastic. Thanks Franček

Re: How to get a name of PC?

Posted: Mon Nov 15, 2010 5:39 pm
by huangchenmin
fprijatelj wrote:Hi

.........
function ComputerName()
RETURN hb_ValToStr(win_regRead("HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName") )
BRGS
Franček
Dear Franček
Very impressive!
Allow me a silly question!
Is hb_valtostr()、win_regread() harbour or HMG build-in function ?

Re: How to get a name of PC?

Posted: Mon Nov 15, 2010 7:35 pm
by fprijatelj
Hi

Both functions are Harbour functions (hbwin.lib).
But you can use HMG function RegistryRead( cRegPath ) instead.

Best regards

Franček

Re: How to get a name of PC?

Posted: Tue Nov 16, 2010 4:59 am
by huangchenmin
fprijatelj wrote:Hi
Both functions are Harbour functions (hbwin.lib).
But you can use HMG function RegistryRead( cRegPath ) instead.
Best regards
Franček
Got it!
Thanks for your supports!
Rest Regards
chen min