Link to home
Start Free TrialLog in
Avatar of Roebuck1967
Roebuck1967

asked on

Changing the local group via VB logon script from Administrator to Power Users

All my users are currently part of the Administrators local group on their local pc (Windows 2000 environment).  I would like via logon VB logon script to change their existing group from "Administrator" to "Power User".
Avatar of YohanShminge
YohanShminge

Hello Roebuck1967,

Is your network running the active directory?
Avatar of Roebuck1967

ASKER

Moving in that direction, but not yet.
Avatar of Netman66
No problem.  Add this to a logon script.

net localgroup "Power Users" "Domain Users" /add
net localgroup "Administrators" "Domain Users" /delete


This should work, but do it in the above orde.
ASKER CERTIFIED SOLUTION
Avatar of YohanShminge
YohanShminge

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
YohanShminge,

so the script should contain the following:

-------------------------------------------------
Set SH = CreateObject("WScript.Shell")
Set objNet = CreateObject("WScript.NetWork")

usrName = objNet.UserName

addstr = "net localgroup ""Power Users"" """ + usrName + """ /add"
removestr = "net localgroup ""Administrators"" """ + usrName + """ /delete"

SH.Run addstr, 0, true
SH.Run removestr, 0, true
--------------------------------------------------
That script will retrieve the username of whoever has just logged in, create strings like what Netman66 has posted, then execute them.  They will add the user to the power users group, and remove them from the administrators group.

Yohan
Perfect timing! ;-) And yes, that should do it exactly.
Okay, I will test it on Monday.
That will add the username to the local Admin group - you wanted the user's group to be added and deleted.

Is that right?  It sounded like you wanted the user to switch groups: "All my users are currently part of the Administrators local group on their local pc... I would like via VB logon script to change their existing group from "Administrator" to "Power User"."
You got it right YohanShminge
YohanShminge,

That worked!  Thanks.
I hav another question posted.  Take a look when you have a moment.
YohanShminge,

Anywhat to have the script create a log file of user ID or computer names that are modified?
It's possible.  You could have it write some stuff to a file, perhaps on your server?  Would that work for you?
Yes
Alright then, here it be with logging to a server (you'll have to change the path (\\servername\sharename) so it works for you):

-------------------------------------------------
Dim fso, ts
Const ForAppending = 8

Set SH = CreateObject("WScript.Shell")
Set objNet = CreateObject("WScript.NetWork")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile("\\servername\sharename\logfile.txt", ForWriting, True)


usrName = objNet.UserName

addstr = "net localgroup ""Power Users"" """ + usrName + """ /add"
removestr = "net localgroup ""Administrators"" """ + usrName + """ /delete"

SH.Run addstr, 0, true
SH.Run removestr, 0, true

ts.WriteLine(CStr(Now) + " User " + usrName + " has been removed from the Administrators group and added to the Power Users group.")
--------------------------------------------------
Getting an Invalid procedure call or argument on this line

Set ts = fso.OpenTextFile("\\servername\sharename\logfile.txt", ForWriting, True)

I could really use this script :)

Thanks.
nhbb,

What operating system are you using?  If it's windows 95/98, are you sure you have the latest version of WScript installed?  If so, did you copy the entire script exactly?  Have you made any changes to it or added anything?
Oh wow, I just noticed that perhaps I left out a line... I forgot to define the Constant, "ForWriting" seen in that line...  Just add this line to the top of your script and it should work:

Const ForWriting = 2
Thanks Yohan.
I changed the ForWriting to ForAppending and that seemed to the trick also.