Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Path

Status
Not open for further replies.

Kori

Programmer
Oct 17, 2000
35
US
I am looking into a way to find the start menu's path and set it to a variable. I then will know what the folder is called inside the start menu, and the file to open the file. But with Windows NT and Windows 9x being different on there paths to the start menu is there a command I can use in VB to get it for me?
 
If I understood you good, than you are looking for the path of the windows folder, if I am correct than try this API Function.

Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Jn88
 
This could be done with the Shell Scripting Runtime library (scrrun.dll) on Windows 95 (with the Active Desktop extensions from Internet Explorer), Windows 98, and Windows ME, but I don't know if it's available on NT. Check it out. The documentation is on MSDN as Scripting Run-Time Object Model. Rick Sprague
 
Thanks guys I was looking for a easy way. Now you say I can use the Windows API but will this get me to the NT desktop? Why I say this is the NT desktop is located at

C:\winnt\profiles\user\desktop

But other users are at

c:\windows\desktop

Maybe a if\else well satisfy this problem??
 
Yes make an if statement!

Like this:

Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long


Public Function GetDesktopDir() As String
Dim r As Long
Dim strPath As String

strPath = Space(20)
r = GetWindowsDirectory(strPath, Len(strPath))

If Left(Trim(strPath), Len(Trim(strPath)) - 1) _ = "C:\WINDOWS" Then
GetDesktopDir = Left(Trim(strPath), Len(Trim _(strPath)) - 1) & "\desktop"
ElseIf Left(Trim(strPath), Len(Trim(strPath)) - 1) _ = "C:\WINNT" Then
GetDesktopDir = Left(Trim(strPath), Len(Trim _(strPath)) - 1) & "\profiles\user\desktop"
End If
End Function
 
Actually, on W95/98/ME, the start menu can be in one of several places. It can in C:\Windows\Start Menu, C:\Windows\Profiles\<username>\Start Menu, or anywhere else if the user is using TweakUI or has edited the registry. Furthermore, the Windows directory can have any valid folder name at all--it depends on what they chose for the Windows folder when it was installed. In Windows NT/2000, the start menu is actually a combination of the user's personal start menu and the AllUsers start menu. So to be thorough, there is no simple way to calculate the name of the start menu folder. That's why I suggested the Scripting Runtime. You can ask for the start menu, the desktop, or lots of other folders symbolically, and from what you get back (a FolderItem), you can determine the path.

However, the Scripting Runtime does take some effort to figure out, so if you want to keep it simple, Jn88's method will probably be more to your liking. But don't expect it to work 100% of the time. Rick Sprague
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top