⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch10.htm

📁 《Perl 5 Unreleased》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
The <TT><FONT FACE="Courier">$subkey</FONT></TT> is the subkey

to load the file into from the filename specified in <TT><FONT FACE="Courier">$filename</FONT></TT>.

<P>

You can delete keys or their values. The function to delete a

key is <TT><FONT FACE="Courier">DeleteKey($keyname)</FONT></TT>.

To delete a value, use <TT><FONT FACE="Courier">DeleteValue($keyname);</FONT></TT>.

Here are some examples of these functions:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">$regObject-&gt;DeleteKey($keyname);<BR>

$CURRENT_USER-&gt;DeleteValue($keyname);</FONT></TT>

</BLOCKQUOTE>

<H2><A NAME="TheWin32NetAdminModule"><FONT SIZE=5 COLOR=#FF0000>The

</FONT><TT><FONT SIZE=5 COLOR=#FF0000 FACE="Courier">Win32::NetAdmin</FONT></TT><FONT SIZE=5 COLOR=#FF0000>

Module</FONT></A></H2>

<P>

The <TT><FONT FACE="Courier">Win32::NetAdmin</FONT></TT> module

is useful for working with users and user groups on an NT machine.

Normally you would perform this operation at the main console

using the windowing interface in NT. However, addition and deletion

of users on multiple machines would tax the system administrator's

time too much. A Perl script can list the attributes of a user

or group and perhaps be able to do this automatically and remotely

on a network. This section covers some of the functions available

from within Perl.<P>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR VALIGN=TOP><TD ><B>Note</B></TD></TR>

<TR VALIGN=TOP><TD >

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">Win32::NetAdmin</FONT></TT> module will not load on a Windows 95 machine.

</BLOCKQUOTE>



</TD></TR>

</TABLE></CENTER>

<P>

<H3><A NAME="AddingaUser">Adding a User</A></H3>

<P>

To add a user using the <TT><FONT FACE="Courier">Win32::NetAdmin</FONT></TT>

module, you can call the <TT><FONT FACE="Courier">UserCreate()</FONT></TT>

function. The syntax for this function is

<BLOCKQUOTE>

<TT><FONT FACE="Courier">UserCreate($server,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$userName,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$password,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$passwordAge,

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$privilege,$<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;homeDir,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$comment,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$flags,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$scriptPath);</FONT></TT>

</BLOCKQUOTE>

<P>

The<TT><FONT FACE="Courier"> $server</FONT></TT> variable is the

name of the server. It may be <TT><FONT FACE="Courier">NULL</FONT></TT>

to specify the local server. The <TT><FONT FACE="Courier">$userName</FONT></TT>

variable is the login name of the new user. <TT><FONT FACE="Courier">$groupName</FONT></TT>

is the name of the group. The <TT><FONT FACE="Courier">$comment</FONT></TT>

variable is a string that will have the attributes field of that

group when the function returns. The user's password and the time

before it expires is in the variables <TT><FONT FACE="Courier">$password</FONT></TT>

and <TT><FONT FACE="Courier">$PasswordAge</FONT></TT>, respectively.

The home directory of the user is set in the <TT><FONT FACE="Courier">$homeDir</FONT></TT>

argument. The comment variable contains appropriate information

about the user. The <TT><FONT FACE="Courier">$scriptPath</FONT></TT>

variable is the Uniform Naming Convention (Unc) pathname of the

login script for that user.

<P>

The <TT><FONT FACE="Courier">$privilege</FONT></TT> variable controls

the privileges of the new user. This variable can be set to one

of these values:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">USER_PRIV_MASK</FONT></TT> to set for

all users

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">USER_PRIV_GUEST</FONT></TT> to set for

all guest users

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">USER_PRIV_USER</FONT></TT> to set for

all normal users

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">USER_PRIV_ADMIN</FONT></TT> to set for

the administrative accounts

</BLOCKQUOTE>

<P>

Here are the defined values the <TT><FONT FACE="Courier">$flag</FONT></TT>

option can take:<P>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_SCRIPT</FONT></TT> 

</TD><TD WIDTH=298>The script to execute when the user logs on.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_AccOUNTDISABLE</FONT></TT>

</TD><TD WIDTH=298>Disables the account.</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_PASSWRD_NOTREQD</FONT></TT>

</TD><TD WIDTH=298>No password is required to create this account.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_PASSWRD_CANT_chANGE</FONT></TT> 

</TD><TD WIDTH=298>The user cannot change his or her password.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_LOCKOUT</FONT></TT>

</TD><TD WIDTH=298>Locks the current account out.</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_DONT_EXPIRE_PASSWORD</FONT></TT>

</TD><TD WIDTH=298>The password never expires on the account.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_NORMAL_AccOUNT</FONT></TT>

</TD><TD WIDTH=298>This is a default account type for use with all typical users.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_TEMP_DUPLICATE_AccOUNT</FONT></TT>

</TD><TD WIDTH=298>Use this account for users whose primary account is in another domain. This user has access to the current domain but is not a trusted account and is referred to as a local account.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_WORKSTATION_TRUST_AccOUNT</FONT></TT>

</TD><TD WIDTH=298>Used for a computer account for a Windows NT Workstation server which is also a member of the current domain.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_SERVER_TRUST_AccOUNT</FONT></TT>

</TD><TD WIDTH=298>Used for a computer account for a Windows NT backup domain controller which is also a member of the current domain.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=292><TT><FONT FACE="Courier">UF_INTERDOMAIN_TRUST_AccOUNT</FONT></TT>

</TD><TD WIDTH=298>Gives permission to trust this account.</TD>

</TR>

</TABLE></CENTER>

<P>

<P>

Please refer to the Windows NT reference manual for more information

about these flags. Most of the flags are descriptive enough to

indicate the functions they provide.

<P>

To delete a user from the system, call the <TT><FONT FACE="Courier">UserDelete($server,

$user)</FONT></TT> function. <TT><FONT FACE="Courier">$server</FONT></TT>

is the name of the server and can be <TT><FONT FACE="Courier">NULL</FONT></TT>

for the local machine. <TT><FONT FACE="Courier">$user</FONT></TT>

is the name of the user to delete. It's probably a good idea to

know the attributes of a user before you delete the account. To

get the attributes of a user, you have to use this call:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">UserGetAttributes(<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$server, # The

name of the server.<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$userName, # The

name of the user.<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$password, # Their

password.<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$passwordAge,

# The time before the password expires.<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$privilege,&nbsp;&nbsp;#Their&nbsp;&nbsp;privilege.

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$homeDir, # Their

home directory.<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$comment, # Any

comments about them.<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$flags, # for

the account<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$scriptPath );&nbsp;&nbsp;#

Pathname of login script.</FONT></TT>

</BLOCKQUOTE>

<P>

You can reset these values to different ones and modify an account's

attribute with the <TT><FONT FACE="Courier">UserSetAttributes</FONT></TT>

call. The parameters passed into the function are the same as

the <TT><FONT FACE="Courier">UserGetAttributes()</FONT></TT> function.

<P>

Listing 10.5 obtains listing information about a user.

<HR>

<BLOCKQUOTE>

<B>Listing 10.5. Using the </B><TT><B><FONT FACE="Courier">NetAdmin</FONT></B></TT><B>

module.<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">use Win32::NetAdmin;<BR>

$userName = &quot;khusain&quot;;<BR>

<BR>

&nbsp;&nbsp;&nbsp;Win32::NetAdmin::UserGetAttributes('',$userName,

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$Getpassword,

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$Getcomment,

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$Getflags,

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$Getscriptpath

;</FONT></TT>

</BLOCKQUOTE>

<HR>

<P>

To delete a user, you can use the <TT><FONT FACE="Courier">UserDelete</FONT></TT>

function. Here's the syntax:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">use Win32::NetAdmin;<BR>

Win32::NetAdmin::UserDelete($server,$username);</FONT></TT>

</BLOCKQUOTE>

<H3><A NAME="CreatingorDeletingaGroup">Creating or Deleting a

Group</A></H3>

<P>

To create a group, you can make one of these calls:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">LocalGroupCreate($server, $group, $comment);

<BR>

GroupCreate($server, $group, $comment);</FONT></TT>

</BLOCKQUOTE>

<P>

<TT><FONT FACE="Courier">$server</FONT></TT> is the name of the

server. It may be <TT><FONT FACE="Courier">NULL</FONT></TT> to

specify the local server. <TT><FONT FACE="Courier">$groupName</FONT></TT>

is the name of the group. The <TT><FONT FACE="Courier">$comment</FONT></TT>

field is a string placed in the attributes field of that group.

<P>

To delete a group, you have to specify the name of the group in

one of the following functions:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">LocalGroupDelete($server, $group);<BR>

GroupDelete($server, $group);</FONT></TT>

</BLOCKQUOTE>

<P>

<TT><FONT FACE="Courier">$server</FONT></TT> is the name of the

server. It may be <TT><FONT FACE="Courier">NULL</FONT></TT> to

specify the local server. The <TT><FONT FACE="Courier">$groupName</FONT></TT>

is the name of the group you are about to delete.

<H3><A NAME="CommentsAboutaGroup">Comments About a Group</A></H3>

<P>

Given a group name, you can get its attributes with a call to

one of these functions:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">LocalGroupGetAttributes($server, $groupName,

$comment);<BR>

GroupGetAttributes($server, $groupName,$comment);</FONT></TT>

</BLOCKQUOTE>

<P>

<TT><FONT FACE="Courier">$server</FONT></TT> is the n

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -