|
You can use of CreateProcess
|
|
|
|
|
|
Code like this[^] will do the trick.
Steve
|
|
|
|
|
how to run msdos command from mfc for example ipconfig
|
|
|
|
|
Take a look at CreateProcess.
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));<br />
StartupInfo.cb = sizeof (StartupInfo) ;
<br />
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;<br />
StartupInfo.wShowWindow = false;<br />
<br />
if(CreateProcess("c:\\Windows\\System32\\defrag.exe", <br />
"defrag C: /v", <br />
NULL,NULL,FALSE,0,NULL,<br />
NULL,&StartupInfo,&ProcessInfo))<br />
<br />
...
Hope this helps.
|
|
|
|
|
Running DOS/Command-Line apps does not appear to be your problem, but rather how to capture the output from running one. Do an MSDN search for "redirected console handles" for ways to do this without doing redirection-to-file.
This may be the better way, if you have no other way to get the same information directly from the Win32 API, because the user your app may be running under may not have permission to create a file.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Perhaps this will help:
#include "StdAfx.h"
#include <process.h>
int main()
{
system("ipconfig");
return 0;
}
To output result to a file use this line instead:
system("ipconfig > C:\\Log.txt");
Steve
|
|
|
|
|
yes i got it for ipconfig. but when i tried the same for netsh as system("netsh -c interface dump > e:\boot\net") i cant get it. i have to redirect this output to my flash drive which will be in e:\
|
|
|
|
|
I tried this and it works just fine:
#include "StdAfx.h"
#include <process.h>
int main()
{
system("netsh -c interface dump > C:\\Log.txt");
return 0;
}
Looks like you're redirecting to a directory (or a file in the "boot" directory called "net" with no extension). Also, are you ecscaping your backslashes?
Steve
|
|
|
|
|
no net is a folder inside boot. see this is what i have done.
char para3[1024];
strcpy (para3, "\0");
strcat (para3, cRemovableDrive);
strcat (para3, ":\\boot\\net\\ipconf");
system("netsh -c interface dump > para3");
is this correct. the same thing which i have done for ipconfig (system("ipconfig > para3"))
works well
|
|
|
|
|
Using strcpy and fixed sized buffers is crap: use CString instead (after all, you're using MFC). Try this:
CString para3;
para3.Format(_T("%c:\\boot\\net\\ipconf.txt"), cRemovableDrive);
CString command;
command.Format(_T("netsh -c interface dump > %s"), para3);
system(command);
Steve
|
|
|
|
|
thanks a lot. its working well. but how to disable the command promt window while executing sytem command
-- modified at 0:29 Tuesday 6th March, 2007
|
|
|
|
|
That's not so easy. You'll have to do a lot more work.
Steve
|
|
|
|
|
Replace system with code something like this:
ShellExecute(
NULL,
"open",
"cmd",
"/C \"netsh -c interface dump > C:\\Log.txt\"",
NULL,
SW_HIDE
);
Steve
|
|
|
|
|
hi i have to get the output of netsh -c interface dump to a file. i coded as
char para3[1024];
strcpy (para3, "\0");
strcat (para3, "netsh -c interface dump > ");
strcat (para3, cRemovableDrive);
strcat (para3, ":\\boot\\net\\ipconf");
src=cOperatingSysDrive;
src+=":\\windows\\system32\\cmd.exe ";
hInt = ShellExecute(NULL,"open",src, para3,NULL,SW_HIDE);
but i didnt get the output in the file. anyone know this
|
|
|
|
|
Have you seen content of para3 , is it correct ?
It is good practice to intialize array on declaration , Modify your code to,
char para3[1024] = {'\0'};
strcat (para3, "netsh -c interface dump > ");
strcat (para3, cRemovableDrive);
strcat (para3, ":\\boot\\net\\ipconf");
|
|
|
|
|
i initialised the array. but now also i the file ipconf was not created
how to capture the output from netsh in mfc
-- modified at 11:25 Monday 5th March, 2007
|
|
|
|
|
ShellExecute() doesn't interpret the command line's redirection syntax, it takes the entire string you pass it and looks for a file with that name.
|
|
|
|
|
Hi,
How can you programatically find which bluetooth stack is present on a windows PC.
Regards,
Deepak
|
|
|
|
|
Hello,
How can I properly create and use a CPropertySheet object with vertically arranged pages?
Here I've uploaded a demo project with source code included. It's just a simple SDI application which has main view class CVerticalPropSheetView (derived from CView) containing property sheet CPropSheetDemo (derived from CPropertySheet) with 3 property pages:
http://forum.codenet.ru/attachment....=1&d=1173007311
http://www.rsdn.ru:80/File/35531/VerticalPropSheet.rar
I tried to follow the advice from one of topics at CodeGuru forum (http://www.codeguru.com/forum/archi...p/t-331500.html) however, I've discovered the following issues related to resizing of the property sheet's window in CVerticalPropSheetView::OnSize():
1) When changing size of CPropSheetDemo window so that its width is less than its height, the tabs of the bottom property pages are not properly drawn. It looks like only rectangle part of property sheet (width x width) is being drawn properly.
2) When changing height of CPropertySheet window so that it can't display all tabs, the spin control is displayed. However, it doesn't work (I can't choose tab using spin control).
Does anyone know how to resolve these issues? All above appears only when property pages are arranged vertically - e.g. until I comment the following lines of code in CPropSheetDemo::OnInitDialog():
// create the new font for property pages' titles
CreateNewFont(&m_Font,14,_T("Microsoft Sans Serif"));
// make our property sheet vertical-oriented
CWnd* pctrlTab=GetDlgItem(AFX_IDC_TAB_CONTROL);
if (pctrlTab!=NULL) {
pctrlTab->ModifyStyle(TCS_FOCUSONBUTTONDOWN,TCS_VERTICAL,0);
pctrlTab->SetFont(&m_Font);
}
Many thanks in advance!
dp
|
|
|
|
|
Hi
I tried to write copy-constructor example. It compiles well but gives me run-time error
#include <iostream><br />
using namespace std;<br />
<br />
class MyClass <br />
{<br />
private:<br />
int* x;<br />
char ch;<br />
public:<br />
MyClass();<br />
MyClass(int i, char ch1);<br />
MyClass(const MyClass& MyClass);<br />
~MyClass();<br />
MyClass& operator=(const MyClass& MyClass);<br />
void Show(MyClass MyClass1,MyClass s2);<br />
};<br />
void MyClass::Show(MyClass myClass1, MyClass myClass2)<br />
{<br />
cout << myClass1.ch << "..." << *(myClass1.x);<br />
cout << myClass2.ch << "..." << *(myClass2.x);<br />
};<br />
<br />
MyClass::MyClass()<br />
{<br />
x = new int(8);<br />
ch = 'a';<br />
cout << "default copy constructor";<br />
};<br />
MyClass::MyClass(int i, char ch1):ch(ch1)<br />
{<br />
x = new int(i);<br />
};<br />
<br />
MyClass::MyClass(const MyClass &MyClass)<br />
{<br />
this->ch = MyClass.ch;<br />
x = new int(*MyClass.x);<br />
};<br />
MyClass& MyClass::operator=(const MyClass &MyClass)<br />
{<br />
this->ch = MyClass.ch;<br />
x = new int( *MyClass.x);<br />
return *this;<br />
};<br />
MyClass::~MyClass()<br />
{<br />
delete x;<br />
}<br />
<br />
int main()<br />
{<br />
int s =5;<br />
int s1 = 8;<br />
MyClass *myClass1 = new MyClass(s, 'a');<br />
MyClass *myClass2 = new MyClass(s1, 'b');<br />
myClass1 = myClass2;<br />
MyClass *asılMyClass = new MyClass();<br />
asılMyClass->Show(*myClass1, *myClass2);<br />
delete asılMyClass;<br />
delete myClass1;<br />
delete myClass2;<br />
<br />
<br />
<br />
}
I think i made mistake at that line :
x = new int( *MyClass.x);
But if i change it to
x = new int(MyClass.x);
It gives me that error:
cannot convert from 'int *const ' to 'int'
How can i fix it?
Can you please explain my mistake.
Thanks..
|
|
|
|
|
sawerr wrote: I think i made mistake at that line :
No, that's not your problem. Your problem is because you are copying pointers and not object. So, first, the copy constructor or the = operator won't be called but two pointers will point at the same memory location and if you delete them both, you'll get a crash.
sawerr wrote:
MyClass *myClass1 = new MyClass(s, 'a');<br />
MyClass *myClass2 = new MyClass(s1, 'b');<br />
myClass1 = myClass2;
This is your problem: at the end, myClass1 and myClass2 will point to the same memory location (remember that you play with pointers here, not with objects, that makes a HUGE difference).
If you want to use the =operator, you need to do this instead:
*myClass1 = *myClass2;
But I would advice that you don't allocate your objects dynamically, why do you need to use new here ?
|
|
|
|
|
Thank you very much.
I understood.
Thanks for help.
|
|
|
|
|
Hi,
Are you aware that with
myClass1 = myClass2;
you are making a pointer assignment, instead of calling the operator= function? The program of course crashes then when you do delete myClass2, since the object has been already deleted the line before. In order to call the assigment operator of your class, you have to say:
*myClass1 = *myClass2;
The copy constructor itself does not look too bad...
Regards
|
|
|
|
|
Hello,
How do I make my application work on a PC where VC++ is not loaded ?
How do I make an exe of my application?
Is there an article which will tell me the steps to make the exe.
Thanks
Prithaa
|
|
|
|