jcarrington
asked on
Impersonation problem in vbscript with winnt
I am trying to develop a vbscript file that will run and reset the local administrator account password to one of my choosing.
Background:
1. This will be run off a logon script
2. Running on windows xp platforms
Code:
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
ComputerName=WshNetwork.Co mputerName
NewPassword = "password"
Set objAllAcounts = GetObject("winmgmts:{imper sonationLe vel=impers onate}!\\" & ComputerName & "\root\cimv2").ExecQuery(" Select * from Win32_UserAccount")
For Each objSystemUser in objAllAcounts
if Right(objSystemUser.SID,3) ="500" Then
'Reset Password
Set objUser = GetObject("WinNT://" & ComputerName & "/" & objsystemuser.name & ",user")
objUser.SetPassword(NewPas sword)
Exit For
end if
next
This code works fine when you run it with an account with administative priveldges. With just user rights the objallaccounts impersonation works fine, but the objuser does not. I know this is because there is no impersonation on the objuser like it is on the objallacounts.
How can I impersonate the objuser? I read one of the fourms concerning this issue but it did not address an answer to the WINNT impersonation problem?
Background:
1. This will be run off a logon script
2. Running on windows xp platforms
Code:
Set WshNetwork = WScript.CreateObject("WScr
ComputerName=WshNetwork.Co
NewPassword = "password"
Set objAllAcounts = GetObject("winmgmts:{imper
For Each objSystemUser in objAllAcounts
if Right(objSystemUser.SID,3)
'Reset Password
Set objUser = GetObject("WinNT://" & ComputerName & "/" & objsystemuser.name & ",user")
objUser.SetPassword(NewPas
Exit For
end if
next
This code works fine when you run it with an account with administative priveldges. With just user rights the objallaccounts impersonation works fine, but the objuser does not. I know this is because there is no impersonation on the objuser like it is on the objallacounts.
How can I impersonate the objuser? I read one of the fourms concerning this issue but it did not address an answer to the WINNT impersonation problem?
ASKER
The RUNAS command will not work in this situation. That works if I was launching an external program from the above code. I need the elevated permission incorporated inside the same code to be able to execute the setpassword command.
Your right, you do need runas to launch another program to do this... but that's simple... a batch file that ueses "net user" commands can do this easily
runas /user:net-admin@yourDomain Here reset.bat
reset.bat (begin)
@echo off
REM no domain specified, local machine account is defaulted
net user administrator 123456
:end
The password must be entered in manually with this example, before reset.bat run's.
-rich
runas /user:net-admin@yourDomain
reset.bat (begin)
@echo off
REM no domain specified, local machine account is defaulted
net user administrator 123456
:end
The password must be entered in manually with this example, before reset.bat run's.
-rich
ASKER
I tryied the run as but it is limited. The Code section:
if Right(objSystemUser.SID,3) ="500" Then
'Reset Password
Set objUser = GetObject("WinNT://" & ComputerName & "/" & objsystemuser.name & ",user")
objUser.SetPassword(NewPas sword)
Exit For
end if
I am evaluating which account is the administrator account and grabing the name with the objUser line. The problem is that if you try this with user rights the objUser will dispaly an insufficent rights type error message.
The runas command only works if you already have the acocunt information. I am trying to gather the information and proceed to reset the password.
if Right(objSystemUser.SID,3)
'Reset Password
Set objUser = GetObject("WinNT://" & ComputerName & "/" & objsystemuser.name & ",user")
objUser.SetPassword(NewPas
Exit For
end if
I am evaluating which account is the administrator account and grabing the name with the objUser line. The problem is that if you try this with user rights the objUser will dispaly an insufficent rights type error message.
The runas command only works if you already have the acocunt information. I am trying to gather the information and proceed to reset the password.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Awesome, if you want your points back, visit: https://www.experts-exchange.com/Community_Support/
and post your intentions.
-rich
and post your intentions.
-rich
For instance, you have all your computers joined to a domain, and by default when a PC is joined to a domain, the domain admin's group is added to the local administrator's group of the PC's. using an account in the domain admins group could easily reset any password on the local PC.
The main problem with a logon script and runas is that the password must be fed plain-text... unless you envoke a program that will obusificate the pass, and inject it into the cmd line for you. I've done this in the past, using cygwin(perl) and the runas utiltiy. if this sounds like a means to your end, I can give you the example code- but if your dead-set on VB, perhaps someone else could answer your question.
http://www.microsoft.com/windows2000/en/professional/help/default.asp?url=/windows2000/en/professional/help/windows_security_runas.htm
-rich