Hi and thanks for looking at this post...
After a day or two of searching I've failed to find exactly what I need and hope that someone may be able to spread some light on this for me!
Basically I hope to have a script that when run under a SYSTEM context on a machine will obtain the current logged on user and add them to the local admin group of the computer, a huge bonus would be if it then wrote the user details to a txt file file on the computer somewhere.
So far all I've been able to find are snippets that dont actually achieve this exact thing and being totally ignorant of vbs etc I've not been able to figure out how to declare this current user variable or pass it to add them to the group!
The closest thing I've found is:
Set oWshNet = CreateObject("WScript.Network" )
sUser = "fill in some domain user name here"
sNetBIOSDomain = oWshNet.UserDomain
sComputer = oWshNet.ComputerName
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group" )
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user" )
' suppress errors in case the user is already a member
On Error Resume Next
oGroup.Add(oUser.ADsPath)
On Error Goto 0
But as you can see this requires an explicit Username.
Anyone who is able to give advice here it is very gratefully received as this is driving me mad!
Many thanks!
After a day or two of searching I've failed to find exactly what I need and hope that someone may be able to spread some light on this for me!
Basically I hope to have a script that when run under a SYSTEM context on a machine will obtain the current logged on user and add them to the local admin group of the computer, a huge bonus would be if it then wrote the user details to a txt file file on the computer somewhere.
So far all I've been able to find are snippets that dont actually achieve this exact thing and being totally ignorant of vbs etc I've not been able to figure out how to declare this current user variable or pass it to add them to the group!
The closest thing I've found is:
Set oWshNet = CreateObject("WScript.Network" )
sUser = "fill in some domain user name here"
sNetBIOSDomain = oWshNet.UserDomain
sComputer = oWshNet.ComputerName
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group" )
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user" )
' suppress errors in case the user is already a member
On Error Resume Next
oGroup.Add(oUser.ADsPath)
On Error Goto 0
But as you can see this requires an explicit Username.
Anyone who is able to give advice here it is very gratefully received as this is driving me mad!
Many thanks!