|
Sir can you give me some line of code example?.Plz help me
|
|
|
|
|
Davitor wrote: Sir can you give me some line of code example?
Well, which problem are you facing now? Please be specific, so that I can try my best.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Command line problem?
When System is start that time my applcation is run in hidden mode?
I am set path of exe in registry but i havn't know how to use command line for startup.So plz help me
|
|
|
|
|
You can pass the command line together with exe path. For instance, in your case, add the registry value as C:\hello.exe /startup . And if you call GetCommandLine() in your application, you will get the /startup string. Hope its clear.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thanks for vital nformation but can you give me only some line of example code.Plz help.
i am doing like that.But not geting result.
ln=GetCommandLine();
ln +="-help";
AfxMessageBox(ln);
Plz help me
|
|
|
|
|
|
i tried to get information from remote machine using WMI by vc6,
i can connect with remote machine ,but i fail to get the infomation,
and then i tried wbemtest tool, there is no problem between the two computers,
here is my code ,Any suggestion will be really appreciated!
#define _WIN32_DCOM
#include <iostream>
#include <comdef.h>
#include <wbemidl.h>
# pragma comment(lib, "wbemuuid.lib")
#include <atlbase.h>
#include <windows.h>
#include <wincred.h>
# pragma comment(lib, "credui.lib")
using namespace std;
int main(int argc, char **argv)
{
HRESULT hres;
// Step 1: --------------------------------------------------
// Initialize COM. ------------------------------------------
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. Error code = 0x"
<< hex << hres << 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))
{
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))
{
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;
// Get the user name and password for the remote computer
CREDUI_INFO cui;
TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH+1]="user";
TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH+1]="pass";
BOOL fSave;
DWORD dwErr;
cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
// Ensure that MessageText and CaptionText identify
// what credentials to use and which application requires them.
cui.pszMessageText = TEXT("Remote computer account information");
cui.pszCaptionText = TEXT("Enter Account Information");
cui.hbmBanner = NULL;
fSave = FALSE;
dwErr = CredUIPromptForCredentials(
&cui, // CREDUI_INFO structure
TEXT("\\10.7.24.83"), // Target for credentials
NULL, // Reserved
0, // Reason
pszName, // User name
CREDUI_MAX_USERNAME_LENGTH+1, // Max number for user name
pszPwd, // Password
CREDUI_MAX_PASSWORD_LENGTH+1, // Max number for password
&fSave, // State of save check box
CREDUI_FLAGS_GENERIC_CREDENTIALS | // flags
CREDUI_FLAGS_ALWAYS_SHOW_UI |
CREDUI_FLAGS_DO_NOT_PERSIST);
if(dwErr)
{
cout << "Did not get credentials." << endl;
pLoc->Release();
CoUninitialize();
return 1;
}
// 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"\\\\10.10.13.48\\root\\cimv2"),
_bstr_t("user"), // User name
_bstr_t("pass"), // User password
_bstr_t(L"MS_409"), // Locale
NULL, // Security flags
_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))
{
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;
// Step 5: --------------------------------------------------
// Set security levels on a WMI connection ------------------
SEC_WINNT_AUTH_IDENTITY_W* pAuthIdentity =
new SEC_WINNT_AUTH_IDENTITY_W;
ZeroMemory(pAuthIdentity, sizeof(SEC_WINNT_AUTH_IDENTITY_W));
pAuthIdentity->User = new WCHAR[32];
wcscpy(pAuthIdentity->User , L"user" );
pAuthIdentity->UserLength = wcslen(pAuthIdentity->User);
pAuthIdentity->Domain = new WCHAR[32];
wcscpy(pAuthIdentity->Domain, L"\\10.10.13.48");
pAuthIdentity->DomainLength = wcslen( pAuthIdentity->Domain);
pAuthIdentity->Password = new WCHAR[32];
wcscpy(pAuthIdentity->Password, L"pass" );
pAuthIdentity->PasswordLength = wcslen( pAuthIdentity->Password);
pAuthIdentity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
pAuthIdentity, // client identity
EOAC_NONE // proxy capabilities
);
if (FAILED(hres))
{
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))
{
cout << "Query for operating system name failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.ad
}
// Step 7: -------------------------------------------------
// Get the data from the query in step 6 -------------------
IWbemClassObject *pclsObj=NULL;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn) //But uReturn =0 all the time!
{
break; // break every time!
}
VARIANT 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(); //often return "access deny"
Sleep(1000);
CoUninitialize();
return 0; // Program successfully completed.
}
Report post as abusive
|
|
|
|
|
I see you've put plenty of output statements in your program, to show what's happening or failing - might help if you shared the output of the program with us, just in case it gave some pointers as to the problem?
|
|
|
|
|
thank you for your reply!
just "connect ..." was put out,everything seemed to be fine.
but after debug ,i found:
if(0 == uReturn) //uReturn =0 all the time!
{
break; // break every time!
}
....
pclsObj->Release(); //often return "access deny"
|
|
|
|
|
I notice you don't check the result of the enumerator Next call:
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
Maybe its HRESULT indicates an error?
One last thing - maybe you could prototype & debug using VBScript, as documented here[^]? Then you can be sure that the use casse you're implementing is valid? And it's a lot quicker to prototype in a scripting language...
|
|
|
|
|
yes,i checked it
if(SUCCEEDED(hr))
{.......}
pEnumerator->Next SUCCEEDED(hr) return False,
but what leads to the error
|
|
|
|
|
TechCrazy wrote: but what leads to the error
The HRESULT value may give you a hint. I would be willing to bet its returning 0x80070005 - E_ACCESSDENIED.
Best Wishes,
-David Delaune
|
|
|
|
|
maybe it was
but right now ,i created a account in target machine ,the same username and password with my machine, and the code worked !!!!
i still don't know why
|
|
|
|
|
TechCrazy wrote: maybe it was
but right now ,i created a account in target machine ,the same username and password with my machine, and the code worked !!!!
i still don't know why
Seems pretty obvious it was security related...it failed until you created an account on the other machine with the same credentials as the one you were running the program with.
I notice in your program that you prompt for a username and password, but then just use hard-coded values. That seems to be the single deviation between your program and this sample one in MSDN[^].
I think you need to do some reading, to understand how all this works, rather than taking a sample and poking it to try to get you get what you want.
|
|
|
|
|
|
Hi,
I'm working on a project with the following configuration:
- several static libraries (*.lib) which contains some services.
- MFC application which link to the above libraries in order to use it's services.
All of the projects stored in the same solution.
One of the static libraries contain a static array with a predefined size.
I know that if I add the header of that library to my MFC application project(the only project which is an executable file) and recompile the entire solution , the array will be allocated according to the specified size in the overriden file.
The problem is that now I don't have the libraries in my solution(instead - I only get the *.lib files),therefor, I can't recompile those libraries(and still - I need to change the size of that array from the MFC application project).
Is it possible?(Is there a compiler setting which I missed????)
With best regards,
Eli
|
|
|
|
|
You can't change the size of the array. The libraries only 'know' the size of the array that was in effect when they were originally compiled.
|
|
|
|
|
Hi experts!
well as i'm developping an advenced chat application using MFC winsock (VS2005) under windows Vista and windows XP, i faced some problems,i could solve some of it, however i couldn't solve other problems..
- the first problem is when the client opens a public chat room or any other window, the rest of application must stay responsive and the user can access it! the problem is when i use DoModal method for the dialogs or any similar method (that have it's own message loop!) the main window is not responding anymore!
- tried solutions:
i tryed UI threads but i still have the same problem!
wel hope you have a solution for me.. (maybe about Non-Modal dialog boxes or so..)
(just an example: i want sth like in yahoo messenger where the user can open many windows and still able to use the main window or any other window)
waiting for your answers
Some People dream of success while others woke-up and are working to get it..
|
|
|
|
|
For short, how to create many dialogboxes and the main window stays responsive and i can acces any shown window (like the messenger chat)
|
|
|
|
|
|
Thank's bro,
that's it, it works now..
|
|
|
|
|
Hi all !
I'm using the MFC sockets mechanism for TCP\IP communication (CSocket, Srialization ability etc.) in a Process that spawns some threads.
It works fine until I deliver the socket pointer to one of the threads created by this process so that it can use it to send messages through this socket too - the application then fails, and if I understand correctly it is since the only thread allowed to use this socket is the one created it (in my case the main process).
I'm looking for an elegant solution to this limitation (I can go around the problem in several ways but it might affect the complexity and run-time of the program).
Any suggestions ???
Thanks in advanced,
Amit
|
|
|
|
|
You secondary thread may possibly post messages to the primary one and let the latter do socket processing.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
...or you can stop using CSocket (it's really only a useful class for the most
basic socket application) and use CAsyncSocket instead.
If you'll be using the same socket from different threads, you'll want to use
events instead of window messages for socket notifications.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
AmitCohen222 wrote: if I understand correctly it is since the only thread allowed to use this socket is the one created it
Not exactly, it's got to do with a bug in MFC. See knowledge base Q193101[^] - I had a similar problem and calling AfxSocketInit() in each thread fixed it.
|
|
|
|
|