How to read registry values? 
Author Message
 How to read registry values?

I need to know who is the current user in the WindowsNT.

How can i read de value of the key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultUserName in the Windows registry?

Does anyone have a better idea?

Thanks in advance,
Fabricio Marcal.



Sat, 04 Jan 2003 03:00:00 GMT  
 How to read registry values?

Quote:

> I need to know who is the current user in the WindowsNT.

> How can i read de value of the key
> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
> NT\CurrentVersion\Winlogon\DefaultUserName in the Windows registry?

> Does anyone have a better idea?

> Thanks in advance,
> Fabricio Marcal.

NT has an environment variable that is always set by the system that can
be read instead of messing with the registry.  For example, adapting
from the WSH documentation example ...

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("Process")
Username = WshSysEnv("USERNAME")
WScript.Echo Username

Or in a single line ...

UserName =
WScript.CreateObject("WScript.Shell").Environment("Process")("UserName")

I assume these work in 2000, but know they do not work in Win 9x (no
Username variable).

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Sat, 04 Jan 2003 03:00:00 GMT  
 How to read registry values?
set network = createObject("wscript.network")
msgbox network.username

'one-liner...
msgbox createObject("wscript.network").username

--
Michael Harris
MVP Scripting


I need to know who is the current user in the WindowsNT.

How can i read de value of the key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultUserName in the Windows registry?

Does anyone have a better idea?

Thanks in advance,
Fabricio Marcal.



Sat, 04 Jan 2003 03:00:00 GMT  
 How to read registry values?
Hi Fabricio

Dim oShell 'Shell object
Dim sUserName
Set oShell=CreateObject("WScript.Shell")
sUserName=oShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultUserName")

But you could also use this code:

Dim oNet 'Network object
Dim sUserName
Set oNet=CreateObject("WScript.Network")
sUserName=oNet.UserName

Regards
Flemming Christiansen


Quote:

> I need to know who is the current user in the WindowsNT.

> How can i read de value of the key
> HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
> NT\CurrentVersion\Winlogon\DefaultUserName in the Windows registry?

> Does anyone have a better idea?

> Thanks in advance,
> Fabricio Marcal.



Sat, 04 Jan 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to read registry values with vb.NET??

2. How to read registry value?

3. Byte Array for reading registry values

4. How do i read registry values

5. How can I read registry values?

6. How can I read registry value(s) with vbscript?

7. Reading user's registry value

8. Read a value in a remote registry

9. Reading registry values containing a backslash (\)

10. How to read a value from the registry ...

11. How to read registry key containing many string values

12. Reading registry values

 

 
Powered by phpBB® Forum Software