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