CSIDL constant for user folder for Windows XP - c++

I can't seem to find what is the CSIDL constant for "C:\Documents and Settings\username" folder for Windows XP?
EDIT: I'm retrieving this path using the following code:
HANDLE hUserToken = NULL;
if(WTSQueryUserToken(dwUserSessionID, &hUserToken))
{
PIDLIST_ABSOLUTE pIdl = NULL;
if(SHGetFolderLocation(NULL, nCSIDL, hUserToken, NULL, &pIdl) == S_OK)
{
SHGetPathFromIDList(pIdl, path_buf);
ILFree(pIdl);
}
CloseHandle(hUserToken);
}
The issue becomes that the code returns C:\WINDOWS\system32\config\systemprofile for an administrative account when I'm expecting C:\Documents and Settings\Administrator.

Check this reference: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762494%28v=vs.85%29.aspx
The constant you are looking for is CSIDL_PROFILE.

Code snippet to obtain locations: ConstantSpecialItems.cpp + binary ConstantSpecialItems.exe if you want to print them yourself
Sample Locations:
Windows XP
Windows Vista
Windows 7
The one you ask for:
Windows version 5.1, Build 2600
CSIDL paths:
[...]
CSIDL_PROFILE: C:\Documents and Settings\John Doe

Related

Chromium Edge-based WebView2 does not work

I have followed all the instructions from Getting Started with WebView2 (developer preview) to create an app that is using Microsoft Edge (Chromium). However, it is not able to find the Edge browser. I also tried the sample apps (this and this) but with the same results. I have built the apps both for 32- and 64-bit.
What I get from calling CreateWebView2EnvironmentWithDetails() is error 0x80070002, which is ERROR_FILE_NOT_FOUND (The system cannot find the file specified.)
HRESULT hr = CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr,
Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>(
[hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT {
// Create a WebView, whose parent is the main window hWnd
env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>(
[hWnd](HRESULT result, IWebView2WebView* webview) -> HRESULT {
if (webview != nullptr) {
webviewWindow = webview;
}
// Resize WebView to fit the bounds of the parent window
RECT bounds;
GetClientRect(hWnd, &bounds);
webviewWindow->put_Bounds(bounds);
// Schedule an async task to navigate to Bing
webviewWindow->Navigate(L"https://www.bing.com/");
return S_OK;
}).Get());
return S_OK;
}).Get());
if (!SUCCEEDED(hr))
{
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
{
MessageBox(
nullptr,
L"Couldn't find Edge installation. "
"Do you have a version installed that's compatible with this "
"WebView2 SDK version?",
nullptr, MB_OK);
}
else
{
std::wstringstream formattedMessage;
formattedMessage << L"Failed to create webview environment"
<< ": 0x" << std::hex << std::setw(8) << hr;
MessageBox(nullptr, formattedMessage.str().c_str(), nullptr, MB_OK);
}
}
I have:
Edge Version 79.0.309.60 (Official build) beta (64-bit)
Windows 10.0.17134
Visual Studio 2019 16.4.2
Any ideas why my Edge installation is not found?
Probably the version of the Browser is not compatible with the latest version of the SDK, you may have to go back some versions for it to work, following the list:
https://learn.microsoft.com/en-us/microsoft-edge/hosting/webview2/releasenotes
Edit:
As informed by one of the developers of WebView2, at the moment WebView2 is still in preview version so always the latest version of Webview2 will accompany the latest canary version of Edge.
https://github.com/MicrosoftEdge/WebViewFeedback/issues/103#issuecomment-575287157
I got the same error, and after installed WebView2 Runtime , it works. https://developer.microsoft.com/microsoft-edge/webview2
You must install the WebView2 runtime in order to run the compatible applications.
Also, you need to upgrade the NuGet package, maybe in your code you still have the reference of "pre-release version".
In that version, "WebView2Environment" was missing it was kind of "WebView2Experiment".
Update Edge to latest version.
Update Nuget WebView2 SDK to lastest (INCLUDE prelease)

C++ - How to read system files

I'm trying to find a file that starts with "silabs-cdc" in "C:\\Windows\\System32\\DriverStore\\FileRepository"
DIR *dir;
struct dirent *ent;
if ((dir = opendir(path.c_str())) != NULL) { // FAILED
while ((ent = readdir(dir)) != NULL)
{
std::string fln = ent->d_name;
if(fln.substr(0,10) == "silabs-cdc")
{
// I found it
break;
}
}
closedir(dir);
}
but on windows vista the opendir always ends up with error as the folder did not exist (but it exists!), windows xp, windows 10 works just fine. I also tried findfirstfile function, but same result.
Is there any system folder protection? Is it possible to get through it - programmatically?
BTW: non system folders works fine, path to the folder is correct
EDIT: running program as admin will do nothing
Based on our comment exchange, it looks like on Vista, you built a 32 bit executable, but the drivers were installed as 64 bit drivers. The WOW64 redirection facility means that even though you tried to open a path under C:\Windows\System32, you actually opened a path under C:\Windows\SysWOW64. You could explicitly disable the redirection or you could build your executable to match the bittedness of the system, as a 64 bit executable will not be subject to redirection.

LoadLibraryEx error 87 (The parameter is incorrect)

One of my applications cannot load a system lib on the only machine. LoadLibraryEx returns 0 and the GetLastError returns 87 (The parameter is incorrect).
That can cause such error and how do I debug it?
Error appears only on a single machine which belongs to my client (server 2008R2). Libarary is located in system32 folder. Here is the code:
HMODULE lib = LoadLibraryEx(L"authui.dll", NULL,
LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_SEARCH_SYSTEM32);
if (lib == NULL)
{
DWORD err=GetLastError();
Log(L"error id: ", err);
throw;
}
I cannot reproduce the error on my copy of 2008R2 and have no idea what can cause the error. My app is written in VS2015 C++ (pure WinApi, no MFC or third party libs) and it is 64-bit.
Joel was right. The problem is in KB2533623 update which was not installed on the problem machine. I have changed my code to use absolute path as David Heffernan recommended and it works fine now.
Use the absolute path of authui.dll as the first parameter of LoadLibraryEx.

ShellExecute fails: ERROR_FILE_NOT_FOUND

I'm trying to start my application with my own launcher with administrator rights. The launcher works on my 64Bit Win7 but not at my 32Bit WinXP computer.
The code I am using is this:
wstring fullAppPath = "myapp.exe";
ShellExecuteW(NULL,
L"runas", //admin rights
fullAppPath.c_str(),
NULL, //startup params
NULL, //default dir
SW_SHOWNORMAL
);
I use the MSVC 2010 32Bit compiler with the Qt IDE and the launcher-application and the main-application are in the same directory, which is not C:\Windows\System32.
On my WinXP computer I get anytime I start my launcher an ERROR_FILE_NOT_FOUND error. (value 2)
How can I solve this?
The solution was using an absolute path instead of a relative path.

OLE/COM Object Viewer reports STG_E_FILENOTFOUND

I have created simple COM DLL using ATL and have added "ATL Simple Object" after that. To be sure server is registering I have placed messagebox:
STDAPI DllRegisterServer(void)
{
MessageBoxA ( NULL, "Hello World!", "Test", MB_OK );
HRESULT hr = _AtlModule.DllRegisterServer();
return hr;
}
Registering does fine. I decided to look how this object looks with OLE-COM Object Viewer that is part of SDK. Viewer reports error:
"LoadTypelib'(c:\pr\ILight.dll) failed.
<No system message defined> STG_E_FILENOTFOUND ($800300002)
Does it means my COM dll corrupted? How to make VIewer to show my dll information?
P.S.
Project RC file contians:
"REGISTRY"
IDR_ILIGHT
HKCR{}
IDR_LIGHT
HKCR
{
AboutiLight.1 = s 'Light Class'
{
CLSID = s '{DBC53EA8-A51E-4374-B104-06A834273B0C}'
}
AboutiLight = s 'Light Class'
{
CurVer = s 'AboutiLight.1'
}
NoRemove CLSID
{
ForceRemove {DBC53EA8-A51E-4374-B104-06A834273B0C} = s 'Light Class'
{
ProgID = s 'AboutiLight.1'
VersionIndependentProgID = s 'AboutiLight'
ForceRemove Programmable
InprocServer32 = s '%MODULE%'
{
val ThreadingModel = s 'Apartment'
}
TypeLib = s '{1D9F859D-10FF-4827-A341-4A8B8E318A61}'
Version = s '1.0'
}
}
}
String table
String table
ID=IDS_PROJNAME Value=100 Caption ILight
Version
VS_VERSION_INFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEMASK 0x3fL
FILEFLAGS 0x0L
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
After having received the same error (STG_E_FILENOTFOUND), and seeing Joe Willcoxson's comment about 64-bit and 32-bit, I was able to find a solution.
If you are using OleView.exe, the OLE/COM Object Viewer, there are actually two versions of it: 32-bit, and 64-bit. Ensure that you are launching with the proper version of OleView. The version in the base "BIN" folder of the SDK will be the 32-bit version. The "x64" folder will have the 64-bit version of the application, which is not fully compatible with older binaries and their typelibs (made in a 32-bit world).
On the other hand, if your new DLL is actively being compiled for x64, then it's highly likely 32-bit OleView will not be able to read the data properly, either.
1) Check to make sure that is the right path to your DLL.
2) Open the DLL itself from Visual Studio and check to be sure that a type library is embedded in the resources. If a typelib isn't found, add one.
3) If all that fails, did you register it under an administrator account/shell. If you call regsvr32.exe on it, make sure you are running with elevated privileges.