Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript detecting and adding logged on user to local admin

Status
Not open for further replies.

Asher01

MIS
Oct 10, 2012
3
CA

vbscript.
-----------------------
Set wshShell = WScript.CreateObject("WScript.Shell")
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
WScript.Echo "User Name: " & strUserName

'the above script detects User logged on to the computer and it works fine, The botom script gets the user "Test" which is already in local users group and adds it to the local admin group.

what I would like to do is joing both scripts so I detect the logged on user in the above script then fetch or put it it into the "StrUser" so it is used be added to the local admin group. in windows 7.

strUser = "Test"

Set objWshNet = CreateObject("WScript.Network")
strDomain = objWshNet.UserDomain
strComputer = objWshNet.ComputerName
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
If Not objGroup.IsMember(objUser.ADsPath) Then
objGroup.Add(objUser.ADsPath)
End If


I did this but, it did not work.

Set wshShell = WScript.CreateObject("WScript.Shell")
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
' WScript.Echo "User Name: " & strUserName

strUser = strUserName

Set objWshNet = CreateObject("WScript.Network")
strDomain = objWshNet.UserDomain
strComputer = objWshNet.ComputerName
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
If Not objGroup.IsMember(objUser.ADsPath) Then
objGroup.Add(objUser.ADsPath)
End If

Many thanks

 
Post this problem in: forum329

You'll get the best replies.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top