Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to get startup folder path?

How can i find the path to startup folder(s)? Preferably a method that will work on windows 98 through to windows XP and using C or Visual Basic.

Currently i have VB code that i was going to convert to C. It can get me the "All Users" startup folder but i'm unsure if i can get it to get me the current users startup folder aswell. The code is shown below: (not mine)

[code]
Declare Function SHGetSpecialFolderLocation Lib "shell32" (ByVal hwnd As Long, ByVal nFolder As Long, Pidl As Long) As Long

Declare Function SHGetPathFromIDList Lib "shell32" (Pidl As Long, ByVal FolderPath As String) As Long
Const CSIDL_COMMON_STARTUP = 24
Const MAX_PATH = 260

Public Function StartupMenu() As String
Dim lpStartupPath As String * MAX_PATH
Dim Pidl As Long
Dim hResult As Long

hResult = SHGetSpecialFolderLocation(0, CSIDL_COMMON_STARTUP, Pidl)


If hResult = 0 Then
hResult = SHGetPathFromIDList(ByVal Pidl, lpStartupPath)


If hResult = 1 Then
lpStartupPath = Left(lpStartupPath, InStr(lpStartupPath, Chr(0)) - 1)
StartupMenu = lpStartupPath
End If
End If
End Function
[/code]

Can anyone help me in getting the all users startup folder aswell as the current users startup folder on windows 98 through to windows XP?

Thanks!

Comments

  • 684867684867 Posts: 110Member
    Hint:

    Windows is centralized around the registry. VB has a command to read registry keys. Enter the registry, find the folder name (some of us do change from the standard folder definitions), then voila, you have the folder for whatever you want, current user, all users, even the system or my documents.

    Where is this in the registry? Ah, grasshopper. When you snatch the pebble from my hand it will be time for you to go. All I can say is that HKLM defines the machine, HKCU defines the user currently logged into the machine, HKUSERS is all users on the system and HKCR is the key of all classes (software object configuations). Focus on HKLM, HKCU and HKCR. HKUSERS is a pain in the posterior.

    P.S. Don't play in the registry unless you are willing to reformat the machine on which you are playing!

    ****************************************
    Excellence Breeds! Go Hard or Go Home.

    Let Penguins rule the earth.
    Break some windows today.

  • DarknezzDarknezz Posts: 245Member
    "Ah, grasshopper. When you snatch the pebble from my hand it will be time for you to go."

    Hmm, did i come across as a bit of a newbie in that post? It was 2am and i was very sleepy but i assure you i'm no newbie. I simply don't know and can't find a method of getting the startup folder no matter what it is set to (wether it is set to "C:Startup", "F:WindowsStartup" or even "Z:FooBarHere").

    It would help greatly if you could tell me exactly where i can find this in the registry or if someone could tell me a good method of getting the startup folder(s) on any windows system.

    I'm at college at the moment but i guess i can do a registry search in regedit when i get home later. Thanks :)
  • DarknezzDarknezz Posts: 245Member
    No worries, back from college and i have searched the registry and found what i need.

  • pingpongpingpong Posts: 937Member
    How about SHGetSpecialFolderLocation? better than reading the registry
  • DarknezzDarknezz Posts: 245Member
    Yeah the code i originally found and tested used that function but it only returned the "Common Startup" folder and i want both the common startup folder and the current users startup folder.

    I have created a working solution that reads both startup folder locations from the registry so problem solved but thanks anyway :)

  • andrei5008andrei5008 Posts: 10Member
    I had this problem once.
    Try "GetModuleFileName()" in Platform SDK
  • The OschThe Osch Posts: 30Member
    : Yeah the code i originally found and tested used that function but it
    : only returned the "Common Startup" folder and i want both the common
    : startup folder and the current users startup folder.

    There was a constant named "CSIDL_COMMON_STARTUP" in the call to SHGetSpecialFolderLocation(). All you have to do to get current user's startup folder is change it to CSIDL_STARTUP.

    : I have created a working solution that reads both startup folder
    : locations from the registry so problem solved but thanks anyway :)

    I think using SHGetSpecialFolderLocation() is more reliable.
  • AlexandrescuAlexandrescu Posts: 66Member
    [b][red]This message was edited by Alexandrescu at 2005-6-30 10:0:54[/red][/b][hr]
    Come on, give the man complete refferences!
    In Windows 95, 98, 98SE there are two files - system.dat and user.dat - that are located in "C:Windows" and used to build the registry (hierarchical) database. So that registry is a product, rather than a database per se.

    Because my computer is too slow to use other Windows OSs - like 2000, 2003, XP... - I can't tell how these Windows OSs store their registry; I heard there are 3 "dat" files in the C:Windows directory.

    But the best ideea is to use some VB instead sniffing in those 2-3 huge files; handling the registry is riskey enough anyway - so ALWAYS MAKE A BAKUP.
    ================================================
    ((cons(car X)(cdr X))X)
    holds(X,P):-P(X);holds(Y,P),IsA(X,Y).

    Any (more) questions? SHOOT!
  • AlexandrescuAlexandrescu Posts: 66Member
    [b][red]This message was edited by Alexandrescu at 2005-6-30 10:20:24[/red][/b][hr]
    Well, make a disk autoscan for "win.ini", "system.ini"... They are always located in the Windows system folder - at least I never found these system files elsewhere.
    Anyway, if you find "win.com" in the same folder too, then you can bet you found the desired root.

  • 684867684867 Posts: 110Member
    It is not advisable to access the registry hive files directly.

    Microsoft is notorious for changing their specs. Keep your program maintainable and use the API.

    ****************************************
    Excellence Breeds! Go Hard or Go Home.

    Let Penguins rule the earth.
    Break some windows today.

Sign In or Register to comment.