I have a program on a shared drive and inside of it I have a richtextbox and I want to save that as a file on the users desktop.
If I specify the location its fine ex.
RichTextBox1.SaveFile ("C:\Documents and Settings\mycpu\Desktop\testvbdox.doc")
but I dont want to specify everybodys location thats going to be using this. There has to be something out there like app.path that will give you the location of the desktop on a users pc but I dont know what it is can anyone help?!?!
sPiKie
09-07-2003, 09:46 AM
Here is a code I found for many months ago:
'Get The Desktop Path
'Insert this code to your form:
Private Const ERROR_SUCCESS = 0&
Private Const HKEY_CURRENT_USER = &H80000001
Private Const SYNCHRONIZE = &H100000
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_READ = READ_CONTROL
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or _
KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const REG_SZ = 1
Private Declare Function RegCloseKey& Lib "ADVAPI32.DLL" (ByVal hKey&)
Private Declare Function RegOpenKeyExA& Lib "ADVAPI32.DLL" _
(ByVal hKey&, ByVal lpSubKey$, ByVal ulOptions&, _
ByVal samDesired&, phkResult&)
Private Declare Function RegQueryValueExA& Lib "ADVAPI32.DLL" (ByVal _
hKey&, ByVal lpValueName$, ByVal lpReserved&, lpType&, lpData As Any, _
lpcbData&)
Private Function sGetDesktop() As String
Const nLG As Long = 256
Dim sValue As String * nLG
Dim hKey As Long
Dim nType As Long
Dim nCR As Long
If (RegOpenKeyExA(HKEY_CURRENT_USER, _
"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", 0, _
KEY_READ, hKey) = ERROR_SUCCESS) Then
If (RegQueryValueExA(hKey, "Desktop", 0, nType, ByVal sValue, nLG) _
= ERROR_SUCCESS) Then
If (nType = REG_SZ) Then
sGetDesktop = Left(sValue, InStr(sValue, vbNullChar) - 1)
End If
End If
nCR = RegCloseKey(hKey)
End If
End Function
Private Sub Form_Load()
MsgBox "Your desktop path is " & sGetDesktop
End Sub
Hope that helps :)
P.S: You can simply take a search on this forum, and you will found alot of methods etc..
Thanks so much it works like a charm.... I looked around I couldn't find anything like your code.... thanks...
sPiKie
09-07-2003, 10:04 AM
Your totally welcome m8, nice to hear it worked..