|
-
June 23rd, 2006, 03:22 PM
#7
Junior Member
Hi everyone, I actually got a vb script recently that allows certain users admin rights on the machine and it works rather well. I was hoping that someone could look at the script and help me with an if.....then statement. Right now, if the user is already an admin on the machine, it gives an error that the account already exists. Here is the script.
Option Explicit
Dim Shell
Set Shell=wscript.createobject("wscript.shell")
Dim fso
Set fso = wscript.CreateObject("Scripting.FileSystemObject")
'On Error Resume Next
Main
If err.number <> 0 then
MsgBox err.description,vbcritical,wscript.scriptname
End If
wscript.quit
Sub main
'--------------------------------------------------------- Main -
Set objNet = CreateObject("WScript.Network") 'new
Dim strUser, StrGroup, oComputer, cuser
Dim oUser, oGroup, sComputerName, objNet, objnetwork, suser
suser = objnet.username
strUser = suser
strGroup = "Administrators"
sComputerName = objNet.ComputerName 'new
Set oComputer = GetObject("WinNT://" & sComputerName)
Set oUser = oComputer.Create ("User", strUser)
On Error Resume Next
Dim strComputer
Dim objWMIService
Dim colItems
oUser.SetPassword "password"
oUser.Put "PasswordExpired", 1
oUser.Fullname = "Fullname"
oUser.Description = "Description"
oUser.SetInfo
Set oGroup = oComputer.GetObject("Group", strGroup)
oGroup.Add(oUser.ADsPath)
oGroup.SetInfo
wscript.echo "User [" & strUser & "] added to[" & strGroup & "] Group"
Set oUser = nothing
Set oGroup = nothing
'-----------------------------------------------------------------
End Sub
Any help would be great!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|