Visual C# .NET : 2 adjustments in application
From advanced to novice... come, join in, teach, and learn. Web programming and help. We have stuff on it all: php, html, asp, asp.net, etc. Share your coding expertise too.

Moderators: Management, Forum Experts

Visual C# .NET : 2 adjustments in application

Postby styx on Thu Feb 23, 2006 5:34 pm

I downloaded a source code of a C# .NET application, because it was the only thing working I've found.

Fact is, I don't know this language, and I only have to do 2 adjustments in the code, so I'll ask you guys :D Hope someone can help me here

Code: Select all
   public static void Main(string[] args)
   {
      if (!AuthClass.AuthCheck())
         MessageBox.Show("Not an administrator","Need more privileges",MessageBoxButtons.OK,MessageBoxIcon.Stop);
      else
         MessageBox.Show("Preparing to install\n\n(Nothing will install... Just for demo)","Admin OK",MessageBoxButtons.OK,MessageBoxIcon.Information);
   }   


instead of
Code: Select all
MessageBox.Show("Not an administrator","Need more privileges",MessageBoxButtons.OK,MessageBoxIcon.Stop);

there should be nothing. But when I just simply remove it, and type
Code: Select all
;
" I don't get an error, but the ";" is underlined red. So is this bad? And how would I write it better?

And the other adjustment :
instead of
Code: Select all
MessageBox.Show("Preparing to install\n\n(Nothing will install... Just for demo)","Admin OK",MessageBoxButtons.OK,MessageBoxIcon.Information);

the program should open "c:\documents and settings\all users\application.exe"

Can somebody please help? Thanks in advance :)
User avatar
styx
PRO Level 5
PRO Level 5
 
Posts: 171
Joined: Fri Feb 18, 2005 11:58 am
Location: belgium

Re: Visual C# .NET : 2 adjustments in application

Postby _Taz_ on Thu Feb 23, 2006 6:01 pm

instead of
Code: Select all
MessageBox.Show("Not an administrator","Need more privileges",MessageBoxButtons.OK,MessageBoxIcon.Stop);

there should be nothing. But when I just simply remove it, and type
Code: Select all
;
" I don't get an error, but the ";" is underlined red. So is this bad? And how would I write it better?[/quote]

Well I don't know much about it either but in this one it's trying to show a message box, since I don't know that much about it either I would simply change it to

Code: Select all
MessageBox.Show(" "," ",MessageBoxButtons.OK,MessageBoxIcon.Stop);


I think you would just get a blank message box then.
I don't know how to make it launch an app. I'm sure someone will be along shortly to help the correct way.
User avatar
_Taz_
Support Team
 
Posts: 1215
Joined: Tue Jun 29, 2004 10:01 am
Location: Florida

Re: Visual C# .NET : 2 adjustments in application

Postby styx on Thu Feb 23, 2006 6:03 pm

hmmm, but if I type ";" instead of that messagebox, I don't get an error.
It just says "possible mistaken null statement".
I'll leave it the way it is, I suppose, because the user may dislike it to click on an empty message :lol:

But thanks anyway
User avatar
styx
PRO Level 5
PRO Level 5
 
Posts: 171
Joined: Fri Feb 18, 2005 11:58 am
Location: belgium

Re: Visual C# .NET : 2 adjustments in application

Postby Telos on Thu Feb 23, 2006 7:33 pm

styx wrote:I downloaded a source code of a C# .NET application, because it was the only thing working I've found.

Fact is, I don't know this language, and I only have to do 2 adjustments in the code, so I'll ask you guys :D Hope someone can help me here

Code: Select all
   public static void Main(string[] args)
   {
      if (!AuthClass.AuthCheck())
         MessageBox.Show("Not an administrator","Need more privileges",MessageBoxButtons.OK,MessageBoxIcon.Stop);
      else
         MessageBox.Show("Preparing to install\n\n(Nothing will install... Just for demo)","Admin OK",MessageBoxButtons.OK,MessageBoxIcon.Information);
   }   


instead of
Code: Select all
MessageBox.Show("Not an administrator","Need more privileges",MessageBoxButtons.OK,MessageBoxIcon.Stop);

there should be nothing. But when I just simply remove it, and type
Code: Select all
;
" I don't get an error, but the ";" is underlined red. So is this bad? And how would I write it better?

And the other adjustment :
instead of
Code: Select all
MessageBox.Show("Preparing to install\n\n(Nothing will install... Just for demo)","Admin OK",MessageBoxButtons.OK,MessageBoxIcon.Information);

the program should open "c:\documents and settings\all users\application.exe"

Can somebody please help? Thanks in advance :)


So you just want it to show the "Preparing to install..." popup right?

Just change the if statement. You want to display "Preparing to install..." if Authclass.AuthCheck is true, and not have anything happen otherwise. This would look like this:

Code: Select all
//notice the ! is gone
if (AuthClass.AuthCheck())
{
   MessageBox.Show("Preparing to install\n\n(Nothing will install... Just for demo)","Admin OK",MessageBoxButtons.OK,MessageBoxIcon.Information);
}


You were getting the warning because a semi-colon all by itself doesn't really mean anything. It's just what appears at the end of a statement, so you had nothing followed by a semi-colon, which is basically an empty statement.

Hope that helps.
...I'm prepared to passionately argue the point until nothing makes sense anymore! - Red Mage
User avatar
Telos
PRO Level 6
PRO Level 6
 
Posts: 230
Joined: Tue Jul 12, 2005 8:04 pm
Location: Tonawanda, NY

Re: Visual C# .NET : 2 adjustments in application

Postby styx on Fri Feb 24, 2006 3:37 pm

So you just want it to show the "Preparing to install..." popup right?

Just change the if statement. You want to display "Preparing to install..." if Authclass.AuthCheck is true, and not have anything happen otherwise. This would look like this:

Code: Select all
//notice the ! is gone
if (AuthClass.AuthCheck())
{
   MessageBox.Show("Preparing to install\n\n(Nothing will install... Just for demo)","Admin OK",MessageBoxButtons.OK,MessageBoxIcon.Information);
}



Actually, no :emberassed:
I want it to launch application.exe instead of showing that message.
Sorry if I didn't explain it that well :) But thanks for trying !
You were getting the warning because a semi-colon all by itself doesn't really mean anything. It's just what appears at the end of a statement, so you had nothing followed by a semi-colon, which is basically an empty statement.

Hope that helps.

Thanks :)
User avatar
styx
PRO Level 5
PRO Level 5
 
Posts: 171
Joined: Fri Feb 18, 2005 11:58 am
Location: belgium

Postby coreyw2000 on Fri Feb 24, 2006 5:07 pm

Try it without the ;
Be nice to nerds.... chances are you will end up working for one

<u><b>Current system</b></u>
ASUS M3A78-EMH HDMI
AMD Athlon X2 6000+ o/c'd at 3.2GHz
4GB (2x2GB) OCZ RAM
Integrated Radeon HD 3200 (HDMI out)
500GB SATA/360GB IDE HDD's
32" Sharp 1080p Monitor/TV
Vista RTM/Vista SP2 Beta/7 6801
coreyw2000
PROfessional Member
 
Posts: 7120
Joined: Tue Oct 05, 2004 1:30 am
Location: Saskatchewan, Canada

Postby THE ONE on Mon Feb 27, 2006 7:43 am

Just Replace

Code: Select all
public static void Main(string[] args)
   {
      if (!AuthClass.AuthCheck())
         MessageBox.Show("Not an administrator","Need more privileges",MessageBoxButtons.OK,MessageBoxIcon.Stop);
      else
         MessageBox.Show("Preparing to install\n\n(Nothing will install... Just for demo)","Admin OK",MessageBoxButtons.OK,MessageBoxIcon.Information);
   }   


with

Code: Select all
public static void Main(string[] args)
   {
          System.Diagnostics.Process.Start(@"c:\documents and settings\all users\application.exe");
   }
Image
User avatar
THE ONE
PRO Level 5
PRO Level 5
 
Posts: 169
Joined: Fri Oct 01, 2004 12:10 pm
Location: Pakistan

Postby styx on Thu Sep 04, 2008 8:32 pm

Computer Guru wrote:already solved via email....
He was more than happy to continue emailing me to explain his problem, but the minute he got a solution he abandons the forums and "forgets" to send a "thank you it worked" back...
whatever.

that's so me, sorry to bump this topic.. I really appreciated it actually!
d*mn that's so me, really! :oops:
User avatar
styx
PRO Level 5
PRO Level 5
 
Posts: 171
Joined: Fri Feb 18, 2005 11:58 am
Location: belgium

Next

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 0 guests