|
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I saw examples on the codeproject about it did you search on codeproject
|
|
|
|
|
How can I change IP address of my system programmatically ?
Thanks .
|
|
|
|
|
the IPM_SETADDRESS message
Tom
|
|
|
|
|
No sorry, Ihavn't woken up this morning yet, I was thinking of the IP control Sorry
Tom
|
|
|
|
|
Hi,
try to check this AddIPAddress[^], and analyze the sample
And other view on this issue (I'm not sure if recommended by MS) Changing IPADDRESS[^]
-----------
Mila
|
|
|
|
|
Here is another way of doing it, Sorry about earlier
<br />
**************************************************************************<br />
<br />
#define POLARITY<br />
#define _WIN32_DCOM<br />
<br />
#include <br />
#include <br />
using namespace std;<br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
<br />
#include <br />
<br />
int WMIEnableStatic()<br />
{<br />
IWbemLocator *pLocator = NULL;<br />
IWbemServices *pNamespace = 0;<br />
IWbemClassObject * pClass = NULL;<br />
IWbemClassObject * pOutInst = NULL;<br />
IWbemClassObject * pInClass = NULL;<br />
IWbemClassObject * pInInst = NULL;<br />
<br />
BSTR path = SysAllocString(L"root\\cimv2");<br />
BSTR ClassPath = SysAllocString(L"Win32_NetWorkAdapterConfiguration");<br />
BSTR InstancePath =<br />
SysAllocString(L"Win32_NetWorkAdapterConfiguration.Index='1'");<br />
BSTR MethodName = SysAllocString(L"EnableStatic");<br />
BSTR ArgName1 = SysAllocString(L"IPAddress");<br />
BSTR ArgName2 = SysAllocString(L"SubNetMask");<br />
<br />
<br />
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); <br />
<br />
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,<br />
RPC_C_AUTHN_LEVEL_CONNECT, <br />
RPC_C_IMP_LEVEL_IMPERSONATE, <br />
NULL, EOAC_NONE, 0<br />
);<br />
<br />
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,<br />
IID_IWbemLocator, (LPVOID *) &pLocator);<br />
<br />
hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL, NULL,<br />
&pNamespace);<br />
<br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
cout << "Connected to WMI" << endl;<br />
<br />
hr = CoSetProxyBlanket(pNamespace,<br />
RPC_C_AUTHN_WINNT,<br />
RPC_C_AUTHZ_NONE,<br />
NULL,<br />
RPC_C_AUTHN_LEVEL_CALL,<br />
RPC_C_IMP_LEVEL_IMPERSONATE,<br />
NULL,<br />
EOAC_NONE<br />
);<br />
<br />
<br />
<br />
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);<br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
<br />
<br />
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL); <br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
hr = pInClass->SpawnInstance(0, &pInInst);<br />
if(hr != WBEM_S_NO_ERROR)<br />
return 1;<br />
<br />
<br />
BSTR ip;<br />
ip = SysAllocString(L"10.0.0.3");<br />
<br />
BSTR mask;<br />
mask = SysAllocString(L"255.255.255.0");<br />
<br />
long index[]={0};<br />
<br />
SAFEARRAY *ip_list;<br />
ip_list = SafeArrayCreateVector(VT_BSTR,0,1);<br />
SafeArrayPutElement(ip_list,index,ip);<br />
<br />
SAFEARRAY *mask_list;<br />
mask_list = SafeArrayCreateVector(VT_BSTR,0,1);<br />
SafeArrayPutElement(mask_list,index,mask);<br />
<br />
VARIANT arg1;<br />
arg1.vt = VT_ARRAY|VT_BSTR;<br />
arg1.parray = ip_list;<br />
hr = pInInst->Put(ArgName1, 0, &arg1, 0);<br />
<br />
VARIANT arg2;<br />
arg2.vt = VT_ARRAY|VT_BSTR;;<br />
arg2.parray = mask_list;<br />
hr = pInInst->Put(ArgName2, 0, &arg2, 0);<br />
<br />
<br />
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL, pInInst,<br />
&pOutInst, NULL);<br />
if(hr != WBEM_S_NO_ERROR){<br />
cout << "ExecMethod failed " << hr;<br />
return 1;<br />
}<br />
<br />
<br />
VARIANT ret_value;<br />
BSTR strReturnValue = SysAllocString(L"ReturnValue");<br />
hr = pOutInst->Get(strReturnValue, 0, &ret_value, 0, 0);<br />
long ret = V_I4(&ret_value);<br />
if(ret != 0) {<br />
cout << "EnableStatic failed with return code = " << ret;<br />
}else{<br />
cout << "EnableStatic succeeded" << endl;<br />
}<br />
<br />
<br />
SysFreeString(strReturnValue);<br />
VariantClear(&ret_value);<br />
SysFreeString(ip);<br />
SysFreeString(mask);<br />
SafeArrayDestroy(ip_list);<br />
SafeArrayDestroy(mask_list);<br />
VariantClear(&arg1);<br />
VariantClear(&arg2);<br />
<br />
SysFreeString(path);<br />
SysFreeString(ClassPath);<br />
SysFreeString(InstancePath);<br />
SysFreeString(MethodName);<br />
SysFreeString(ArgName1);<br />
SysFreeString(ArgName2);<br />
<br />
pClass->Release();<br />
pInInst->Release();<br />
pInClass->Release();<br />
pOutInst->Release();<br />
pLocator->Release();<br />
pNamespace->Release();<br />
CoUninitialize();<br />
return 0;<br />
}
Hope this helps a bit more
Tom
|
|
|
|
|
edit you post and use the <pre></pre> tags around your code.
thanks you
|
|
|
|
|
As you prefer
**************************************************************************
#define POLARITY
#define _WIN32_DCOM
#include
#include
using namespace std;
#include
#include
#include
#include
#include
#include
#include
int WMIEnableStatic()
{
IWbemLocator *pLocator = NULL;
IWbemServices *pNamespace = 0;
IWbemClassObject * pClass = NULL;
IWbemClassObject * pOutInst = NULL;
IWbemClassObject * pInClass = NULL;
IWbemClassObject * pInInst = NULL;
BSTR path = SysAllocString(L"root\\cimv2");
BSTR ClassPath = SysAllocString(L"Win32_NetWorkAdapterConfiguration");
BSTR InstancePath =
SysAllocString(L"Win32_NetWorkAdapterConfiguration.Index='1'");
BSTR MethodName = SysAllocString(L"EnableStatic");
BSTR ArgName1 = SysAllocString(L"IPAddress");
BSTR ArgName2 = SysAllocString(L"SubNetMask");
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL, EOAC_NONE, 0
);
hr = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLocator);
hr = pLocator->ConnectServer(path, NULL, NULL, NULL, 0, NULL, NULL,
&pNamespace);
if(hr != WBEM_S_NO_ERROR)
return 1;
cout << "Connected to WMI" << endl;
hr = CoSetProxyBlanket(pNamespace,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
hr = pNamespace->GetObject(ClassPath, 0, NULL, &pClass, NULL);
if(hr != WBEM_S_NO_ERROR)
return 1;
hr = pClass->GetMethod(MethodName, 0, &pInClass, NULL);
if(hr != WBEM_S_NO_ERROR)
return 1;
hr = pInClass->SpawnInstance(0, &pInInst);
if(hr != WBEM_S_NO_ERROR)
return 1;
BSTR ip;
ip = SysAllocString(L"10.0.0.3");
BSTR mask;
mask = SysAllocString(L"255.255.255.0");
long index[]={0};
SAFEARRAY *ip_list;
ip_list = SafeArrayCreateVector(VT_BSTR,0,1);
SafeArrayPutElement(ip_list,index,ip);
SAFEARRAY *mask_list;
mask_list = SafeArrayCreateVector(VT_BSTR,0,1);
SafeArrayPutElement(mask_list,index,mask);
VARIANT arg1;
arg1.vt = VT_ARRAY|VT_BSTR;
arg1.parray = ip_list;
hr = pInInst->Put(ArgName1, 0, &arg1, 0);
VARIANT arg2;
arg2.vt = VT_ARRAY|VT_BSTR;;
arg2.parray = mask_list;
hr = pInInst->Put(ArgName2, 0, &arg2, 0);
hr = pNamespace->ExecMethod(InstancePath, MethodName, 0, NULL, pInInst,
&pOutInst, NULL);
if(hr != WBEM_S_NO_ERROR){
cout << "ExecMethod failed " << hr;
return 1;
}
VARIANT ret_value;
BSTR strReturnValue = SysAllocString(L"ReturnValue");
hr = pOutInst->Get(strReturnValue, 0, &ret_value, 0, 0);
long ret = V_I4(&ret_value);
if(ret != 0) {
cout << "EnableStatic failed with return code = " << ret;
}else{
cout << "EnableStatic succeeded" << endl;
}
SysFreeString(strReturnValue);
VariantClear(&ret_value);
SysFreeString(ip);
SysFreeString(mask);
SafeArrayDestroy(ip_list);
SafeArrayDestroy(mask_list);
VariantClear(&arg1);
VariantClear(&arg2);
SysFreeString(path);
SysFreeString(ClassPath);
SysFreeString(InstancePath);
SysFreeString(MethodName);
SysFreeString(ArgName1);
SysFreeString(ArgName2);
pClass->Release();
pInInst->Release();
pInClass->Release();
pOutInst->Release();
pLocator->Release();
pNamespace->Release();
CoUninitialize();
return 0;
}
I've never used these before. What's the deal? the code seemed to apear as it should
tom
|
|
|
|
|
Why did you suggest I did that?
It looks terrible, all the formatting has gone!
Tom
|
|
|
|
|
first of all, i told you to EDIT the existing post, to resposting again and again a huge bloc of code.
moreover, why i told you to use it? because Chris asks us to[^] (see 5.)! the code samples should be embraced by pre tags.
at last, it DOES PRESERVE the formating, but you used it wrongly.
if you want to see the empty lines, place at least a space on those lines.
and if you want to see some indentation, just put some spaces at the beginning ot your lines, and you'll see the spaces that doesn't appear in normal case...
oh, i was forgetting : when you put some #include statement, use the < and > html codes to print < > , otherwise, your include headers will be understood as html tags too.
|
|
|
|
|
Thanks to your advice I also noted Chris said:
"Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job."
But, before this gets more out of shape. I agree what you said was completly valid as far as the response protocols I employed is concerned (That won't happen again) but the way you said it did not inspire me to seek to thoroughly correct myself.
Sorry if I pressed your buttons though.
Tom
|
|
|
|
|
i don't think i shouted though. i simply insisted on some words.
you could have said so if my sentence was all in caps...
btw, sorry if i hurted you, but loading the boards with huge posts and reposts is not helping...
|
|
|
|
|
heh! Good post though!
I'm sure glad there's .NET for WMI - doing it in straight C/C++ is wordy!
|
|
|
|
|
Thanks Mark
|
|
|
|
|
Thanks friends TClarke,toxcct and Mila025 for your guide .
|
|
|
|
|
The following won't compile with the following error :
error C2660: 'B::f()' : function does not take 2 arguments
class A{<br />
public:<br />
virtual void f(int a, int b); <br />
};<br />
<br />
class B : public A{<br />
virtual void f(int a)<br />
{<br />
f(a, 1);<br />
}<br />
};
I fail to see the logic error !!! can anyway shed some light ?
Odesh
|
|
|
|
|
-- forget, nothing interresting here --
|
|
|
|
|
toxcct wrote: the function A::f() inherited mush be implemented
Again, this is false. This statement is true only if the function is pure virtual. You can perfectly have a virtual function in the base class which is not implemented in one or several derived classes (even not implemented at all in the derived classes).
|
|
|
|
|
odesh wrote: error C2660: 'B::f()' : function does not take 2 arguments
I think you should try this:
class B : public A
{
virtual void f(int a)
{
A::f(a, 1);
}
};
I hope this helps.
|
|
|
|
|
won't compile more. A::f() is virtual, so, not implemented...
moreover, the compilation error is no B::f() implementation overloads A::f()
|
|
|
|
|
toxcct wrote: A::f() is virtual, so, not implemented...
You can perfectly have a virtual function that is implemented in the base class. Making it virtual doesn't mean that you cannot implement it. I think you mix it with a pure virtual function which is:
virtual void f() = 0;
|
|
|
|
|
Cedric Moonen wrote: You can perfectly have a virtual function that is implemented in the base class
yes, i know that, but it didn't seem to be here...
|
|
|
|
|
The proposed solution solves the compilation error message mentioned in the original post: "error C2660: 'B::f()' : function does not take 2 arguments". In my opinion, just adding an implementation for A::f() is not a solution for original problem. Missing implementation (if really was not done by the author) will be reported on linking phase.
|
|
|
|
|
The problem is that function overloading is limited at the class scope, that means you cannot overload a function in a derived class (or you need to implement the function which is overloaded too).
|
|
|
|
|