
Admin user in Logon script
One posible trick would be to add the user to the admin group of the machine
while the script is running and then the last thing to do would be to remove
them again. But, this would require that you know an admin and password of
that machine. You could either use ADSi, you'll have to install if it's not
already - which I would suggest - or dump out to a command prompt and use a
net command, but you'd have to search for help on that method.
'Local Object Vars
dim strUsrPath, adsGrp, wshNet, dso, adsCpu
'Get the network object to get the computer name, users domain, and users
name
set wshNet = CreateObject("WScript.Network")
'bind to the namespace
set dso = GetObject("WinNT:")
'Bind to the computer using an admins credentials
'This will allow you to bind to the administrators group to add the user
'without the user needing to be an administrator
'the parms are 'OpenDSObject(ObjectPath, Admins ID, Admin Pswd, Reserved)'
'the admin ID needs to be in the form 'Domain\ID'
set adsCPU = dso.OpenDSObject("WinNT://" & wshNet.ComputerName, strAdminID,
strAdminPswd, 1)
'Build the adsPath to the current users account
strUsrPath = "WinNT://" & wshNet.UserDomain & "/" & wshNet.UserName
'Bind to the Administrators of the local cpu using the credentials of an
admin
set adsGrp = adsCPU.GetObject("Group", "Administrators")
'add the user to the administrators group
adsGrp.Add adsUsr.AdsPath
......
'Do your script to make changes
......
'Remove the user from the administrators group
adsGrp.Remove adsUsr.AdsPath
'Clear out objects
set adsGrp = nothing
Quote:
> Hello
> Im using WSH for my logon script in our company. I need to delete and
write
> to registy because some globaly changes must be done. If im logging as
> admin, everything works fine, but as user privilege, script dont work.
> So, how can I promote user to admin for the logon time, or trick, how can
i
> start program with admin privileges.
> I think KIX had same solution, but I can not find it...
> Thanks..
> Tomaz Kralj, MCP
> RTV Slovenija