GetAppliedGPOList and pGuidExtension value - c

I'm trying to use the GetAppliedGPOList function, but cannot find/understand what the pGuidExtension should be.
Here's the simple code so far:
#include <Windows.h>
#include <UserEnv.h>
int wmain(int argc, WCHAR *argv[])
{
//GetAppliedGPOList
DWORD flags = GPO_LIST_FLAG_MACHINE;
LPCWSTR machineName = NULL; //Local computer is used
PSID sidUser = NULL;
GUID *pGuidExtension; //What is the GUID of the extension?
PGROUP_POLICY_OBJECT *ppGPOList;
return 0;
}
Cannot run the function because I need to send that value.
Any example about the pGuidExtension value?
I did search here but found nothing about it.
Thank you.

The guids is listed at
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions
For example - Group Policy Client Side Extension List. The GetAppliedGPOList is looked under
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\History\{GuidExtension}
key

Related

How to create shortcut with Win32 API and c language

I want to write a program to create a shortcut for a specific file by using win32 API in c. my IDE is visual studio 2010.
I found this page but its sample just not compile and return many errors.
I also find this code but this always create a link with Target: "D:\Desktop\㩣睜湩潤獷湜瑯灥摡攮數" and I don't know why.
can someone tell me why the sample code of Microsoft is not working or the second one return something in Chinese shape language and also with wrong and constant location for any argument?
This is my code for MSDN sample:
#include "stdafx.h"
#include "windows.h"
#include "winnls.h"
#include "shobjidl.h"
#include "objbase.h"
#include "objidl.h"
#include "shlguid.h"
void _tmain(int argc, TCHAR *argv[])
{
CreateLink(argv[1],__argv[2],argv[3]);
}
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCSTR lpszPathLink, LPCWSTR lpszDesc)
{
HRESULT hres;
IShellLink* psl;
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface, used for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
WCHAR wsz[MAX_PATH];
// Ensure that the string is Unicode.
MultiByteToWideChar(CP_ACP, 0, lpszPathLink, -1, wsz, MAX_PATH);
// Add code here to check return value from MultiByteWideChar
// for success.
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(wsz, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
and the errors are:
1 error C1083: Cannot open include file: 'stdafx.h' and
2 IntelliSense: cannot open source file "stdafx.h"
CreateLink(argv[1],__argv[2],argv[3]);
This call looks weird. You are using argv[] for two LPCWSTR (const wchar_t *) parameters, but are using __argv[] for an LPCSTR (const char *) parameter. You should change the 2nd parameter to LPCWSTR to match the other parameters, and then use argv[] instead of __argv[].
The TCHAR-based IShellLink works with LP(C)WSTR string parameters, and LP(C)TSTR is LP(C)WSTR when compiling for Unicode. Which you are obviously doing, given that you are passing TCHAR-based argv[] values to LPCWSTR parameters, which will only compile if TCHAR is wchar_t.
IPersistFile::Save() takes only a Unicode string as input, regardless of what TCHAR maps to. You are converting the char* value from __argv[] from ANSI to Unicode, so you may as well just get a Unicode string from argv[] to begin with, and omit the call to MultiByteToWideChar() altogether.
There is no good reason to mix ANSI and Unicode strings like this. This is something the MSDN example is getting wrong.
And since your function parameters are working with Unicode strings, you should use the IShellLinkW interface directly instead of the TCHAR-based IShellLink interface.
Try this:
#include "stdafx.h"
#include "windows.h"
#include "shobjidl.h"
#include "objbase.h"
#include "objidl.h"
#include "shlguid.h"
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszPathLink, LPCWSTR lpszDesc)
{
HRESULT hres;
IShellLinkW* psl;
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
// has already been called.
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkW, (LPVOID*)&psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);
psl->SetDescription(lpszDesc);
// Query IShellLink for the IPersistFile interface, used for saving the
// shortcut in persistent storage.
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
if (SUCCEEDED(hres))
{
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(lpszPathLink, TRUE);
ppf->Release();
}
psl->Release();
}
return hres;
}
void _tmain(int argc, TCHAR *argv[])
{
if (argc > 3)
CreateLink(argv[1], argv[2], argv[3]);
}
Visual Studio generates stdafx.h and stdafx.cpp when you are using new project wizard. If Create empty project checkmark is marked, it will not generate them. These files are used to build a precompiled header file Projname.pch and a precompiled types file Stdafx.obj
For small projects you can eventually remove #include "stdafx.h", but it would be better to create new project with Create empty project unmarked.

Multiple instances of main method in C

I've got an issue with an assignment, but I'm not asking for help to do the assignment, just single problem.
My code is like this:
#include "linux/kernel.h"
#include "linux/unistd.h"
#include <linux/slab.h>
typedef _msg_t msg_t;
struct msg_t { /* members here */ };
static msg_t *bottom = NULL;
static msg_t *top = NULL;
int function_one (argA, argB) {
/* function is working, no need to show code*/
}
int function_two (argA, argB) {
/* function is working, so no need I guess to show the code*/
}
int main(int argc, char ** argv) {
char *in = "This is a testing message";
char msg[50];
int mlen;
function_one(in, strlen(in)+1);
mlen = function_two(msg, 50);
}
Here's the problem: When I do the make command from the directory, I get the error
/home/<username hidden by me>/dm510/linux-3.18.2/arch/um/os-linux/main.c:118:
multipli definition of 'main'
arch/um/kernel/built-in.o:
/home/<username hidden again>/dm510/linux-3.18.2/arch/um/kernel/file_i_created.c:60
first defined here"
What does this error mean? I only defined the main method one time in my own file
The message says you have (at least) two C files, main.c and file_i_created.c that are included in the build. Both have main() functions. (In C, the term is "function", not "method".) Remove one of those source files, or remove/rename the main() function in one of them.
You have multiple approaches here:
Usually there is only one main in a program. If so, decide, which is the actual main and rename the other one
If both mains are essential, you could try putting them in seperate namespaces
Really can't tell without seeing the file_i_created.c code though. Could be something else as well.

Getting user's country and keyboard language

In order to present the proper menu text and some other aspects of the UI I am trying to get the current user's country and keyboard language.
I know the locale (via the env. variable) but I can't find a way to get these two pieces of info.
The code is in C for Mac OS X. I can use Cocoa API to get them but they need to be called from C. Any ideas?
Thank you!
Use CFLocaleCopyCurrent, CFLocaleGetValue and CFLocaleCopyPreferredLanguages (note that the preferred language may not match the locale's language). See the documentation.
Edit: ok, here's some sample code.
#include <CoreFoundation/CoreFoundation.h>
#include <stdio.h>
int main (int argc, char **argv)
{
CFLocaleRef loc = CFLocaleCopyCurrent();
CFStringRef countryCode = CFLocaleGetValue (loc, kCFLocaleCountryCode);
CFStringRef countryName = CFLocaleCopyDisplayNameForPropertyValue (loc, kCFLocaleCountryCode, countryCode);
CFShow(countryCode);
CFShow(countryName);
CFArrayRef langs = CFLocaleCopyPreferredLanguages();
CFStringRef langCode = CFArrayGetValueAtIndex (langs, 0);
CFStringRef langName = CFLocaleCopyDisplayNameForPropertyValue (loc, kCFLocaleLanguageCode, langCode);
CFShow(langCode);
CFShow(langName);
}

How do I set an emblem with GTK/GIO?

I'm trying to set an emblem using gio
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
GFile *gfile = NULL;
g_type_init();
gfile = g_file_new_for_path("./foo.txt");
if (g_file_set_attribute_string(gfile,
"metadata::emblems",
"favorite",
G_FILE_QUERY_INFO_NONE,
NULL, NULL) == TRUE) {
puts("Success");
} else {
puts("Fail");
}
return 0;
}
if the file exists, the function returns TRUE, which, according the docs means the metadata was set, but Nautilus (GNOME) doesn't display the favorite emblem. There are not many example on the net, so I'm kind of stuck.
It looks like metadata::emblems needs an array of strings even if you are only setting one value.
This seems to work:
char *value[] = {"favorite", '\0'};
[...]
g_file_set_attribute(file, "metadata::emblems",
G_FILE_ATTRIBUTE_TYPE_STRINGV,
&value[0],
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
If you want Nautilus to show an emblem, you need to actually provide an extension to Nautilus to do so. Your extension should use the nautilus-info-provider interface, and in the nautilus_info_provider_update_file_info()
function you can call the nautilus_file_info_add_emblem() function to add an emblem.

Oracle client with OpenforwardOnly flag in database connection.

I am porting an existing windows based C++ application to 64 bit environment, and this is one of those weird errors.
In the code snippet you can that I am using openforwardonly and it used to work fine with our old setup but in the 64 bit environment it gives the problem of fetching only ONE recordset. Or it could be a problem with the MoveNext(); of ADO.
To circumvent it we started using adOpenStatic, and it worked fine for me for a while but only later realized that it has a performance hit and it is taking forever to get/iterative through values.
I request someone to try this code with both the flags and validate the behavior I am seeing.
Information about ado flags:
http://www.w3schools.com/ADO/met_rs_open.asp
Another EE topic
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_DB/Q_11520558.html
I remember seeing a MS support case, but I can't get to it now.
I would appreciate any help or suggestions. I know we are using old technology, but we want to move to the additional capabilities without changing code much.
// Dbtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <time.h>
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
int main(int argc, char* argv[])
{
HRESULT hr = S_OK;
try
{
CoInitialize(NULL);
_bstr_t strCnn("Provider=OraOLEDB.Oracle;Data Source =****; User Id=****; password=***");
_ConnectionPtr m_pConn;
hr=m_pConn.CreateInstance(__uuidof(Connection));
if(FAILED(hr))
{
printf("Failed creating record set instance\n");
return 0;
}
m_pConn->Open(strCnn,"","",NULL);
//Open the Record set for getting records from Author table
_RecordsetPtr pRstDoctors = NULL;
time_t start,end1,end2;
pRstDoctors.CreateInstance(__uuidof(Recordset));
time(&start);
pRstDoctors->Open("select logid from log",strCnn, adOpenForwardOnly,
**adLockReadOnly**,adCmdText);
//Declare a variable of type _bstr_t
int valField1;
//int valField2;
pRstDoctors->MoveFirst();
//Loop through the Record set
if (!pRstDoctors->EndOfFile)
{
while(!pRstDoctors->EndOfFile)
{
valField1 = pRstDoctors->Fields->GetItem("logid")->Value.intVal;
// valField2 = pRstDoctors->Fields->GetItem("reportid")->Value.intVal;
// printf("%d - \n",valField1);
pRstDoctors->MoveNext();
}
}
time(&end1);
double dif=difftime(end1,start);
printf("time difference is %.2lf",dif);
}
catch(_com_error e)
{
printf("Error:%s\n",e);
}
CoUninitialize();
return 0;
}
Using "adOpenStatic" instead of "adOpenForwardOnly" will work
pRstDoctors->Open("select logid from log",strCnn, adOpenStatic,
**adLockReadOnly**,adCmdText);

Resources