Click here to Skip to main content
15,888,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: positive values count WHILE heap sort Pin
sadas232341s2-Oct-11 21:55
sadas232341s2-Oct-11 21:55 
QuestionRe: positive values count WHILE heap sort Pin
David Crow3-Oct-11 7:22
David Crow3-Oct-11 7:22 
AnswerRe: positive values count WHILE heap sort Pin
sadas232341s3-Oct-11 8:39
sadas232341s3-Oct-11 8:39 
QuestionRe: positive values count WHILE heap sort Pin
David Crow3-Oct-11 9:27
David Crow3-Oct-11 9:27 
QuestionPhysical Drive Size Pin
john56321-Oct-11 22:08
john56321-Oct-11 22:08 
GeneralRe: Physical Drive Size Pin
Code-o-mat1-Oct-11 22:48
Code-o-mat1-Oct-11 22:48 
AnswerRe: Physical Drive Size Pin
Software_Developer2-Oct-11 0:29
Software_Developer2-Oct-11 0:29 
QuestionHow can program tell that itself is running as admin? Pin
Brandon-X120001-Oct-11 3:07
Brandon-X120001-Oct-11 3:07 
Hello people I have the following the code written in C++, converted from Vb.net to C++ from a program, the following code tells the user via message box if the program is running as an admin, see below

C++
Object ^identity = WindowsIdentity::GetCurrent();
WindowsPrincipal ^principal = gcnew WindowsPrincipal(identity);
bool isElevated = principal->IsInRole(WindowsBuiltInRole::Administrator);

try
    {
    if (isElevated == true)
    {
    }
    else
    {
        MessageBox::Show("WARNING: Program not running as administrator!", "Credential Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
    }
    }
catch (Exception ^ex)
{
    MessageBox::Show("This program cannot run as performed because your system does not support admin rights, program now terminating from computer memory.", ".Net Framework Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
    Environment::Exit(1);
}


When this block of code was executed with my program, I get the following error message (In double quotations):

"error C2664: 'System::Security::Principal::WindowsPrincipal::WindowsPrincipal(System::Security::Principal::WindowsIdentity ^)' : cannot convert parameter 1 from 'System::Object ^' to 'System::Security::Principal::WindowsIdentity ^'"

the remaining error messages are (In double quotations):

"1> No user-defined-conversion operator available, or
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast"


Could anyone point out something that I could edit that could make the compiler accept or work, any suggestions or personal solutions are appreciated Smile | :) .
AnswerRe: How can program tell that itself is running as admin? Pin
Chris Losinger1-Oct-11 4:10
professionalChris Losinger1-Oct-11 4:10 
GeneralRe: How can program tell that itself is running as admin? Pin
Brandon-X120001-Oct-11 5:38
Brandon-X120001-Oct-11 5:38 
QuestionDatum & Map projection Pin
rajgaurav_jsr1-Oct-11 3:01
rajgaurav_jsr1-Oct-11 3:01 
AnswerRe: Datum & Map projection Pin
Software_Developer1-Oct-11 21:58
Software_Developer1-Oct-11 21:58 
QuestionHow to update the Document generated by server COleServerDoc Pin
Andraw Tang30-Sep-11 10:01
Andraw Tang30-Sep-11 10:01 
QuestionHow can I Move a memory pointer in FILE? Pin
002comp30-Sep-11 2:52
002comp30-Sep-11 2:52 
AnswerRe: How can I Move a memory pointer in FILE? Pin
Code-o-mat30-Sep-11 3:04
Code-o-mat30-Sep-11 3:04 
AnswerRe: How can I Move a memory pointer in FILE? Pin
Madhu Nair30-Sep-11 3:29
Madhu Nair30-Sep-11 3:29 
AnswerRe: How can I Move a memory pointer in FILE? PinPopular
enhzflep30-Sep-11 3:34
enhzflep30-Sep-11 3:34 
GeneralRe: How can I Move a memory pointer in FILE? Pin
Chris Meech30-Sep-11 7:13
Chris Meech30-Sep-11 7:13 
AnswerRe: How can I Move a memory pointer in FILE? PinPopular
Richard MacCutchan30-Sep-11 10:10
mveRichard MacCutchan30-Sep-11 10:10 
QuestionSetting font size in popup message Pin
nashhashdash30-Sep-11 1:21
nashhashdash30-Sep-11 1:21 
AnswerRe: Setting font size in popup message Pin
Richard MacCutchan30-Sep-11 2:35
mveRichard MacCutchan30-Sep-11 2:35 
Question'Should I use <code>using namespace std;</code> in my code?' Pin
Stefan_Lang30-Sep-11 0:49
Stefan_Lang30-Sep-11 0:49 
AnswerRe: 'Should I use using namespace std; in my code?' Pin
Erudite_Eric30-Sep-11 0:56
Erudite_Eric30-Sep-11 0:56 
GeneralRe: 'Should I use using namespace std; in my code?' Pin
Stefan_Lang2-Oct-11 22:14
Stefan_Lang2-Oct-11 22:14 
GeneralRe: 'Should I use using namespace std; in my code?' Pin
Erudite_Eric3-Oct-11 22:00
Erudite_Eric3-Oct-11 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.