Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving user's loginname
Message
From
10/07/1999 01:13:57
Penmetsa Sridhar
Visualsoft Technologies Limited
Hyderabad, India
 
General information
Forum:
Visual Basic
Category:
Other
Miscellaneous
Thread ID:
00239556
Message ID:
00239767
Views:
15
Hai Hugo Dahl

For Retrieving the Username,Systemdateformat,companyname use this code


Public companynm, sysformat, usernm As String
'Registry Constants
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_CURRENT_CONFIG = &H80000005

'Registry Specific Access Rights
Public Const KEY_QUERY_VALUE = &H1
Public Const KEY_SET_VALUE = &H2
Public Const KEY_CREATE_SUB_KEY = &H4
Public Const KEY_ENUMERATE_SUB_KEYS = &H8
Public Const KEY_NOTIFY = &H10
Public Const KEY_CREATE_LINK = &H20
Public Const KEY_ALL_ACCESS = &H3F

'Open/Create Options
Public Const REG_OPTION_NON_VOLATILE = 0&
Public Const REG_OPTION_VOLATILE = &H1

'Key creation/open disposition
Public Const REG_CREATED_NEW_KEY = &H1
Public Const REG_OPENED_EXISTING_KEY = &H2

'masks for the predefined standard access types
Public Const STANDARD_RIGHTS_ALL = &H1F0000
Public Const SPECIFIC_RIGHTS_ALL = &HFFFF

'Define severity codes
Public Const ERROR_SUCCESS = 0&
Public Const ERROR_ACCESS_DENIED = 5
Public Const ERROR_NO_MORE_ITEMS = 259

'Predefined Value Types
Public Const REG_NONE = (0) 'No value type
Public Const REG_SZ = (1) 'Unicode nul
terminated
string
Public Const REG_EXPAND_SZ = (2) 'Unicode nul
terminated
string w/enviornment var
Public Const REG_BINARY = (3) 'Free form binary
Public Const REG_DWORD = (4) '32-bit number
Public Const REG_DWORD_LITTLE_ENDIAN = (4) '32-bit number
(same as
REG_DWORD)
Public Const REG_DWORD_BIG_ENDIAN = (5) '32-bit number
Public Const REG_LINK = (6) 'Symbolic Link
(unicode)
Public Const REG_MULTI_SZ = (7) 'Multiple Unicode
strings
Public Const REG_RESOURCE_LIST = (8) 'Resource list in
the
resource map
Public Const REG_FULL_RESOURCE_DESCRIPTOR = (9) 'Resource list in
the
hardware description
Public Const REG_RESOURCE_REQUIREMENTS_LIST = (10)

Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Type ACL
AclRevision As Byte
Sbz1 As Byte
AclSize As Integer
AceCount As Integer
Sbz2 As Integer
End Type

Type SECURITY_DESCRIPTOR
Revision As Byte
Sbz1 As Byte
Control As Long
Owner As Long
Group As Long
Sacl As ACL
Dacl As ACL
End Type
Type WNDCLASS
style As Long
lpfnWndProc As Long
cbClsExtra As Long
cbWndExtra2 As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
End Type
Type WNDCLASSEX
cbSize As Long
style As Long
lpfnWndProc As Long
cbClsExtra As Long
cbWndExtra As Long
hInstance As Long
hIcon As Long
hCursor As Long
hbrBackground As Long
lpszMenuName As String
lpszClassName As String
hIconSm As Long
End Type


Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As
Long
Declare Function RegConnectRegistry Lib "advapi32.dll" Alias
"RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As
Long,
phkResult As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA"
(ByVal
hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias
"RegCreateKeyExA"
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long,
ByVal
lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long,
lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long,
lpdwDisposition As Long) As Long
Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA"
(ByVal
hKey As Long, ByVal lpSubKey As String) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias
"RegDeleteValueA"
(ByVal hKey As Long, ByVal lpValueName As String) As Long
Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA"
(ByVal hKey
As Long, ByVal dwIndex As Long, ByVal lpName As String, ByVal cbName As
Long)
As Long
Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA"
(ByVal
hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName
As Long,
lpReserved As Long, ByVal lpClass As String, lpcbClass As Long,
lpftLastWriteTime As FILETIME) As Long
Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA"
(ByVal
hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String,
lpcbValueName As Long, lpReserved As Long, lpType As Long, lpData As
Byte,
lpcbData As Long) As Long
Declare Function RegFlushKey Lib "advapi32.dll" (ByVal hKey As Long) As
Long
Declare Function RegGetKeySecurity Lib "advapi32.dll" (ByVal hKey As
Long,
ByVal SecurityInformation As Long, pSecurityDescriptor As
SECURITY_DESCRIPTOR,
lpcbSecurityDescriptor As Long) As Long
Declare Function RegisterClass Lib "user32" (Class As WNDCLASS) As Long
Declare Function RegisterClassEx Lib "user32" Alias "RegisterClassExA"
(pcWndClassEx As WNDCLASSEX) As Integer
Declare Function RegisterClipboardFormat Lib "user32" Alias
"RegisterClipboardFormatA" (ByVal lpString As String) As Long
Declare Function RegisterEventSource Lib "advapi32.dll" Alias
"RegisterEventSourceA" (ByVal lpUNCServerName As String, ByVal
lpSourceName As
String) As Long
Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal
id As
Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Declare Function RegisterServiceCtrlHandler Lib "advapi32.dll" Alias
"RegisterServiceCtrlHandlerA" (ByVal lpServiceName As String, ByVal
lpHandlerProc As Long) As Long
Declare Function RegisterWindowMessage Lib "user32" Alias
"RegisterWindowMessageA" (ByVal lpString As String) As Long
Declare Function RegLoadKey Lib "advapi32.dll" Alias "RegLoadKeyA"
(ByVal hKey
As Long, ByVal lpSubKey As String, ByVal lpFile As String) As Long
Declare Function RegNotifyChangeKeyValue Lib "advapi32.dll" (ByVal hKey
As
Long, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long, ByVal
hEvent
As Long, ByVal fAsynchronus As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"
(ByVal hKey
As Long, ByVal lpSubKey As String, phkResult As Long) As Long

Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, _
ByVal lpSubKey As String, ByVal ulOptions As Long, _
ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32" Alias
"RegQueryValueExA" _
(ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As
Long, _
ByRef lpType As Long, ByVal szData As String, ByRef lpcbData As
Long) As Long


Sub compname()
Dim szBuffer As String, dataBuff As String, ldataBuffSize As Long
Dim hKey As Long, phkResult As Long, RetVal As Long
Dim Value As String, RegEnumIndex As Long

'Create Buffer
dataBuff = Space(255)
ldataBuffSize = Len(dataBuff)

szBuffer = ".Default\Software\Microsoft\MS Setup (ACME)\User Info"
hKey = HKEY_USERS
RetVal = RegOpenKeyEx(hKey, szBuffer, 0, KEY_ALL_ACCESS, phkResult)
Value = "DefCompany"

RetVal = RegQueryValueEx(phkResult, Value, 0, 0, dataBuff,
ldataBuffSize)
If RetVal = ERROR_SUCCESS Then
companynm = ConvertString(dataBuff, ldataBuffSize)
End If
RegCloseKey hKey
RegCloseKey phkResult
End Sub
Public Function ConvertString(tmpVal As String, KeyValSize As Long) As
String
If (Asc(Mid(tmpVal, KeyValSize, 1)) = 0) Then ' Win95 Adds
Null
Terminated String...
ConvertString = Left(tmpVal, KeyValSize - 1) '
Null
Found, Extract From String
Else ' WinNT
Does NOT
Null Terminate String...
ConvertString = Left(tmpVal, KeyValSize) '
Null Not
Found, Extract String Only
End If
End Function
Sub username()
Dim szBuffer As String, dataBuff As String, ldataBuffSize As Long, _
hKey As Long, phkResult As Long, RetVal As Long, _
Value As String, RegEnumIndex As Long
'Create Buffer
dataBuff = Space(255)
ldataBuffSize = Len(dataBuff)

szBuffer = ".Default\Software\Microsoft\MS Setup (ACME)\User Info"
hKey = HKEY_USERS
RetVal = RegOpenKeyEx(hKey, szBuffer, 0, KEY_ALL_ACCESS, phkResult)

Value = "DefName"
RetVal = RegQueryValueEx(phkResult, Value, 0, 0, dataBuff,
ldataBuffSize)
If RetVal = ERROR_SUCCESS Then
usernm = ConvertString(dataBuff, ldataBuffSize)
End If

'Close the keys
RegCloseKey hKey
RegCloseKey phkResult
End Sub
Public Sub sysdatefmt()
Dim szBuffer As String, dataBuff As String, ldataBuffSize As Long, _
hKey As Long, phkResult As Long, RetVal As Long, _
Value As String, RegEnumIndex As Long
'Create Buffer
dataBuff = Space(255)
ldataBuffSize = Len(dataBuff)

szBuffer = ".Default\Control Panel\International"
hKey = HKEY_USERS
RetVal = RegOpenKeyEx(hKey, szBuffer, 0, KEY_ALL_ACCESS, phkResult)
Value = "sshortdate"
RetVal = RegQueryValueEx(phkResult, Value, 0, 0, dataBuff,
ldataBuffSize)
If RetVal = ERROR_SUCCESS Then
sysformat = ConvertString(dataBuff, ldataBuffSize)
End If
'
'Close the keys.
'
RegCloseKey hKey
RegCloseKey phkResult
End Sub



Private Sub Form_Load()
compname
sysdatefmt
username
MsgBox companynm & vbCrLf & sysformat & vbCrLf & usernm
End Sub
Previous
Reply
Map
View

Click here to load this message in the networking platform