|
|
Hi all:
i am having a problem connecting to query wmi object
HRESULT hres;
// Step 1: --------------------------------------------------
// Initialize COM. ------------------------------------------
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
std::cout << "Failed to initialize COM library. Error code = 0x" << hex << hres << std::endl;
return 1; // Program has failed.
}
// Step 2: --------------------------------------------------
// Set general COM security levels --------------------------
// Note: If you are using Windows 2000, you need to specify -
// the default authentication credentials for a user by using
// a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
// parameter of CoInitializeSecurity ------------------------
hres = CoInitializeSecurity(
NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hres))
{
std::cout << "Failed to initialize security. Error code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
// Step 3: ---------------------------------------------------
// Obtain the initial locator to WMI -------------------------
IWbemLocator *pLoc = NULL;
hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hres))
{
std::cout << "Failed to create IWbemLocator object."
<< " Err code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
}
// Step 4: -----------------------------------------------------
// Connect to WMI through the IWbemLocator::ConnectServer method
IWbemServices *pSvc = NULL;
// Connect to the remote root\cimv2 namespace
// and obtain pointer pSvc to make IWbemServices calls.
//---------------------------------------------------------
// change the computerName and domain
// strings below to the full computer name and domain
// of the remote computer
hres = pLoc->ConnectServer(
_bstr_t(L"\\\\192.168.1.243\\ROOT\\cimv2"),
_bstr_t(L"username"), // User name
_bstr_t(L"password"), // User password
_bstr_t(L"MS_409"), // Locale
NULL, // Security flags
NULL, //_bstr_t(L"ntlmdomain:domain"), // Authority
0, // Context object
&pSvc // IWbemServices proxy
);
// When you have finished using the credentials,
// erase them from memory.
//SecureZeroMemory(pszName, sizeof(pszName));
//SecureZeroMemory(pszPwd, sizeof(pszPwd));
if (FAILED(hres))
{
std::cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
std::cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
if (FAILED(hres))
{
std::cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
// Step 6: --------------------------------------------------
// Use the IWbemServices pointer to make requests of WMI ----
// For example, get the name of the operating system
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("Select * from Win32_OperatingSystem"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
std::cout << "Query for operating system name failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
// Step 7: -------------------------------------------------
// Get the data from the query in step 6 -------------------
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
VariantInit(&vtProp);
// Get the value of the Name property
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
wcout << " OS Name : " << vtProp.bstrVal << endl;
// Get the value of the FreePhysicalMemory property
hr = pclsObj->Get(L"FreePhysicalMemory",
0, &vtProp, 0, 0);
wcout << " Free physical memory (in kilobytes): "
<< vtProp.uintVal << endl;
VariantClear(&vtProp);
}
// Cleanup
// ========
pSvc->Release();
pLoc->Release();
pEnumerator->Release();
pclsObj->Release();
CoUninitialize();
return 0; // Program successfully completed.
running this program, it shows the followings
Connected to ROOT\CIMV2 WMI namespace
Query for operating system name failed. Error code = 0x80070005
anyone helps?
|
|
|
|
|
Hi
Im in a fix regarding accessing the flexgrid control of my dialog.
Im calling my dll(MFC) through an exe. In the dll there is a dialog that contains the FlexGrid. on calling of the dll the dialog box gets called. now i want to populate the grid with some data but im unable to access the flexgrid. On accessing the method of the grid it is showing Assertion error.
I know there are gurus in VC++ and hope you will assist me or give me any pointers.
Your help is greatly appreciated.
|
|
|
|
|
How can I detect when the ALT key is pressed and no other key is pressed? I wanted to change my cursor when the ALT is pressed. So i wanted to know which message is sent in this case.
Thanks
|
|
|
|
|
Try with WM_SYSKEYDOWN
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
It works only if i press a key followed by ALT. I want an event which fires when i press just the ALT key .
|
|
|
|
|
Is GetAsyncKeyState() of any help?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Yes i am using it get the state of the ALT key but the point is I want to change my cursor as soon as the user presses the ALT key so for that i would require an event being fired or Currently i am using a timer which uses GetAsyncKeyState() to get the state and then i change the app cursor.
Thanks
|
|
|
|
|
Vikash Dubey wrote:
It works only if i press a key followed by ALT.
Could you show me how and where you have written the code.
<bold>- Nilesh
<italics>"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
What about the WM_CHAR message?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi Everybody!
what shude I do for create and develop a simple Windows Service in "Visual Studio.Net 2003" with "Visual C++" Project Type?
Is it possible that I use the "MFC" instructions in this?
If the answer is "Yes" please tel me "What To Do?"
and if not, please help me in another way.
Thanks for your guidance.
|
|
|
|
|
|
Hello everybody,
I'm looking for a client library to get and delete mails from an imap server.
Now, I use the IP Works library and the delete of the mails is too long (30 sec).
Thanks
BriceDeNice
|
|
|
|
|
On one of my dialogs I have about 70 check boxes which when checked toggle the associated bool value in an array (one bool for every check box).
Rather than create 70 check boxes on the dialog and also then write (copy) the handling code for each check box, is there an easy way to do this?
|
|
|
|
|
I would do it like that: you keep an array of CButton (I think this is the class that handle check boxes messages), then in OnInitDialog, I will instantiate this array and create the check boxes:
BOOL CyourDlg::OnInitDialog()<br />
{<br />
m_pCheckBoxesArray = new CButton[m_ChckBoxCount];<br />
for (int i=0;i<ChckBoxCount;i++)<br />
m_pCheckBoxesArray[i].Create(......);<br />
}
In the Create function, you will need to pass the Id of the control and its position. For the Id, edit the ressource file and use consecutive Id's so you can just do something like that:
for (int i=0;i<ChckBoxCount;i++)<br />
m_pCheckBoxesArray[i].Create(.., IDC_FIRSTCHCKBOX+i ,....);<br />
In the ressource file, you can do something like that:
#define IDC_FIRSTCHCKBOX 10000<br />
#define IDC_LASTCHCKBOX 10070
Then you can use the ON_CONTROL_RANGE macro instead of ON_COMMAND to map the notification messages of all your check boxes (take a look in the MSDN).
Hope this helps
|
|
|
|
|
thanks, I'll give this a try,
Andy
|
|
|
|
|
If I were you I would decide whether I need so much of them and they are all needed at once. Notice that this way gives you 2^about70 different combinations. Is every combination allowed and does make sense? I would reprogram this interface.
|
|
|
|
|
|
I have downloaded a sample program from this web-site to read data from a com-port.
When I compile and run everything is fine.
When I edit the code, and then change it back to it's original, and run the program, every second character that is recieved by the comport is false. ie.
vv.v.v.v.v.v.v.v.v.v.v.v.v.v. or 00°0°0°0°0°0°0°0°0, I can't show all the wierd characters as they are not on the keyboard.
but if I only send 1 or 2 of the same characters, then it is ok, ie.
aabbccddefghij and so on
Does anyone know what the problem might be? I'm using Visual c++ 6
I think it might be using Unicode, but still don't understand why it'll do it if I change it back to the original code. For it to work again, I have to run a fresh copy of the source code.
Thanks heaps!
(Leonardo da Vinci)
Simplicity is the ultimate sophistication.
|
|
|
|
|
Show the code in which you send the data.
|
|
|
|
|
Part of the code, link is at the bottom.
LRESULT CChildView::OnSerialMsg (WPARAM wParam, LPARAM /*lParam*/)
{
CSerial::EEvent eEvent = CSerial::EEvent(LOWORD(wParam));
CSerial::EError eError = CSerial::EError(HIWORD(wParam));
if (eError)
DisplayEvent(_T("An internal error occurred."));
.
.
. //many if statements
.
.
if (eEvent & CSerial::EEventRecv)
{
// Create a clean buffer
DWORD dwRead;
char szData[101];
const int nBuflen = sizeof(szData)-1;
// Obtain the data from the serial port
do
{
m_serial.Read(szData,nBuflen,&dwRead);
szData[dwRead] = '\0';
// Scan the string for unwanted characters
for (DWORD dwChar=0; dwChar
|
|
|
|
|
Hi group
Can anybody help me out
I want to change the background color of the header(column tab)in the ListControl
Actually i am doing a project in VC++
I am able to change the background color of the CListCtrl but i failed to change the color of the header tab,
so can anybody help me out
VC++
vcforums@gmail.com
|
|
|
|
|
Hi,
you need to owner-draw the complete headercontrol to do so, which means:
- subclass the header control that is a child of the listcontrol in its PreSubclassWIndow handler
- for every button in the headercontrol set the HDF-OWNERDRAW flag
- draw the button in the DrawItem handler
takes only some 100 lines of code...
dirk
|
|
|
|
|
Hi,
I have created a CWnd in a CPropertyPage. I want to display some drawing inside the CWnd. How can this be achieved?
I tried the following approaches but did not succeed:
1) Tried creating CWnd object in the CPropertyPage class and then override the OnInit function to draw . I used the GetDC() to get the CDC and then the GetSafeHandle() function to get the HDC. I used this handle to render my drawing. The CWnd was created but the drawing is not displayed.
2) According to a suggestion from a colleague, I tried creating separate class for the CWnd object. This was to let me override the OnPaint function of the CWnd object.
My code in OnPaint function is as follows:
PAINTSTRUCT ps;
CDC * dc = this->BeginPaint(&ps);
//draw function takes in the CDC * dc obtained in fuction above
draw();
this->EndPaint( &ps );
Then I created a object of this class in CPropertyPage class. I tried calling the create function in the constructor and OnCreate function of the property page. Here again I could at the most get my window displayed but no drawing.
Any suggestions on how to achieve this?
Also, does MFC basically support GDI in CWnd objects when created as child window of a dialog or property page?
P.S. to make sure that the code to draw is working correctly, I tried testin that by having the rendering in a document using the view class. It works correctly i.e. I can get the display in a document window but cannot get it in dialog window or to be precise CWnd instance.
Thanks in advance for your help.
Regards,
Abhijit Deshmukh
|
|
|
|
|
Hi everyone.
I have an application with a photo realistic interface and i want to use a non standard LCD type font. Is there some way i can include this inside the app like a resource, or do i really need to install it onto the users machine with the program? I cant seem to find any information on how to do this?
Any pointers would be appreciated
M
|
|
|
|