# VBS script



## StumpedTechy (Jul 7, 2004)

Can anyone tell me why this isn't working?

blnUserEx = False
strComputer = InputBox("Type in the Computer Name","Computer Name Variable")
strUID = InputBox("Enter Domain User Name", "Domain User Name Variable")
strCmdLine = "mstsc.exe /v:" & strComputer & " /f"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://Domain/" & strUID & "")
If objuser = exist Then
blnUserEx = True
End If
If blUsrEx = True Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run strCmdLine, , True
WshShell.Popup "Please see why " & strUID & " is already an admin on this computer"
Else
objGroup.Add(objUser.ADsPath)
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run strCmdLine, , True
objGroup.Remove(objUser.ADsPath)
End If

I was adding to my previous script that worked like a charm except for one flaw -

strComputer = InputBox("Type in the Computer Name","Computer Name Variable")
strUID = InputBox("Enter Domain User Name", "Domain User Name Variable")
strCmdLine = "mstsc.exe /v:" & strComputer & " /f"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://Domain/" & strUID & "")
objGroup.Add(objUser.ADsPath)
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run strCmdLine, , True
objGroup.Remove(objUser.ADsPath)

The only problem is when the second script hit line Set objUser = GetObject("WinNT://MORLYMCA/" & strUID & "") if the user was already in there it bombed (I know I could then force it to run but then it would automatically remove their admin rights). So I came up with the thought of doing an If exist and then making it so it ran the add user and remove user but it only ran the remote desktop if the user already existed but them prompted us to ask the User why they need admin rights...

Remember that this script is being ran from one PC against a PC that is at a remote site.

Anyone have any clues?


----------



## StumpedTechy (Jul 7, 2004)

Okay I added to it... this makes it so you can "gracefully" exit the script without a VBS error. I am still stuck on only one line.... how in the heck do I tell it if the users is already in the user group (In this case Administrators) then to only perform the remote desktop and then prompt to check why the user is already an admin.

blnUserEx = False
strComputer = InputBox("Type in the Computer Name","Computer Name Variable")
IF strComputer = "" THEN
WScript.Echo "No Computer Name was given or you clicked Cancel"
WScript.Quit
END IF
strUID = InputBox("Enter Domain User Name", "Domain User Name Variable")
IF strUID = "" THEN
WScript.Echo "No Domain User Name was given or you clicked Cancel"
WScript.Quit
END IF
strCmdLine = "mstsc.exe /v:" & strComputer & " /f"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://DOMAIN/" & strUID & "")
IF objuser exists Then <--------- STUCK! (I have tried all combinations) 
blnUserEx = True
End If
If blUserEx = True Then
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run strCmdLine, , True
WshShell.Popup "Please see why " & strUID & " is already an admin on this computer"
Else
objGroup.Add(objUser.ADsPath)
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run strCmdLine, , True
objGroup.Remove(objUser.ADsPath)
End If


----------

