| View previous topic :: View next topic |
| Author |
Message |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu Aug 21, 2008 12:19 am Post subject: [c++] system("cmd line...") |
|
|
does anyone know how to execute a system cmdline without poping up cmd window :/
i tried to use system(), it pops up a new window each time i use it. really annoying
_________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils
Last edited by Bizarro on Thu Aug 21, 2008 12:20 am; edited 1 time in total |
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Thu Aug 21, 2008 12:20 am Post subject: |
|
|
What are you wanting to do on the command line?
_________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu Aug 21, 2008 12:21 am Post subject: |
|
|
"sc create"
"sc start"
i use these cmd instead of CreateServices/StartServices because its much easier. all i need is 2 lines of cmd code instead of 2 pages winapi codes :/
_________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Thu Aug 21, 2008 12:24 am Post subject: |
|
|
the command prompt executes programs from system32 folder, for example "shutdown -s" will start shutdown.exe with 1 parameter, 's'.
The commands you see when you type "help" are batch commands, which you can use any language to perform those. (if, else, copy files, moving files, creating folders, thats pretty much everything...)
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Thu Aug 21, 2008 12:31 am Post subject: |
|
|
its like
output = CMD.exe [input_command]
but C++ has built in function
system();
system("PAUSE");
would do command prompt command PAUSE.
http://www.cplusplus.com/reference/clibrary/cstdlib/system.html
IDK how to get stuff back doesn't seem like it gives stuff back
u might have to mess with GetStdHandle
_________________
|
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Thu Aug 21, 2008 12:33 am Post subject: |
|
|
Pretty much anything you want to run off the command line will open up a window. As Symbol said, it just runs separate programs from the system32 folder. You're better off just using Win32 API to do most things. Because using system() just makes things slow and laggy. Its just not worth it.
_________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Thu Aug 21, 2008 12:35 am Post subject: |
|
|
No u could mess with GetStdHandle.. and make a re-roution to your old console.. idk how.. but a friend once did it for me.. its when I was trying to make my own IDE for java compiling in C++.
_________________
|
|
| Back to top |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Thu Aug 21, 2008 1:33 am Post subject: |
|
|
you don't know what he's talking about. he's trying to start his driver.
_________________
|
|
| Back to top |
|
 |
Wintermoot Expert Cheater
Reputation: 0
Joined: 08 Nov 2007 Posts: 198
|
Posted: Thu Aug 21, 2008 4:35 am Post subject: |
|
|
| The hacked up crappy way is to code your program to make a batch file that will do what you want then delete the batch file...
|
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu Aug 21, 2008 4:38 am Post subject: |
|
|
| HawwwaH wrote: | | The hacked up crappy way is to code your program to make a batch file that will do what you want then delete the batch file... |
but does that still show a cmd window?
_________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Thu Aug 21, 2008 5:03 am Post subject: |
|
|
Why don't you do it the proper way?
There is a header file from Microsoft that makes this very easy.
If you really want to do it that way, then I suppose you can try to get a handle for the window and hide it.
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Thu Aug 21, 2008 5:04 am Post subject: |
|
|
You really shouldn't do it this way! You should write a function (which could be used later with some other code.)
But anyway, something like this should work: | Code: | STARTUPINFO si;
PROCESS_INFORMATION pi;
::ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
::ZeroMemory( &pi, sizeof(pi) );
::CreateProcess( L"sc.exe",
L"create",
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi
);
::WaitForSingleObject( pi.hProcess, INFINITE );
::CloseHandle( pi.hProcess );
::CloseHandle( pi.hThread ); | Didn't show any windows for me. Tho, didn't do anything else, because there's no console allocated -> no help message. :D
Using ::system() is even more "dirty" than this. Again, you should write a function to perform your stuff.
|
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu Aug 21, 2008 5:14 am Post subject: |
|
|
yea i did write them all short awhile ago lol
createservices, openservices, startservices, controlservice and deleteservice.
so fcking long lol. also have to handle all the error...
can't believe its only 2 system() cmd lines =[
_________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Thu Aug 21, 2008 5:24 am Post subject: |
|
|
| Bizarro wrote: | | also have to handle all the error... | That's just positive. Using ::system() or ::CreateProcess() you don't know if it failed or succeeded.
| Bizarro wrote: | | can't believe its only 2 system() cmd lines =[ |
| Code: | #include "myservices.h"
MyHandle h = myservices::createservices("test");
myservices::startservices(h);
..or something.. | Oh noes, 3 lines + a blank one! But, performance is at least 10x higher on the very first run and following ones the difference isn't that huge, but it still is.
|
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu Aug 21, 2008 5:53 am Post subject: |
|
|
dam did u find the wrapper online or made it urself :O
_________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
|