How to get a name of PC?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

How to get a name of PC?

Post by huangchenmin »

Hello everyone
How to get a name of PC?
Please Help
Best Regards
User avatar
danielmaximiliano
Posts: 2763
Joined: Fri Apr 09, 2010 4:53 pm
DBs Used: DBF
Location: Argentina
Contact:

Re: How to get a name of PC?

Post 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
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
Telegram invitation https://t.me/HMGWorkspace
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: How to get a name of PC?

Post by Rathinagiri »

Great! Thanks a lot Daniel.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

Re: How to get a name of PC?

Post 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
fprijatelj
Posts: 14
Joined: Wed Mar 10, 2010 4:09 pm

Re: How to get a name of PC?

Post 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
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: How to get a name of PC?

Post by Rathinagiri »

Fantastic. Thanks Franček
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

Re: How to get a name of PC?

Post 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 ?
fprijatelj
Posts: 14
Joined: Wed Mar 10, 2010 4:09 pm

Re: How to get a name of PC?

Post by fprijatelj »

Hi

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

Best regards

Franček
huangchenmin
Posts: 157
Joined: Mon Jun 07, 2010 2:24 am

Re: How to get a name of PC?

Post 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
Post Reply