473,473 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

New User Account.

I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give
permissions to my app to that folder programatically.

My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?

Regards,

Marcelo.
Nov 15 '05 #1
11 2141
Marcelo,

I have to say, this generally is a bad idea. You should never, ever
take away the right from a user to do what they wish to their machine. What
happens if your app does something wrong, and writes a file to the directory
that needs to be removed for some reason or another? The user wouldn't be
able to fix it at all, since they wouldn't have the rights to remove the
folder and/or the files. You are making the assumption that your code will
be perfect, and also neglecting other factors that could affect your program
(what if the power goes out while writing one of these files, and it becomes
corrupt, for example).

Also, in order to do this all, if the user is on a network and not an
administrator, then more likely than not, they are not going to have the
rights to do this sort of thing.

That being said, to create a new user account, you will have to call the
NetUserAdd function in the Netapi32 dll through the P/Invoke layer. To
assign permissions to a folder for the new user, check out knowledge base
article 318744, titled "HOWTO: Use Visual Basic to Programmatically Change
Ownership of a File or Folder", located at (watch for line wrap):

http://support.microsoft.com/default...b;en-us;318744

As for starting your app using this new user, check out the
documentation for the Impersonate method on the WindowsIdentity class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Marcelo López" <t-********@infocorp.com.uy> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give
permissions to my app to that folder programatically.

My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?

Regards,

Marcelo.

Nov 15 '05 #2
Ok, Nicholas, what you say sounds reasonable. Thanks for your answer.

So that, What would you do in my case if you had to prevent others to modify
the files in a special folder for your app ?. I'm developing a windows
explorer like application. I have a repository in which I store the files
and I don't want anybody else could delete or rename, move, etc. the files
'cause my repository could become inconsistent.

I'd tried using a file watcher, but restoring information in the bd was too
complicated because it was difficult to manage the watcher 's event queue to
exactly know which operation the user had done. Because for example a file
move throw really 4 events: change-deleted-change-created.

What would you do recomend in my case to do ?

I'm developing a career project and I have to finish to January 30, so I
don't have lot time !!

Thanks !!

Marcelo.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:#K*************@TK2MSFTNGP10.phx.gbl...
Marcelo,

I have to say, this generally is a bad idea. You should never, ever
take away the right from a user to do what they wish to their machine. What happens if your app does something wrong, and writes a file to the directory that needs to be removed for some reason or another? The user wouldn't be
able to fix it at all, since they wouldn't have the rights to remove the
folder and/or the files. You are making the assumption that your code will be perfect, and also neglecting other factors that could affect your program (what if the power goes out while writing one of these files, and it becomes corrupt, for example).

Also, in order to do this all, if the user is on a network and not an
administrator, then more likely than not, they are not going to have the
rights to do this sort of thing.

That being said, to create a new user account, you will have to call the NetUserAdd function in the Netapi32 dll through the P/Invoke layer. To
assign permissions to a folder for the new user, check out knowledge base
article 318744, titled "HOWTO: Use Visual Basic to Programmatically Change
Ownership of a File or Folder", located at (watch for line wrap):

http://support.microsoft.com/default...b;en-us;318744

As for starting your app using this new user, check out the
documentation for the Impersonate method on the WindowsIdentity class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Marcelo López" <t-********@infocorp.com.uy> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give
permissions to my app to that folder programatically.

My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?

Regards,

Marcelo.


Nov 15 '05 #3
Don't use C# for this, Learn to use the command line tools.
1) issue a net user command to check user exists, if not create the user
something like:
@Echo Off
Net User MarceloL >NUL: 2>&1
if ERRORLEVEL 1 goto noSuchUser
goto exists
:noSuchUser
net user MarceloL somePassword /add fullname:"Marcelo López")
:exists
...
2) issue a cacls command to set the folder permissions
3) start your program commandline using the "runas" command.
Put this all nicely in a cmd file, and done.

Willy.
"Marcelo López" <t-********@infocorp.com.uy> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give
permissions to my app to that folder programatically.

My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?

Regards,

Marcelo.

Nov 15 '05 #4
Marcelo,

I think that basically, you should have your directory (create it where
you know you can find it), but do not put permissions on it. Rather, have
extensible error handling which would detect when the files are not as they
should be.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marcelo López" <t-********@infocorp.com.uy> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
Ok, Nicholas, what you say sounds reasonable. Thanks for your answer.

So that, What would you do in my case if you had to prevent others to modify the files in a special folder for your app ?. I'm developing a windows
explorer like application. I have a repository in which I store the files
and I don't want anybody else could delete or rename, move, etc. the files
'cause my repository could become inconsistent.

I'd tried using a file watcher, but restoring information in the bd was too complicated because it was difficult to manage the watcher 's event queue to exactly know which operation the user had done. Because for example a file
move throw really 4 events: change-deleted-change-created.

What would you do recomend in my case to do ?

I'm developing a career project and I have to finish to January 30, so I
don't have lot time !!

Thanks !!

Marcelo.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:#K*************@TK2MSFTNGP10.phx.gbl...
Marcelo,

I have to say, this generally is a bad idea. You should never, ever
take away the right from a user to do what they wish to their machine.

What
happens if your app does something wrong, and writes a file to the

directory
that needs to be removed for some reason or another? The user wouldn't be able to fix it at all, since they wouldn't have the rights to remove the
folder and/or the files. You are making the assumption that your code

will
be perfect, and also neglecting other factors that could affect your

program
(what if the power goes out while writing one of these files, and it

becomes
corrupt, for example).

Also, in order to do this all, if the user is on a network and not an administrator, then more likely than not, they are not going to have the
rights to do this sort of thing.

That being said, to create a new user account, you will have to call

the
NetUserAdd function in the Netapi32 dll through the P/Invoke layer. To
assign permissions to a folder for the new user, check out knowledge base article 318744, titled "HOWTO: Use Visual Basic to Programmatically Change Ownership of a File or Folder", located at (watch for line wrap):

http://support.microsoft.com/default...b;en-us;318744

As for starting your app using this new user, check out the
documentation for the Impersonate method on the WindowsIdentity class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Marcelo López" <t-********@infocorp.com.uy> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give permissions to my app to that folder programatically.

My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?

Regards,

Marcelo.



Nov 15 '05 #5
Ok, Thanks , i'll try this way.

Where can i find more about using the command tools to create users ?

Regards
Marcelo
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
Don't use C# for this, Learn to use the command line tools.
1) issue a net user command to check user exists, if not create the user
something like:
@Echo Off
Net User MarceloL >NUL: 2>&1
if ERRORLEVEL 1 goto noSuchUser
goto exists
:noSuchUser
net user MarceloL somePassword /add fullname:"Marcelo López")
:exists
...
2) issue a cacls command to set the folder permissions
3) start your program commandline using the "runas" command.
Put this all nicely in a cmd file, and done.

Willy.
"Marcelo López" <t-********@infocorp.com.uy> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give
permissions to my app to that folder programatically.

My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?

Regards,

Marcelo.


Nov 15 '05 #6
From the command prompt type:
net help command
or net command /help
available commands can be viewed with net help

ex. net help user shows all options available for net user

Willy.
"Marcelo López" <ma******@infocorp.com.uy> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Ok, Thanks , i'll try this way.

Where can i find more about using the command tools to create users ?

Regards
Marcelo
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
Don't use C# for this, Learn to use the command line tools.
1) issue a net user command to check user exists, if not create the user
something like:
@Echo Off
Net User MarceloL >NUL: 2>&1
if ERRORLEVEL 1 goto noSuchUser
goto exists
:noSuchUser
net user MarceloL somePassword /add fullname:"Marcelo López")
:exists
...
2) issue a cacls command to set the folder permissions
3) start your program commandline using the "runas" command.
Put this all nicely in a cmd file, and done.

Willy.
"Marcelo López" <t-ma******@infocorp.com.uy> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
I need to create a folder in the file system owned by an special user
created by my application. The idea is that only my app will have
permissions to delete and create files on that folder.
My app is a redistribuitable one, so i need to create the user and give permissions to my app to that folder programatically.

My questions are:
1) Using c# how can i create a new user account
2) How can i asign permissions to a folder to the new user
3) how can i start my app using this new user ?

Regards,

Marcelo.



Nov 15 '05 #7
Ok, very good.
I just only need to assign permissions to my folder...but i don't know how
to do that.. How can i do that ?

Thanks again !
Marcelo
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:em**************@tk2msftngp13.phx.gbl...
From the command prompt type:
net help command
or net command /help
available commands can be viewed with net help

ex. net help user shows all options available for net user

Willy.
"Marcelo López" <ma******@infocorp.com.uy> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Ok, Thanks , i'll try this way.

Where can i find more about using the command tools to create users ?

Regards
Marcelo
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
Don't use C# for this, Learn to use the command line tools.
1) issue a net user command to check user exists, if not create the user something like:
@Echo Off
Net User MarceloL >NUL: 2>&1
if ERRORLEVEL 1 goto noSuchUser
goto exists
:noSuchUser
net user MarceloL somePassword /add fullname:"Marcelo López")
:exists
...
2) issue a cacls command to set the folder permissions
3) start your program commandline using the "runas" command.
Put this all nicely in a cmd file, and done.

Willy.
"Marcelo López" <t-ma******@infocorp.com.uy> wrote in message
news:Ov**************@TK2MSFTNGP12.phx.gbl...
> I need to create a folder in the file system owned by an special user > created by my application. The idea is that only my app will have
> permissions to delete and create files on that folder.
> My app is a redistribuitable one, so i need to create the user and give > permissions to my app to that folder programatically.
>
> My questions are:
> 1) Using c# how can i create a new user account
> 2) How can i asign permissions to a folder to the new user
> 3) how can i start my app using this new user ?
>
> Regards,
>
> Marcelo.
>
>



Nov 15 '05 #8
Check the cacls.exe command line utility (w2k, and higher).
Willy.

"Marcelo López" <ma******@infocorp.com.uy> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
Ok, very good.
I just only need to assign permissions to my folder...but i don't know how
to do that.. How can i do that ?

Thanks again !
Marcelo

Nov 15 '05 #9
Willy, hi.

I did what you recomended to me and it works !
But i found a little problem:

The user i had created for my app is on the select list at the windows start
up !!
So the windows user can see it in the select user list and althought he
can't log in because he doesn't know the pass, and i don't want that he
could see the user at the start up.
I saw that other "limited" users like SQLAgent, doesn`t appears at the start
up (wich is logic), so, my question is:

How can i hide the user from the windows start up ??

Regards and thanks !
Marcelo

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:#7**************@TK2MSFTNGP11.phx.gbl...
Check the cacls.exe command line utility (w2k, and higher).
Willy.

"Marcelo López" <ma******@infocorp.com.uy> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
Ok, very good.
I just only need to assign permissions to my folder...but i don't know how to do that.. How can i do that ?

Thanks again !
Marcelo


Nov 15 '05 #10


"Marcelo López" <ma******@infocorp.com.uy> wrote in message
news:OB**************@tk2msftngp13.phx.gbl...
How can i hide the user from the windows start up ??

Regards and thanks !
Marcelo

Check this: Microsoft Knowledge Base Article - 827072

Willy.
Nov 15 '05 #11
Marcelo López wrote:
Ok, Nicholas, what you say sounds reasonable. Thanks for your answer.

So that, What would you do in my case if you had to prevent others to modify
the files in a special folder for your app ?. I'm developing a windows
explorer like application. I have a repository in which I store the files
and I don't want anybody else could delete or rename, move, etc. the files
'cause my repository could become inconsistent.

Hello -

Have a look at 'IsolatedStorageFile Class' here: http://tinyurl.com/3694z.
It isn't *exactly* what you are looking for, sorry.

From the MSDN Remarks:

Remarks
This object corresponds to a specific isolated storage scope, where files
represented by IsolatedStorageFileStream objects exist. Applications can use
isolated storage to save data in their own isolated portion of the file
system, without having to specify a particular path within the file system.
Since isolated stores are scoped to particular assemblies, most other
managed code will not be able to access your code's data (highly trusted
managed code and administration tools can access stores from other
assemblies). Unmanaged code can access any isolated stores.

The last bit also includes users *but* the portion of the filesystem they
speak of is buried under ~/Application Data/ which I believe is hidden by
default.

Good luck.

--
chris

Nov 15 '05 #12

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

Similar topics

10
by: DC Gringo | last post by:
Using latest SP Win2k and .NET versions, I have a .NET application running on server1 with a SQL Server database running on server2. I have the Windows user account passwords sync'd for...
0
by: jakobsgaard | last post by:
It is possible to Map a certificate to a Active Directory User Account from DotNet? Please provide an example. Best regards, Ejnar Jakobsgaard...
1
by: Roshan | last post by:
Hi, I wanted a reliable way of detecting if a given NTAccount object represents a user account or group account. I was using SecurityIdentifier.IsAccountSid() method but this doesn't work as I...
1
by: Dica | last post by:
i'm getting an error when trying to perform a file move operation. this operation worked fine on my dev box after i granted read/write/delete perms to the asp.net user account on the folders i...
6
by: Not Me | last post by:
Hey, We have an sql server 2000 machine and IIS 6 machine running seperately but on the same domain. I can connect fine to the database without using impersonation, but when it's enabled I get...
1
by: archana | last post by:
Hi all, I want to develop one web application. What i want is to allow user to create account but at that time before giving rights to that user admin should accept this person's account. So...
22
by: klenwell | last post by:
I'm in the process of refactoring the php code base I've amassed over the last few years into an object-oriented framework. I'm about to start in on the authentication/login extension and I've...
1
by: Alex | last post by:
Hi everybody Is creating of the service, which must be ran under the "user account" something really tricky? I mean if in ServiceProcessInstaller properties I'm using account: Local System...
1
by: =?Utf-8?B?Qi5BaGxzdGVkdA==?= | last post by:
Hi all, This is something that I have been toying with for about a week now. What I want to achieve is Install a Service with Customised parameters (using InstallUtil.exe) for User Name. Example...
9
by: happyse27 | last post by:
Hi All, In perl script(item b below) where we check if html registration form are filled in properly without blank with the necessary fields, how to prompt users that the field are incomplete...
0
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,...
0
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,...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.