新用户帐户。 [英] New User Account.

查看:76
本文介绍了新用户帐户。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在由我的应用程序创建的特殊用户

所拥有的文件系统中创建一个文件夹。我的想法是只有我的应用程序才有权删除和创建该文件夹上的文件。

我的应用程序是可再分发的,所以我需要创建用户和以编程方式将我的应用程序的
权限授予该文件夹。


我的问题是:

1)使用c#如何创建一个新的用户帐户

2)我如何将文件夹的权限设置为新用户

3)如何使用这个新用户启动我的应用程序?


问候,


Marcelo。

解决方案

Marcelo,


我不得不说,这通常是一个坏主意。你永远不应该从用户那里拿走他们想要的机器权利。什么

如果您的应用程序出错了,并将文件写入需要因某种原因需要删除的目录

?用户根本无法修复它,因为他们没有权利删除

文件夹和/或文件。您假设您的代码将是完美的,并且忽略了可能影响您的程序的其他因素

(如果在编写其中一个时断电,该怎么办?文件,它变成

腐败,例如)。


另外,为了做到这一切,如果用户在网络而不是

管理员,那么更有可能,他们不会有

权利来做这类事情。


话虽如此,要创建一个新的用户帐户,您必须通过P / Invoke层调用Netapi32 dll中的

NetUserAdd函数。要为
分配新用户文件夹的权限,请查看知识库

文章318744,标题为HOWTO:使用Visual Basic以编程方式更改

文件或文件夹的所有权,位于(注意换行):

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

至于使用这个新用户启动你的应用程序,请查看WindowsIdentity类上的Impersonate方法的

文档。


希望这个帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

"MarceloLópez" <吨 - ******** @ infocorp.com.uy>在消息中写道

新闻:Ov ************** @ TK2MSFTNGP12.phx.gbl ...

我需要创建一个文件系统中的文件夹由特殊用户拥有
由我的应用程序创建。我的想法是只有我的应用程序才有权删除和创建该文件夹上的文件。
我的应用程序是可再分发的,所以我需要创建用户并给予我的
权限以编程方式将该应用程序添加到该文件夹​​。

我的问题是:
1)使用c#如何创建新的用户帐户
2)如何将文件夹的权限设置为新用户
3)如何使用这个新用户启动我的应用程序?

问候,

Marcelo。


好的,尼古拉斯,你说的听起来很合理。谢谢你的回答。


那么,如果你不得不阻止别人修改

特殊文件夹中的文件,你会怎么做?你的应用?我正在开发一个窗口

explorer就像应用程序一样。我有一个存储库,我存储文件

,我不希望任何人可以删除或重命名,移动等文件

''因为我的存储库可能会变得不一致。


我尝试过使用文件观察程序,但是恢复bd中的信息太复杂了因为它很难管理观察者的事件排队到
确切地知道用户做了哪个操作。因为例如一个文件

移动扔了4个事件:更改 - 删除 - 更改 - 创建。


在我的情况下你会做什么建议?


我正在开发一个职业项目,我必须在1月30日结束,所以我没有b $ b没有多少时间!!


谢谢!!


Marcelo。


" Nicholas Paldino [.NET / C#MVP] " < mv*@spam.guard.caspershouse.com>写在

消息新闻:#K ************* @ TK2MSFTNGP10.phx.gbl ...

Marcelo,
我不得不说,这通常是一个坏主意。你永远不应该从用户手中夺走他们对机器做的事情。
如果您的应用程序出错了,并将文件写入需要因某种原因而被删除的
目录,会发生什么?用户根本无法修复它,因为他们无权删除
文件夹和/或文件。您假设您的代码
将是完美的,并且忽略了可能影响您的
程序的其他因素(如果在写入其中一个文件时电源耗尽,那么它是
然而,为了做到这一点,如果用户在网络上而不是管理员,那么他们很可能不会这样做拥有这样做的权利。

就是说,要创建一个新的用户帐户,你必须在Netapi32 dll中调用
NetUserAdd函数通过P / Invoke层。要为新用户分配文件夹的权限,请查看知识库
文章318744,标题为HOWTO:使用Visual Basic以编程方式更改文件或文件夹的所有权,位于在(注意换行):

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

至于使用这个新用户启动你的应用,请检查在WindowsIdentity类上输出Impersonate方法的
文档。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C# MVP]
- mv*@spam.guard.caspershouse.com

" MarceloLópez <吨 - ******** @ infocorp.com.uy>在消息中写道
新闻:Ov ************** @ TK2MSFTNGP12.phx.gbl ...

我需要在文件中创建一个文件夹由我的应用程序创建的特殊用户所拥有的系统。我的想法是只有我的应用程序才有权删除和创建该文件夹上的文件。
我的应用程序是可再分发的,所以我需要创建用户并给予我的
权限以编程方式将该应用程序添加到该文件夹​​。

我的问题是:
1)使用c#如何创建新的用户帐户
2)如何将文件夹的权限设置为新用户
3)如何使用这个新用户启动我的应用程序?

问候,

Marcelo。



不要使用C#,学习使用命令行工具。

1)发网用户命令检查用户是否存在,如果没有创建用户

类似于:

@Echo Off

净用户MarceloL> NUL:2> ;& 1

如果ERRORLEVEL 1转到noSuchUser

goto存在

:noSuchUser

净用户MarceloL somePassword /添加全名:MarceloLópez)

:存在

...

2)发出cacls命令设置文件夹权限

3)使用runas启动程序命令行命令。

把这一切都很好地放在一个cmd文件中,然后完成。


Willy。

"MarceloLópez" <吨 - ******** @ infocorp.com.uy>在消息中写道

新闻:Ov ************** @ TK2MSFTNGP12.phx.gbl ...

我需要创建一个文件系统中的文件夹由特殊用户拥有
由我的应用程序创建。我的想法是只有我的应用程序才有权删除和创建该文件夹上的文件。
我的应用程序是可再分发的,所以我需要创建用户并给予我的
权限以编程方式将该应用程序添加到该文件夹​​。

我的问题是:
1)使用c#如何创建新的用户帐户
2)如何将文件夹的权限设置为新用户
3)如何使用这个新用户启动我的应用程序?

问候,

Marcelo。


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.

解决方案

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.



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.




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.



这篇关于新用户帐户。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆