1. How can I get the directory / folder for desktop?
If I want to make a program that write a .txt file directly to the desktop, how can I get the desktop folder so that when the program is copied to another computer, I won't have to change the directory again and again? (Without using commondialog control or browsing for the folder)
2. And also, for the same case, how can I get the directory of the startup menu. I want to copy a file to the startup menu that will enable the computer to start the program every time the computer is started.
3. How can I know (how to check) whether a file exists or not. e.g. I want to write a .txt file, but before creating (writing) the file, I want to check whether the file exists or not.
Thanks.
Last edited by Hack; Apr 20th, 2006 at 06:05 AM.
Reason: Added [RESOLVED] to thread title and green "resolved" checkmark
The only thing for the triumph of evil is for a good man to do nothing
Yet, I'm still looking for assistance if someone knows how to get the folder for the desktop and startup menu automatically when using the program in another computer.
Thanx.
Last edited by steven_luck1; Apr 15th, 2006 at 10:34 AM.
The only thing for the triumph of evil is for a good man to do nothing
Call GetDesktopPath to get the physical path of where the desktop shortcut items are stored. Call GetStartMenuPath for the Start menu Programs folder, pass True to it if you want it for all the users or pass False or nothing at all to get the path for the current user only.
There're errors when I tried to use the code, Syntax error. I suppose:
Private Declare Function SHGetSpecialFolderPath _
Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" ( _
ByVal hWnd As Long, _
ByVal pszPath As String, _
ByVal csidl As Long, _
ByVal fCreate As Long _
) As Long
is a function and a return value, right? Can we directly use:
SHGetSpecialFolderPath(0, sPath, CSIDL_DESKTOPDIRECTORY, False)
or
SHGetSpecialFolderPath(0, sPath, nFlag, False)
in the coding? Then it will be futile, isn't it? 'coz it's not used in the program. Can u help me with this again?
Thanks.
The only thing for the triumph of evil is for a good man to do nothing
Actually I've tried it before. Though there's no error, still, it doesn't work. When I try to see the folder using print in the immediate window, nothing appears. If possible, I mean, if possible, can u compress and attach a simple program using the code above? And see what's wrong there. 'coz I've tried modifying it and just can't find something wrong there.
when it's called in the first line, the value isn't used by any variable, and while returning the value in the "GetDesktopPath....", the function SHGetSpecialFolderPath.... is not used either, right??
Sorry, don't really understand about coding using API.
Thanx a lot.
The only thing for the triumph of evil is for a good man to do nothing
The GetDesktopPath is a function on its own. You should call that like this:
VB Code:
MsgBox GetDesktopPath
Or assign the return value into a variable
VB Code:
Dim sDesktop As String
sDesktop = GetDesktopPath
If you for example would call this from the click event of a CommandButton the code would look simular to this:
VB Code:
Private Sub Command1_Click()
Debug.Print GetDesktopPath
End Sub
It's true that SHGetSpecialFolderPath also is a function, the return value of this function isn't that important though since it should simply return 0 (on success) and a non-zero value if it should fail for some reason. But it would only fail if you wouldn't have a desktop folder path... which you of course have.
The desktop folder might not be named "Desktop" on all localized versions of Windows.
I've found my error... The call to SHGetSpecialFolderPath is successful (it returns TRUE = 1 on success not 0 as I first thought) the error is on the next line where we are supposed to trunc the string before the first NULL character. I used vbNullString where it should be vbNullChar, so in both functions change the last line to: