-
This is what i want to do:
Get a registry value and asign it to a Variable, then make a
Code:
Shell " 'The Variable "
in a diferent thing.
I am guessing that the hardest part would be to get that value. If someone could give me the exact code, the regstry path is :
HKEY_CURRENT_USER\Control Panel\Desktop\ and there is a Key called " SCRNSAVE.EXE". I want the value of that key. For all yous, that is the screen saver key for windows. Anyways, any help would be appreciated.
-
-
Or check out the answer to this same question you asked a few days ago. :rolleyes:
-
yes and guess what, i couldn't figure it out and i didn't get the answer i was looking for :)
-
Well if you don't understand the answer to a question someone asks you, you should at least reply saying so and then perhaps someone can offer you more help in understanding it or getting the correct answer, but when you don't reply either one of two things are assumed.
a. You didn't read the reply
or
b. The code worked and you need no further assistance
Anyway the SCRNSAVE.exe is not on every windows computer, on my system (win95) the path to the current screensaver for windows is stored in the System.ini file.
So if you are positive that is the path to the key then this is the code that should do exactly what you want.
Code:
Option Explicit
Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_BINARY = 3 ' Free form binary
Private Const HKEY_CURRENT_USER = &H80000001
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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 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 Sub Form_Load()
Dim lKey as Long
Dim sScreenSaver as String
RegOpenKey HKEY_CURRENT_USER, "Control Panel\desktop", lKey
sScreenSaver = RegVal(lKey, "SCRNSAVE.EXE")
RegCloseKey lKey
Shell sScreenSaver
End Sub
Private Function RegVal(pKey As Long, pValName As String) As String
Dim lValueType As Long, lBufSize As Long
Dim strOut As String
Dim lret As Long
lret = RegQueryValueEx(pKey, pValName, 0, lValueType, ByVal 0, lBufSize)
If lret = 0 Then
If lValueType = REG_SZ Then
strOut = String(lBufSize, Chr(0))
lret = RegQueryValueEx(pKey, pValName, 0, 0, ByVal strOut, lBufSize)
ElseIf lValueType = REG_BINARY Then
Dim iOut As Integer
lret = RegQueryValueEx(pKey, pValName, 0, 0, iOut, lBufSize)
strOut = CStr(iOut)
End If
RegVal = strOut
Else
RegVal = ""
End If
End Function