Solved

nbtstat & DOS commands

Posted on 2002-03-20
1
804 Views
Last Modified: 2012-08-13
I would like to find an option by which I can run all DOS commands in hidden mode.
For example I would like to use nbtstat command line utility from my MFC program, but when I use it I get an DOS window. I would like to hide the DOS window and run the command.


Thanks
saravana
0
Comment
Question by:vsaravana
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6882639
Use 'CreateProcess()' to achieve that. Basically, what you have to do is to

BOOL ExecuteAndWaitForCompletion ( LPTSTR pszCmd) {

BOOL bRes;
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory ( &si, sizeof ( STARTUPINFO));

si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;

    bRes     =     CreateProcess     ( NULL,
                                        pszCmd,
                                        NULL,
                                        NULL,
                                        TRUE,
                                        NORMAL_PRIORITY_CLASS,
                                        NULL,
                                        NULL,
                                        &si,
                                        &pi
                                       );

WaitForSingleObject     (     pi.hProcess,     INFINITE);

CloseHandle( pi.hProcess);
CloseHandle( pi.hThread);

return ( bRes);
}

(if you don't want this function to wait, remove the line containing 'WaitForSingleObject()')
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now