Page 1 of 2 12>
Topic Options
#41023 - 2003-06-04 12:40 AM Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
thanks for viewing!

For an NT/2000 network with many remote locations. I want to give the user logging on local admin rights by adding him/her to the local administrators group. When the user first logon he/she doesn't have local admin rights yet so I'm assuming we need to use something like runas. The problem is runas is only avaible for Win2K.

If there is a way, I would like to remove that user from the local administrators group when he/she logs off.

What is the easiest way of doing this for NT/2000 machines?

Thanks.

Ryan

Top
#41024 - 2003-06-04 12:57 AM Re: Adding user to local administrator
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you have specific password for all wksta's on your network... like every wksta has "mydomainwksta" as password that would be easy... with something like su.

anyway, easiest would be setting up a script on some of your servers that reads an ini for all workstations that do not have domain users as the wksta-admins and add them.
that script has a scriptlet in logonscript that checks if user is in local admin and if not, adds the entry to the ini.

ofcourse every domain-user must have access to this ini.

one option is to create similar script which crawls arounds your net immediately and changes all the wksta's found but that way you never have quarantee of getting to all machines.

now, the decision is yours, which way you want to go?
_________________________
!

download KiXnet

Top
#41025 - 2003-06-04 02:50 AM Re: Adding user to local administrator
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Ryan,

Adding them during logon and removing them during logoff is just not practical with any method beyond Active Directory GPO, and even then it would be difficult due to all the timing issues.

I don't see the purpose of add/removing during logon. If you want them to be Local Admins, then make them Local Admins. Who cares if you leave them in the group after logoff. Once they logon again, you'd put them right back. Just doesn't seem to make sense to me.

Why do you want them to be Local Admins? To install an application? Maybe look at using one of the Scheduling UDFs here on the board in the UDF forum. That may be a much easier route.

Top
#41026 - 2003-06-04 03:44 AM Re: Adding user to local administrator
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or take a look at the FAQ Forum under Installing an Application as an Admin
_________________________
There are two types of vessels, submarines and targets.

Top
#41027 - 2003-06-04 04:34 AM Re: Adding user to local administrator
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
All my users are local admin on their own workstation (user on others)

I know all the issues of security and such, as well as preventative steps to keep users from fubar'ing their PCs, but with 2000 desktop here, I seldom 1 or 2 per month have to re-image a machine

As for how to add users to local admin, the simplest solution is the ini file routine mentioned.

make an ini file keyed on computername

[admin]
pc1=joe
pc2=mike
pc3=dilbert
...

then you, using a domain admin acct (or acct with admin on every PC) use one of the remote execute UDFs where you can exec

net localgroup administrators /add $name
against each PC

your problem will be building/maintaining the ini file
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#41028 - 2003-06-04 06:52 PM Re: Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
Thanks for all your replies. Will try using ini and update.

NTDOC - I should have explained it better. Right now our master image has the LocalWrkAdm group in the local administrators group and everyone on our network belongs to it. I ran into problems where users maps to other user's C$ to share data. This is fine except when the other user doesn't know about it. So now we want to remove all users from the LocalWrkAdm group but before we do that we want to give the logon user admin permission to that PC. Removing the user from local admin group is not important right now.

Hope that clear things up.

Thanks

Ryan

Top
#41029 - 2003-06-05 12:07 AM Re: Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
How would I check to see if that user is already a member of the local admin group?

Thanks,

Ryan

Top
#41030 - 2003-06-05 12:11 AM Re: Adding user to local administrator
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
code:
INGROUP('\\'+@WKSTA+'\Administrators')

as documented in the KiXtart Manual.
_________________________
There are two types of vessels, submarines and targets.

Top
#41031 - 2003-06-05 12:23 AM Re: Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
Thanks.
I also found the code below from NTDOC.

Thanks again.

Ryan

IF INGROUP("\\@WKSTA\Administrators")
? "You are a Local Administrator"
ELSE
? "You are NOT a Local Administrator"
ENDIF

Top
#41032 - 2003-06-05 02:17 AM Re: Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
Below is my code

********************************************
If Ingroup ("\\@WKSTA\Administrators")
Else
?
Shell "net localgroup administrators /add @userid"
EndIf
*******************************************

I want it to check if the user belongs to the local admin group, if no add the user. It works first time but when testing it after that, it keeps trying to add the user but since the user is already in the administrator group, there is an error. Also tried using
InGroup("\\" + @WKSTA + "\Administrators")

Am I missing anything?

Thanks,

Ryan

Top
#41033 - 2003-06-05 02:31 AM Re: Adding user to local administrator
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
If not Ingroup("\\@WKSTA\Administrators")
Shell "net localgroup administrators /add @userid"
EndIf

however, if they are in a group, and the group is in administrators, it will not add the userid, as they are already in there.

You need to enumerate the membership of the administrators group and see if one of the items is userid...
or remove the group
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#41034 - 2003-06-05 02:37 AM Re: Adding user to local administrator
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't know... maybe I'm missing something here...
If the users does not have admin rights then they can't add themselves. If you are running the script by impersonating someone with admin rights using SU or RunAs, then the InGroup() and the @UserID would reflect the impersonated user and not the one you want to add.

Confused [Confused]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#41035 - 2003-06-05 04:13 AM Re: Adding user to local administrator
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
there is a global group with all users added to local admin on every wksta

he wants to make each user local admin on only their PC, and eventually remove the global group

so he needs to add userid to the administrators group and then later remove/delete the global group
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#41036 - 2003-06-05 05:40 AM Re: Adding user to local administrator
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Ryan,

Please give this code a try. It requires KiXtart v4.x If possible please use KiXtart v4.21 and modify the code to suite your group names and needs.


Break On
IF LocalAdmin
$AdminFix=READVALUE("HKLM\SOFTWARE\MyCompany", "AdminFixed")
IF $AdminFix=YES
RETURN
ELSE
shell '%COMSPEC% /C net localgroup administrators /add @userid >NUL 2>NUL'
shell '%COMSPEC% /C net localgroup administrators /del LocalWrkAdm >NUL 2>NUL'
$SetAdminFix=WRITEVALUE("HKLM\SOFTWARE\MyCompany", "AdminFixed", "YES", "REG_SZ")
ENDIF
ENDIF

function LocalAdmin()
$LocalAdmin=ingroup('@wksta\'+sidtoname('S-1-5-32-544'))-1+@inwin
endfunction

Top
#41037 - 2003-06-05 06:00 AM Re: Adding user to local administrator
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
or you can use a slightly larger, yet more accurate combination of:

GroupMembers() - returns all members of a given group
and
AScan() - Searches an array for an element containing the same value as an expression

where you use groupmembers to see if the userid in present, if not it adds it
and where you see if the group is present and if so, removes it
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#41038 - 2003-06-05 07:10 AM Re: Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
Thanks NTDOC and Radimus. Will try and let you guys know.
BTW - What do you guys do for a living that you have so much time to reply to all the posts? Just wondering, sorry if it's too personal. I did some search on the forum and I see you guys all over.

Thanks again.

Ryan

Top
#41039 - 2003-06-05 08:24 AM Re: Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
NTDOC,

Your code check for the reg key, we have many users in the production area that share machines, your code is setup for only the first user that logs on to that machine. The second person would not be added to the local admin group. Any other suggestion?

Thanks,

Ryan

[ 05. June 2003, 08:25: Message edited by: Ryan Dao ]

Top
#41040 - 2003-06-06 12:57 AM Re: Adding user to local administrator
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
well, I'm a government employee [Big Grin]

but back to your parameters for your code.

be specific as to how many people are admin on a PC... is there a real pattern or is it just open to anyone who logs onto a PC??

need more detail.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#41041 - 2003-06-05 07:00 PM Re: Adding user to local administrator
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Agreed... Unless you know specifically every employee who should be a local admin on which machines it will be rather difficult to automate.

I actually would not get rid of the Local Admin group you put in place, I'd just remove everyones membership except your desktop support people. That way they will maintain Admin rights on all desktops when they logon.

Unless you have a very documented and strict work force (which it does not sound like) it will be difficult to achieve what you're asking via an automated method.

For now maybe just run the code to allow people who logon locally to add their own account to the local admin group. Then in a couple weeks disable that portion of the script and then remove everyone from that Local Admin group that is added in the Ghost image. Hopefully by then 90% or more of people that should be local admins will already be. For those stragglers that have not made it into the local admin group yet, you can manually assist them remotely if wanted.

Top
#41042 - 2003-06-05 09:25 PM Re: Adding user to local administrator
Ryan Dao Offline
Fresh Scripter

Registered: 2003-03-09
Posts: 45
User should have local admin rights to the machine he/she is logging onto. Doesn't matter who.

The code below doesn't work all the time. It works the first time but when I removed the user from the local admin group and run the script again, it thinks the user is still in the group and will not add. I ran kix32 /f to clear cache with no luck. Any help will be greatly appriciated.

Thanks guys.

IF INGROUP("\\@WKSTA\Administrators")
? "You are a Local Administrator"
ELSE
? "You are NOT a Local Administrator"
shell '%COMSPEC% /C net localgroup administrators /add @userid >NUL 2>NUL'
ENDIF

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 476 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.09 seconds in which 0.03 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org