C++/VB - GetSystemDirectory

Asked By Neil W
19-Nov-09 12:02 PM
I know this is not a kernel question, but not too many groups left where
people are up on winapis.

I am using the function GetSystemDirectory, however in certain circumstances
in Windows XP Pro it is returning a relative path, not the full path to the
system directory!

E.g., sometimes the code below returns "C:\WINDOWS\SYSTEM32" as it should
But sometimes it just returns "SYSTEM32" !!!

char buf[MAX_PATH];
GetSystemDirectory(buf,sizeof(buf))

Is there a bug in this API?  Am I using it the wrong way?  Thanks.
Windows XP
(1)
SHGetSpecialFolderPath
(1)
GetWindowsDirectory
(1)
GetSystemDirectory
(1)
Boekelheide
(1)
Providenza
(1)
Directory
(1)
Sizeof
(1)
  Drew replied to Neil W
19-Nov-09 12:41 PM
Try SHGetSpecialFolderPath() with CSIDL_SYSTEM.

Drew
  David Lowndes replied to Neil W
19-Nov-09 01:54 PM
Give us a clue - what are the "certain circumstances"?

Dave
  Tim Roberts replied to Neil W
20-Nov-09 02:16 AM
Frankly, I do not believe you.  GetSystemDirectory **ALWAYS** returns a full
path.  Always has, always will.  Show us your actual code, and we will try to
point out where you are going wrong.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
  Paul Baker [MVP, Windows Desktop Experience] replied to Tim Roberts
02-Dec-09 10:29 AM
FWIW, I agree. Show me the money!

If you are running this on a server with Terminal Services, you will get a
user-specific path.

You may have third party software that is trying to hook into this stuff. A
remote access application perhaps.

Paul
  Tim Roberts replied to Paul Baker [MVP, Windows Desktop Experience]
02-Dec-09 11:38 PM
Not quite.  GetWindowsDirectory will return a user-specific path in remote
sessions, but GetSystemDirectory (which he asked about) returns the same
System32 path for everyone.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
  Paul Baker [MVP, Windows Desktop Experience] replied to Tim Roberts
03-Dec-09 04:53 PM
Yes, sorry!
Create New Account
help
the settings will be retained in next execution. This approach work fine in Win98, 2000, XP. However, in Vista, it doesn't work! No file was allowed to be created under that. Microsoft seems try to block the write access of System32 in new generation of windows for security reasons. To completely solve my problem. I think I need to find another about this issue. Does anyone have some ideas on this? Thx. Marco VC MFC Discussions Windows XP (1) Windows Server (1) SHGetKnownFolderPath (1) Vista (1) SHGetFolderPath (1) XP (1) SHGetFolder (1) GetSystemDirectory (1) Marco, Strictly speaking your user settings should be stored in side. How on earth are we supposed not to use it if we still support XP? (Here at my work, we still support Win2000). As others have said, advice to use store anything back around 1992 in Win16. It was always a mistake to use the Windows directory to store per-user information, and I basically teach that "If you need to
to store global data, not data specific to a given user. btw: I'm using SHGetSpecialFolderPath API function. My application has to run under W2K, XP and Vista with user running without administrator permissions. Thanks - - Francois PIETTE http: / / www.overbyte.be Win32 Kernel Discussions XP (1) PIETTE (1) ConvertSecurityDescriptorToStringSecurityDescriptor (1) CSIDL_COMMON_APPDATA (1) MSFTNGP (1) CSIDL_COMMON_DOCUMENTS (1) TK (1 SHGetSpecialFolderPath (1) On Jun 7, 6:14 am, "Francois PIETTE" <fpie. . .@newsgroups.nospam> Hi, You can APIs to store global data that is not user-specific, you can also use the Windows registry to store user independent settings: GetTempPath() GetTempFileName() SHGetFolderPath() CSIDL_LOCAL_APPDATA Or, HKEY_LOCAL_MACHINE \ Software http: / / msdn2 application, and set whatever security you need for those directories. See the following link (a Windows 2000 document which is still mostly applicable to Vista) for more details. http: / / msdn2.microsoft
can keep data without admin access and for all user. my programme work fine in xp and vista(if run as admin). i need urgent solution. regards ash - - adsd Win32 Networks Discussions SHGetSpecialFolderPath (1) GetTempPath (1) CSIDL_COMMON_APPDATA (1) HKEY_LOCAL_MACHINE (1) GetTempFileName (1) HKEY_USERS (1) Outlook (1) ArkadyRe (1 APIs to store global data that is not user-specific, you can also use the Windows registry to store user independent settings: GetTempPath() GetTempFileName() SHGetSpecialFolderPath() CSIDL_COMMON_APPDATA Or, HKEY_LOCAL_MACHINE \ Software http: / / msdn2.microsoft.com / En-US / library / aa364992.aspx http: / / msdn2 per-user path if called in the context of a plain user. . . - - Ken Johnson (Skywing) Windows SDK MVP http: / / www.nynaeve.net Hi, I understand that your application should store all
understandable :-) ) Tx for any advice. regards Alice VB COM Discussions Vista (1) Microsoft Access (1) XP (1) HKLM (1) HKEY_LOCAL_MACHINE (1) HKEY_Local_Maschine (1) MVP (1) NET (1) Even under earlier versions of Windows, "regular" users (non-admins and non-powerusers) don't have write access to anything in file in, for example, " \ Documents and Settings \ All Users \ Application Data". Use the Win32API function SHGetSpecialFolderPath to determine the exact location of this folder, as it can vary. For example, mine allow common configurations to be shared amongst all users on the machine. This is sorta Windows 101, Paul, why this line of questioning? - - .NET: It's About Trust! http: / / vfred.mvps allow common configurations to be ¤ shared amongst all users on the machine. This is sorta Windows 101, Paul, why this ¤ line of questioning? Yes Karl, but we're talking about *Vista* security here, which isn't exactly Windows 101. ;-) What is currently being attempted is not likely to succeed. Understanding what the global in place for MS Access, and if not, we create one. Unfortunately, some machines with XP SP2 don't allow the creation of the DSN due to the a missing registry