Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Accessing the Desktop

Hi Brent McIntyre

Try get from register. Put this code on standard module and run the test.

Public Const vStr As Long = 255
Public Const REG_BINARY = 3&
Public Const REG_DWORD = 4&
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
(ByVal hKey As Long, ByVal lpSubKey As String, _
phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA"
_
(ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
ByRef lpType As Long, _
ByVal lpData As String, _
ByRef lpcbData As Long) As Long ' Note that if you declare the lpData
_
'parameter as String, you must pass
it By Value.
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002


'Get Registry Value, Arguments:
'1 - Reg Key (Ex.: HKEY_LOCAL_MACHINE),
'2 - Reg SubKey (Ex.: "Software\Microsoft\Windows\CurrentVersion"),
'3 - Name of Value (Ex.:"ProgramFilesDir" or "" for default)
Function GetRegValue(Key As Long, SubKey As String, ValueName As String) As
String
Dim RetStr As String * vStr 'Fixed-length strings
Dim fctRet As Long
Dim OpenKeyHdl As Long
Dim vType As Long
Dim vLen As Long
Dim i As Integer

GetRegValue = "Error"
vLen = vStr
fctRet = RegOpenKey(Key, SubKey, OpenKeyHdl)
If fctRet < 0 Then Exit Function

fctRet = RegQueryValueEx(OpenKeyHdl, ValueName, 0&, vType, RetStr, vLen)
RegCloseKey OpenKeyHdl
If fctRet < 0 Then Exit Function

If vType = REG_BINARY Then
GetRegValue = ""
For i = 1 To vLen
GetRegValue = GetRegValue _
& IIf(Len(Hex(Asc(Mid(RetStr, i, 1)))) = 1, "0", "") _
& Hex(Asc(Mid(RetStr, i, 1))) & " "
Next
Exit Function
End If

If vType = REG_DWORD Then
GetRegValue = "0x"
For i = 4 To 1 Step -1
GetRegValue = GetRegValue _
& IIf(Len(Hex(Asc(Mid(RetStr, i, 1)))) = 1, "0", "") _
& Hex(Asc(Mid(RetStr, i, 1)))
Next
Exit Function
End If

GetRegValue = Left(RetStr, vLen - 1)
End Function

Private Sub TestGet()
'Test 1 Standard folders
MsgBox GetRegValue(HKEY_CURRENT_USER,
"Software\Microsoft\Windows\CurrentVersion\Explore r\Shell Folders",
"Desktop")
MsgBox GetRegValue(HKEY_CURRENT_USER,
"Software\Microsoft\Windows\CurrentVersion\Explore r\Shell Folders",
"Programs")
MsgBox GetRegValue(HKEY_LOCAL_MACHINE,
"Software\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")
MsgBox GetRegValue(HKEY_LOCAL_MACHINE,
"Software\Microsoft\Windows\CurrentVersion", "ProgramFilesPath")
'Test 2 Outlook Journal
MsgBox GetRegValue(HKEY_CURRENT_USER, "Software\Microsoft\Shared
Tools\Outlook\Journaling\Microsoft Excel", "Enabled")
'Test 3 Calendar
MsgBox GetRegValue(HKEY_CLASSES_ROOT, "MSCAL.Calendar", "")
'Test 4 Screen resolution
MsgBox
Application.WorksheetFunction.Clean(GetRegValue(HK EY_LOCAL_MACHINE,
"Config\0001\Display\Settings", "Resolution"))
End Sub


HTH

---
Orlando Magalhães Filho

(So that you get best and rapid solution and all may benefit from the
discussion, please reply within the newsgroup, not in email)

"Brent McIntyre" escreveu na mensagem
...
Good afternoon all,

Does anyone know how to access the desktop on a Windows
XP machine ? I need to write a text file there but don't
want to input the username, as in XP the Desktop folder
is created in C:\Documents and Settings\USERNAME\Desktop,
I just want to write the file to ActiveDesktop or similar
and have it done.

Any help would be much appreciated, sorry that my request
isn't to clear.

Yours sincerely,

Brent McIntyre



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Accessing the Desktop

Orlando,

Thanks very much for your help, although I didn't use your sample in
this project I will be using it in the future, your help has been much
appreciated.

Yours sincerely,

Brent McIntyre

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing the Solver Add-in in VBA BigHairyUglyGuy Excel Discussion (Misc queries) 1 April 8th 08 03:21 PM
EXCEL FILES SAVED TO DESKTOP WILL NOT OPEN FROM DESKTOP randy111 Excel Discussion (Misc queries) 3 January 13th 08 10:38 PM
Accessing Macros opieandy Excel Discussion (Misc queries) 9 May 23rd 07 10:55 PM
accessing worksheets greg Excel Worksheet Functions 2 November 2nd 04 03:53 PM


All times are GMT +1. The time now is 11:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"