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".
ASKER
Moving in that direction, but not yet.
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
YohanShminge,
so the script should contain the following:
-------------------------- ---------- ---------- ---
Set SH = CreateObject("WScript.Shel l")
Set objNet = CreateObject("WScript.NetW ork")
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
-------------------------- ---------- ---------- ----
so the script should contain the following:
--------------------------
Set SH = CreateObject("WScript.Shel
Set objNet = CreateObject("WScript.NetW
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
Yohan
Perfect timing! ;-) And yes, that should do it exactly.
ASKER
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"."
ASKER
You got it right YohanShminge
ASKER
YohanShminge,
That worked! Thanks.
That worked! Thanks.
ASKER
I hav another question posted. Take a look when you have a moment.
ASKER
YohanShminge,
Anywhat to have the script create a log file of user ID or computer names that are modified?
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?
ASKER
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.Shel l")
Set objNet = CreateObject("WScript.NetW ork")
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Set ts = fso.OpenTextFile("\\server name\share name\logfi le.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.")
-------------------------- ---------- ---------- ----
--------------------------
Dim fso, ts
Const ForAppending = 8
Set SH = CreateObject("WScript.Shel
Set objNet = CreateObject("WScript.NetW
Set fso = CreateObject("Scripting.Fi
Set ts = fso.OpenTextFile("\\server
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("\\server name\share name\logfi le.txt", ForWriting, True)
I could really use this script :)
Thanks.
Set ts = fso.OpenTextFile("\\server
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?
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
Const ForWriting = 2
Thanks Yohan.
I changed the ForWriting to ForAppending and that seemed to the trick also.
I changed the ForWriting to ForAppending and that seemed to the trick also.
Is your network running the active directory?