Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,279 members, 7,815,469 topics. Date: Thursday, 02 May 2024 at 12:52 PM

Help How To Run Cmd Commands As An Admin In A C++ App - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help How To Run Cmd Commands As An Admin In A C++ App (4901 Views)

Php/mysql Help:how To Run Sql Query From A Link / Trying To Run Php Project After Installing Wamp Server (2) (3) (4)

(1) (Reply) (Go Down)

Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 11:54am On Feb 09, 2013
Please i want to run this code as admin how would i do it in visual c++
System(String::Format("net user {0} {1}", this->username->Text, this->password->Text));
Re: Help How To Run Cmd Commands As An Admin In A C++ App by lordZOUGA(m): 12:24pm On Feb 09, 2013
this is a command line issue not exactly a C++ issue...
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 12:43pm On Feb 09, 2013
Cant c++ just start it up with higher priviledges? Like force it to start as admin?
Re: Help How To Run Cmd Commands As An Admin In A C++ App by lordZOUGA(m): 1:03pm On Feb 09, 2013
netesy: Cant c++ just start it up with higher priviledges? Like force it to start as admin?
I do not think windows has an api for that. consider this http://stackoverflow.com/questions/10906072/asking-for-administrator-privileges-in-mfc-application-only-when-it-is-needed
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 2:50pm On Feb 09, 2013
Thanks lordzouga but do u know i can use ShellExecuteEx(); and if possible hide the commandline but get the values in it
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 3:09pm On Feb 09, 2013
Or pls is there another way to get this done
Re: Help How To Run Cmd Commands As An Admin In A C++ App by lordZOUGA(m): 3:21pm On Feb 09, 2013
netesy: Thanks lordzouga but do u know i can use ShellExecuteEx(); and if possible hide the commandline but get the values in it
I do not know about hiding the command line on windows.. am more of a linux systems person.
what you are looking for is an IPC(inter process communication) method.
on linux, you can use pipes, fifo structures or sockets.
research on windows, they should have similar implementations of above concepts..

1 Like

Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 3:31pm On Feb 09, 2013
Thanks for the help pipes it is
Re: Help How To Run Cmd Commands As An Admin In A C++ App by lordZOUGA(m): 3:42pm On Feb 09, 2013
I suppose you are logging into a certain service?
you probably want confirmation if the logon process was successful.
use a file based ipc method in communicating with the shell. this is a bit crude but it works.

create a batch script that executes your command for you. the code in the batch script should just write a certain text to pre-specified file when login fails or succeeds.
your program should monitor the specified file for changes.

call_to_shell()
if(file_changed){
string state = read_file(file.txt)
if(state == " true"
{login = true }
else
{ login = false}

}elseā„¢{
timeout()
}

I hope you get what I mean
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 3:14pm On Feb 10, 2013
I like the idea but the command does not work if not run as admin
Re: Help How To Run Cmd Commands As An Admin In A C++ App by lordZOUGA(m): 3:24pm On Feb 10, 2013
netesy: I like the idea but the command does not work if not run as admin
but the main program itself can be run with admin privileges? such that when the shell process is invoked by the program, it inherits the privileges. isthat not how it works with windows?
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 6:52pm On Feb 10, 2013
That did not work and please how can i make randow numbers ?
Int numb = 300;
Srand(time());
int num = rand();
for(int i=1, i < numb; i++){
cout << num;
} is giving me the same value it nt changing
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 8:46am On Feb 11, 2013
Int numb = 300;
Srand(time());
int num = rand();
for(int i=1, i < numb; i++){
cout << num<<endl;
} is giving me the same value it nt changing please how can i seed it well as the time used is the same the values is the same , i would like each line with a different value
Re: Help How To Run Cmd Commands As An Admin In A C++ App by lordZOUGA(m): 9:15am On Feb 11, 2013
netesy:
Int numb = 300;
Srand(time());
int num = rand();
for(int i=1, i < numb; i++){
cout << num<<endl;
} is giving me the same value it nt changing please how can i seed it well as the time used is the same the values is the same , i would like each line with a different value
you called rand() once. outside the loop. it should be called anytime you want a random number.
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 9:32am On Feb 11, 2013
Example please
lordZOUGA:
you called rand() once. outside the loop. it should be called anytime you want a random number.
Re: Help How To Run Cmd Commands As An Admin In A C++ App by lordZOUGA(m): 9:57am On Feb 11, 2013

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int get_rand_range(int y){
return rand() % (y + 1);
}
int main()
{
srand(time(NULL));
cout << "15 random numbers within 0 - 5. (5 inclusive)" << endl;
for(int i = 0; i < 15; i++)
{
cout << get_rand_range(5) << " ";
}
cout << endl;
return 0;
}



I called the random number function within the loop
Re: Help How To Run Cmd Commands As An Admin In A C++ App by netesy(m): 10:06am On Feb 11, 2013
Thanks now nepa i need light

(1) (Reply)

Reasons Why Programming Is A Dangerous Profession In Nigeria. / Programmers, How Is This Recession Affecting Your Work? / Java Vs C# Which Do You Prefer?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.