473,799 Members | 3,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I make a program that can onlybe run by an administrator

I want to create a program that can only be run by a user with administrator
privileges (ie in the BUILTIN/Administrators group - I think. Correct me if
I'm wrong, I'm a bit hazy on users and groups). I'm not sure where to start.
Can someone point me in the right direction. I'm using VS2005 (just upgraded
from 2003)
--
Dave
Jul 3 '06 #1
8 1519
Hello Dave,

just set only Administrator in the Security tab of the your app file property.
or google, as usual :) http://groups.google.com/group/micro...ba8acd180775fe

DI want to create a program that can only be run by a user with
Dadministrator privileges (ie in the BUILTIN/Administrators group - I
Dthink. Correct me if I'm wrong, I'm a bit hazy on users and groups).
DI'm not sure where to start. Can someone point me in the right
Ddirection. I'm using VS2005 (just upgraded from 2003)
D>
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jul 3 '06 #2
Dave,

Try this.

WindowsPrincipa l prin = new WindowsPrincipa l(
WindowsIdentity .GetCurrent() );

if ( !prin.IsInRole( WindowsBuiltInR ole.Administrat or ) ) {
MessageBox.Show ( "You're not an admin!" );
}

HTH
Andy

Dave wrote:
I want to create a program that can only be run by a user with administrator
privileges (ie in the BUILTIN/Administrators group - I think. Correct me if
I'm wrong, I'm a bit hazy on users and groups). I'm not sure where to start.
Can someone point me in the right direction. I'm using VS2005 (just upgraded
from 2003)
--
Dave
Jul 3 '06 #3
Andy wrote:
Dave,

Try this.

WindowsPrincipa l prin = new WindowsPrincipa l(
WindowsIdentity .GetCurrent() );

if ( !prin.IsInRole( WindowsBuiltInR ole.Administrat or ) ) {
MessageBox.Show ( "You're not an admin!" );
}

HTH
Andy

Dave wrote:
>I want to create a program that can only be run by a user with
administrato r privileges (ie in the BUILTIN/Administrators group - I
think. Correct me if I'm wrong, I'm a bit hazy on users and groups). I'm
not sure where to start. Can someone point me in the right direction. I'm
using VS2005 (just upgraded from 2003)
--
Dave
The OP seems to have posted his question twice, and I wrote a response in
the other one about something like this.

Your code is very, _very_ nice. I like it, but the inherent flaw is, that
given this application, I could now disassemble it, remove the conditional
(or simply negate the expression) and reassemble it, thus giving me access
to the program.

--
Hope this helps,
Tom Spink
Jul 3 '06 #4

Tom Spink wrote:
Your code is very, _very_ nice. I like it, but the inherent flaw is, that
given this application, I could now disassemble it, remove the conditional
(or simply negate the expression) and reassemble it, thus giving me access
to the program.
Likewise, the user can change the security settings on the file (since
the user is likely an admin). This is much easier to do than decompile
a .Net program and remove the expression. Also, the program gets to
run and thus display a friendly message than 'Access is denied.'

Decompiling a .Net program is always a risk, regardless of what your
code is doing.

Jul 3 '06 #5
Andy wrote:
>
Tom Spink wrote:
>Your code is very, _very_ nice. I like it, but the inherent flaw is,
that given this application, I could now disassemble it, remove the
conditional (or simply negate the expression) and reassemble it, thus
giving me access to the program.

Likewise, the user can change the security settings on the file (since
the user is likely an admin). This is much easier to do than decompile
a .Net program and remove the expression. Also, the program gets to
run and thus display a friendly message than 'Access is denied.'

Decompiling a .Net program is always a risk, regardless of what your
code is doing.
Hi Andy,
Likewise, the user can change the security settings on the file (since
the user is likely an admin).
But if the measures are to prevent non-admins from executing the file, then
that's not an issue, as the non-admins shouldn't have permission to alter
the security settings on that file; and the admins should know better, than
to alter the permissions, if it's a sensitive application.
Also, the program gets to
run and thus display a friendly message than 'Access is denied.'
That is particularly sweet.

--
Hope this helps,
Tom Spink
Jul 4 '06 #6
Hi Guys. Thanks for your replies. I posted twice because I was told I had an
error the first time. The UI on these message boards is DIRE - the link from
the notification email never works, the double click on a thread never works,
and quite often the whole message board doesn't work. And it tells you
there's an error and then posts anyway!
However, to the problem in hand - I can see both your points, however, if I
were going to follow Tom's advice and set the security permissions I would
want to do it as part of the installation - so how would I set that up with
the VS2005 installation pacckager.
Actually, what I would also really like to do is ensure that the app can
only be *installed* by an administrator - is that possible with VS2005?
--
Dave
"Tom Spink" wrote:
Andy wrote:

Tom Spink wrote:
Your code is very, _very_ nice. I like it, but the inherent flaw is,
that given this application, I could now disassemble it, remove the
conditional (or simply negate the expression) and reassemble it, thus
giving me access to the program.
Likewise, the user can change the security settings on the file (since
the user is likely an admin). This is much easier to do than decompile
a .Net program and remove the expression. Also, the program gets to
run and thus display a friendly message than 'Access is denied.'

Decompiling a .Net program is always a risk, regardless of what your
code is doing.

Hi Andy,
Likewise, the user can change the security settings on the file (since
the user is likely an admin).

But if the measures are to prevent non-admins from executing the file, then
that's not an issue, as the non-admins shouldn't have permission to alter
the security settings on that file; and the admins should know better, than
to alter the permissions, if it's a sensitive application.
Also, the program gets to
run and thus display a friendly message than 'Access is denied.'

That is particularly sweet.

--
Hope this helps,
Tom Spink
Jul 4 '06 #7
Likewise, the user can change the security settings on the file (since
the user is likely an admin).

But if the measures are to prevent non-admins from executing the file, then
that's not an issue, as the non-admins shouldn't have permission to alter
the security settings on that file; and the admins should know better, than
to alter the permissions, if it's a sensitive application.
That is assuming the application is deployed in a business environment,
in which case you may be totally right (at my current employer,
everyone has admin rights to thier machine though.. I suspect we are
not alone.). The program in question could be a home user product,
which simply requires admin rights to do something. In that case, the
user likely can become the administrator, and more uses know of file
security settings than know how to decompile a .Net application, remove
the check, and then recompile it.

Just some things to consider. :-)

Andy

Jul 5 '06 #8
Dave, I would advise against going Tom's route (see my other reply
today), unless the application is an internal one for your business,
and normal users aren't admins of there boxes (in some companies, like
mine, they are.. no, they shouldn't be, but that's how it is).

However, if that's really the route you want (or if you need any other
custom actions during your installation, unrelated to this issue), what
you do is add an Installer class. The on the installer class you
create, override the install method. From that method, you can execute
CACLS to modfy the ACL. Or, if you're using .Net 2.0, you can use the
ACL classes within the .Net framework to change the permissions.

HTH
Andy

Dave wrote:
Hi Guys. Thanks for your replies. I posted twice because I was told I had an
error the first time. The UI on these message boards is DIRE - the link from
the notification email never works, the double click on a thread never works,
and quite often the whole message board doesn't work. And it tells you
there's an error and then posts anyway!
However, to the problem in hand - I can see both your points, however, if I
were going to follow Tom's advice and set the security permissions I would
want to do it as part of the installation - so how would I set that up with
the VS2005 installation pacckager.
Actually, what I would also really like to do is ensure that the app can
only be *installed* by an administrator - is that possible with VS2005?
--
Dave
Jul 5 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11418
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use managed code instead. I couldn't find any easy way of doing this but searching the Internet with...
4
1371
by: Philip Wagenaar | last post by:
I have a program that has to run under the administrator account. But the use that will start the program has it's own (limited) account. How can I run a program under administrator? I'd like solution that is a secure as possible. So not using run as or something on command prompt.
2
1990
by: Cleyton | last post by:
Hello! Someone knows how I can solve it: I've installed my program in administrator account for all users. But i've tried to run in guest account, my program returned fatal error, and it didn't open... In the administrator account works very well! Someone know what's wrongs?!! Thanks!
0
1003
by: dwalker0229 | last post by:
I have built a program that uses ultr@vnc for my work. how can i have the program ask for credentials (either run as local user or as "Administrator") but not "require" administrator logon? I want my program to start up ask for credentials, if local user do A, if Administrator do B. I have all the code except for the run as window. On a side question how can I have a button that will start the "Run..." window?
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.