/ Forside / Teknologi / Udvikling / VB/Basic / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
VB/Basic
#NavnPoint
berpox 2425
pete 1435
CADmageren 1251
gibson 1230
Phylock 887
gandalf 836
AntonV 790
strarup 750
Benjamin... 700
10  tom.kise 610
Getsettings
Fra : Thomas Jørgensen


Dato : 13-08-01 22:46

Hej NG

Prøver at læse fra registry..
Følgende vil jeg bare ha' ind i en textboks, altså værdien af "SMTP SERVER"

[HKEY_CURRENT_USER\Software\Microsoft\Internet Account
Manager\Accounts\00000013]
"SMTP Server"="smtp.mail.dk"

Har prøvet uden held med forskellige varianter af commando'en:
GetSetting ("ProgramName", "Section", "Key", "Default ")

Mon der er en der gider hjælpe mig videre...

MVH
thomas j.



 
 
Christian Svenstrup (13-08-2001)
Kommentar
Fra : Christian Svenstrup


Dato : 13-08-01 23:00

Hej Thomas.

Med GetSetting og SaveSetting kan du kun læse og skrive til
[HKEY_CURRENT_USER\Software\VB and VBA Program Settings]

Jeg ved ikke hvordan det er muligt at skrive/læse andre steder i regisry,
men mon ikke der er andre der kan!?
Held og lykke med det!

Christian Svenstrup

"Thomas Jørgensen" <tjodense@tdcadsl.dk> skrev i en meddelelse
news:3b7848ed$0$286$edfadb0f@dspool01.news.tele.dk...
> Hej NG
>
> Prøver at læse fra registry..
> Følgende vil jeg bare ha' ind i en textboks, altså værdien af "SMTP
SERVER"
>
> [HKEY_CURRENT_USER\Software\Microsoft\Internet Account
> Manager\Accounts\00000013]
> "SMTP Server"="smtp.mail.dk"
>
> Har prøvet uden held med forskellige varianter af commando'en:
> GetSetting ("ProgramName", "Section", "Key", "Default ")
>
> Mon der er en der gider hjælpe mig videre...
>
> MVH
> thomas j.
>
>



Jens Andersen (14-08-2001)
Kommentar
Fra : Jens Andersen


Dato : 14-08-01 02:06

Prøv dette

Private Sub Form_Load()

MsgBox HentFraReg("HKCU\Software\Microsoft\Internet
Account\Manager\Accounts\00000013\SMTP Server")

End Sub

Public Property Get HentFraReg(Sti As String) As String

Dim WshShell As Object
Set WshShell = CreateObject("Wscript.Shell")
HentFraReg = WshShell.regread(Sti)

End Property




Jens Andersen (14-08-2001)
Kommentar
Fra : Jens Andersen


Dato : 14-08-01 02:14

Lejet lidt.... min kom frem sådan her

Private Sub Form_Load()

MsgBox HentFraReg("HKCU\Software\Microsoft\Internet Account
Manager\Accounts\00000001\SMTP Server")

End Sub
Public Property Get HentFraReg(Sti As String) As String

Dim WshShell As Object
Set WshShell = CreateObject("Wscript.Shell")
HentFraReg = WshShell.regread(Sti)

End Property




Thomas Jørgensen (14-08-2001)
Kommentar
Fra : Thomas Jørgensen


Dato : 14-08-01 20:07

Kanon.... Det virker perfekt.. Mange tak

Thomas

"Jens Andersen" <til@infojens.dk> skrev i en meddelelse
news:3b787b50$0$368$edfadb0f@dspool01.news.tele.dk...
> Lejet lidt.... min kom frem sådan her
>
> Private Sub Form_Load()
>
> MsgBox HentFraReg("HKCU\Software\Microsoft\Internet Account
> Manager\Accounts\00000001\SMTP Server")
>
> End Sub
> Public Property Get HentFraReg(Sti As String) As String
>
> Dim WshShell As Object
> Set WshShell = CreateObject("Wscript.Shell")
> HentFraReg = WshShell.regread(Sti)
>
> End Property
>
>
>



Rayman (16-08-2001)
Kommentar
Fra : Rayman


Dato : 16-08-01 19:33

Det er en rigtig uproffesionel måde at gøre det på.. Fy!

Der ligger en control til det, som hedder RegTool5.dll i Visual Studio,
ligger den under ...\Microsoft Visual Studio\Common\Tools\APE\RegTool5.dll

Herefter er det bare:

If Registry.GetKeyValue(HKEY_LOCAL_MACHINE, KeyName, ValueName, DataValue)
Then
'Got Value
Else
'No value
End If

Husk at under NT, skal brugeren have adgang til disse værdier, eller virker
det som om de ikke findes.
"Jens Andersen" <til@infojens.dk> wrote in message
news:3b78798b$0$314$edfadb0f@dspool01.news.tele.dk...
> Prøv dette
>
> Private Sub Form_Load()
>
> MsgBox HentFraReg("HKCU\Software\Microsoft\Internet
> Account\Manager\Accounts\00000013\SMTP Server")
>
> End Sub
>
> Public Property Get HentFraReg(Sti As String) As String
>
> Dim WshShell As Object
> Set WshShell = CreateObject("Wscript.Shell")
> HentFraReg = WshShell.regread(Sti)
>
> End Property
>
>
>



Bjarke Walling Peter~ (16-08-2001)
Kommentar
Fra : Bjarke Walling Peter~


Dato : 16-08-01 22:10

Rayman skrev:
> Det er en rigtig uproffesionel måde at gøre det på.. Fy!
>
> Der ligger en control til det, som hedder RegTool5.dll i Visual Studio,
> ligger den under ...\Microsoft Visual Studio\Common\Tools\APE\RegTool5.dll

Man kan også bruge API... Jeg gider ikke at poste et eksempel (medmindre der
er nogle der ønsker det), men det bliver brugt i rigtig mange eksempler på
internettet.

- Bjarke Walling Petersen



Allan R. (17-08-2001)
Kommentar
Fra : Allan R.


Dato : 17-08-01 03:06

....jeg ville godt vide det!
mangler en måde at gemme indstillinger...



Jens Andersen (17-08-2001)
Kommentar
Fra : Jens Andersen


Dato : 17-08-01 05:51

Henter og gemme i reg.

Men jeg vil forslå at du bruger ini fil til at gemme dinne indstillinger



Public Property Get HentFraReg(Sti As String) As String

Dim WshShell As Object
Set WshShell = CreateObject("Wscript.Shell")
HentFraReg = WshShell.regread(Sti)

'MsgBox reg.HentFraReg("HKLM\SOFTWARE\Hej\Test")

End Property
Public Function SkrivTilReg(Sti As String, Navn As String, Data As String)

' Skriver til Registringsdatabasen
Dim WshShell As Object
Set WshShell = CreateObject("Wscript.Shell")
WshShell.regwrite Sti & Navn, Data

'reg.SkrivTilReg "HKLM\SOFTWARE\Hej\", "Test", "Hej Igen"

End Function




Rayman (17-08-2001)
Kommentar
Fra : Rayman


Dato : 17-08-01 16:32

Her er de API declares der skal bruges:

Public Declare Function RegCloseKey Lib "advapi32.dll" Alias "RegCloseKey"
(ByVal hKey As Long) As Long
Public Declare Function RegConnectRegistry Lib "advapi32.dll" Alias
"RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long,
phkResult As Long) As Long
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As
Long) As Long
Public 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
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias
"RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias
"RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
Public 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
Public Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias
"RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As
String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String,
lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
Public Declare Function RegEnumValue Lib "advapi32.dll" Alias
"RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal
lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long,
lpType As Long, lpData As Byte, lpcbData As Long) As Long
Public Declare Function RegFlushKey Lib "advapi32.dll" Alias "RegFlushKey"
(ByVal hKey As Long) As Long
Public Declare Function RegGetKeySecurity Lib "advapi32.dll" Alias
"RegGetKeySecurity" (ByVal hKey As Long, ByVal SecurityInformation As Long,
pSecurityDescriptor As SECURITY_DESCRIPTOR, lpcbSecurityDescriptor As Long)
As Long

Hvordan man bruger dem, kan du læse på MSDN...

"Allan R." <ganjadk@icqmail.com> wrote in message
news:9lhu5t$380$1@eising.k-net.dk...
> ...jeg ville godt vide det!
> mangler en måde at gemme indstillinger...
>
>



Bjarke Walling Peter~ (17-08-2001)
Kommentar
Fra : Bjarke Walling Peter~


Dato : 17-08-01 17:20

Man behøves ikke at declare alle de APIs, så vidt jeg ved... men det er
måske fordi jeg kun bruger StringValues.

- Bjarke Walling Petersen

Rayman skrev:
> Her er de API declares der skal bruges:
>
> Public Declare Function RegCloseKey Lib "advapi32.dll" Alias "RegCloseKey"
> (ByVal hKey As Long) As Long
> Public Declare Function RegConnectRegistry Lib "advapi32.dll" Alias
> "RegConnectRegistryA" (ByVal lpMachineName As String, ByVal hKey As Long,
> phkResult As Long) As Long
> Public Declare Function RegCreateKey Lib "advapi32.dll" Alias
> "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult
As
> Long) As Long
> Public 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
> Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias
> "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String) As Long
> Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias
> "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As
Long
> Public 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
> Public Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias
> "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName
As
> String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As
String,
> lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
> Public Declare Function RegEnumValue Lib "advapi32.dll" Alias
> "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal
> lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long,
> lpType As Long, lpData As Byte, lpcbData As Long) As Long
> Public Declare Function RegFlushKey Lib "advapi32.dll" Alias "RegFlushKey"
> (ByVal hKey As Long) As Long
> Public Declare Function RegGetKeySecurity Lib "advapi32.dll" Alias
> "RegGetKeySecurity" (ByVal hKey As Long, ByVal SecurityInformation As
Long,
> pSecurityDescriptor As SECURITY_DESCRIPTOR, lpcbSecurityDescriptor As
Long)
> As Long
>
> Hvordan man bruger dem, kan du læse på MSDN...



Bjarke Walling Peter~ (17-08-2001)
Kommentar
Fra : Bjarke Walling Peter~


Dato : 17-08-01 18:37

Allan R. skrev:
> ...jeg ville godt vide det!
> mangler en måde at gemme indstillinger...

Det her bruger jeg selv:

--- RegSettings.bas ---
Option Explicit

Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long)
As Long
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As
Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal
lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal
Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long)
As Long

Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1

Private hCurKey As Long

Public CompanyName As String
Public AppName As String

Public Function RegSaveSetting(Key As String, Value As String) As Boolean
RegSaveSetting = False
If CompanyName = "" Or AppName = "" Then Exit Function
RegCreateKey HKEY_CURRENT_USER, "Software\" & CompanyName & "\" &
AppName, hCurKey
RegSetValueEx hCurKey, Key, 0, REG_SZ, ByVal Value, Len(Value)
RegCloseKey hCurKey
RegSaveSetting = True
End Function

Public Function RegLoadSetting(Key As String, Optional Default As String) As
String
Dim ValueType As Long
Dim BufferSize As Long
Dim Buffer As String
Dim ZeroPos As Long
If Not IsEmpty(Default) Then
RegLoadSetting = Default
Else
RegLoadSetting = ""
End If
If CompanyName = "" Or AppName = "" Then Exit Function
RegOpenKey HKEY_CURRENT_USER, "Software\" & CompanyName & "\" & AppName,
hCurKey
RegQueryValueEx hCurKey, Key, 0&, ValueType, ByVal 0&, BufferSize
If ValueType = REG_SZ Then
Buffer = String(BufferSize, " ")
RegQueryValueEx hCurKey, Key, 0&, 0&, ByVal Buffer, BufferSize
ZeroPos = InStr(Buffer, vbNullChar)
If ZeroPos = 0 Then
RegLoadSetting = Buffer
Else
RegLoadSetting = Left(Buffer, ZeroPos - 1)
End If
End If
RegCloseKey hCurKey
End Function

--- FrmMain.frm ---
Private Sub Form_Load()
CompanyName = "MY_COMPANY_NAME"
AppName = "MY_APPLICATION_NAME"
End Sub

Private Sub SubRutine()
If Not RegSaveSettings("Key", "Value") Then
MsgBox "Der opstod en fejl med registreringsdatabasen."
Else
MsgBox RegLoadSetting("Key", "Nøglen blev ikke fundet.")
End If
End Sub


- Bjarke Walling Petersen



Søg
Reklame
Statistik
Spørgsmål : 177552
Tips : 31968
Nyheder : 719565
Indlæg : 6408847
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste