Change User Password at Next Login With a VBScript - vbscript

I have a standalone computer connected to a basic router at home and has time warner. I am trying to write a script so that i can run it on the computer and it will make me change my password at next login.
Ive tried the following script where UAL-10167 is the computer name and the username is: UAL-Lab-Tech
And it is not working. Any Advise would be great!!
strComputer = "UAL-10167"
Set objUser = GetObject("WinNT://" & strComputer & "/UAL-Lab-Tech")
objUser.Put "PasswordExpired", 1
objUser.SetInfo

I know it's an old question, but it still unanswered...
To force a user to set his or her password on the next log on set the pwdLastSet property to 0, as in...
objUser.Put "pwdLastSet", 0
objUser.SetInfo

Related

VBScript (HTA) MapNetworkDrive - Logon Failure

I am trying to create a HTA file that, among other things, connects to a remote network drive on a Windows 7 PC. In order to do this I need a username / password. I have the following code:
Sub ConnectDrive
Set objNetwork = CreateObject("WScript.Network")
Set oShell = CreateObject("Shell.Application")
objNetwork.MapNetworkDrive "x:", "\\testsystem3\temp", False, User, Pass
If Err.Number = 0 Then
oShell.NameSpace("x:").Self.Name = "Temp on TS3"
End If
Set oShell = Nothing
Set objNetwork = Nothing
End Sub
User and Pass are the actual username and password used in order to connect.
The problem is that I get a Logon failure error message: "Logon failure: unknown user name or bad password".
I am sure that the username and password are ok since using the net use x: \\testsystem3\temp /user:User pass command connects the drive successfully.
Any suggestions how to get this to work? I could turn off password protected sharing on the Windows 7 machine but I wouldn't like that...
Thank you!

VBScript to have a local user change password at next logon?

I am trying to get a script to run for a local user while logged in to have there user account require them to change their password once they log of then log back in. I have about 40 different users that all have there own local internet connection so i don't have active directory for these computers where i can easily set this. I want to be able to push out a script through remote access that will preform this action (having to reset their password).
The user account name that I am trying to run the script for is called: Ual-Lab-Tech
The script I am running is:
' Bind to local user object.
Set objUser = GetObject("Ual-Lab-Tech")
' Require password change at next logon.
objUser.PasswordExpired = 1
objUser.SetInfo
However when I run the script I am getting an error:
Script: C:\\Users\UAL-Lab-Tech\Desktop\change password at logon.vbs
Line: 2
Char: 1
Error: Invalid syntax
Code: 800401E4
Source (null)
What am I doing wrong?
The sample above is for local accounts.
For an AD account you have to use ADSI like this:
Set objUser = GetObject ("LDAP://CN=username,CN=Users,DC=domain,DC=local")
objUser.Put "PasswordExpired", 1
objUser.SetInfo
You will find a working sample here:
strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer ")
objUser.Put "PasswordExpired", 1
objUser.SetInfo

Running a vbs file via a scheduled task on Server 2003

I've been working on modifying an existing vbscript. The wierd part is that when I run the script manually, it works fine. But as soon as I try to run it as a scheduled task, it reports as complete, but doesn't actually do anything. After much troubleshooting, I think I tracked it down to the original CreateObject. Here's the code:
On Error Resume Next
'create an instance of IE
Dim oIE, objFSO, linenum
linenum = 0
Set oIE = CreateObject("InternetExplorer.Application")
'If err.number <> 0 Then linenum = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile ("C:\test.txt", ForAppending, True)
'objTextFile.WriteLine(now() & " Internet object created.")
'Execute our URL
'oIE.navigate("<intranet site>")
'objTextFile.WriteLine(now() & " Starting import")
'wait for the window to be closed (exit IE)
'Do Until Err : oIE.visible = True : wsh.sleep 1000 : Loop
'objTextFile.WriteLine(now() & " Import complete.")
if Err.Number <> 0 then
' An exception occurred
objTextFile.WriteLine("Exception:" & vbCrLf & " linenum: " & linenum & vbCrLf & " Error number: " & Err.Number & vbCrLf & " Error source: " & Err.source & vbCrLf & " Error description: " & Err.Description & vbCrLf)
End If
'clean up
'oIE.Quit
'oIE.Visible = False
'Set oIE = Nothing
I've commented most of it out, to narrow it down, and from the logging I added, it spits out the current error:
Exception:
linenum: 0
Error number: -2147467259
Error source:
Error description:
Yes, the source and description lines are blank.
Googling the error doesn't seem to bring up anything useful. So I'm not sure what's going on. Permissions have been checked multiple times, and it's always run as Administrator, the same user as I'm logged in as. The funny part is, this script works fine with Windows 2000. About the only thing I can think of is perhaps the Remote Desktop connection I'm using is somehow interfering with it.
Anyone have any ideas or things I might be able to try to resolve this?
For reference, when you've got problems googling a decimal error number, try converting it to hexadecimal. -2147467259 is the same as 80004005 and if you search for that you'll find that it's quite a common error and usually means that you're denied access to something so even if you're sure that it's not permissions for the things you've checked, it might be worth doing the following checks:
Does the scheduled task run under the same account as you used when you executed the script manually? Otherwise, try doing a RunAs on the script to run as the same user account as the task, if that works, try scheduling the task as your account.
That way you'll know if it's (task vs manual) or if it's (user1 vs user2). Which might make it a little easier to track down the issue.

Retrieve all users from Active Directory (LDAP) using VBScript

How can I retrieve all users from Active Directory using VBScript?
Dim oDomain = GetObject("LDAP://OU=YourOU,DC=YourDomain,DC=com")
For Each oUser in oDomain
WScript.echo oUser.Get("distinguishedName")
Maybe this will get you running?

End win32 process vbscript

I've got the following code to end a process, but I still receive an error code 2 (Access Denied).
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'MSSEARCH.exe'")
For each objProcess in colProcessList
wscript.echo objProcess.processid
intrc = objProcess.Terminate()
if intrc = 0 then wscript.echo "succesfully killed process" else wscript.echo "Could not kill process. Error code: " & intrc End if
It's quite legitimate to get "access denied" for ending a program. If it's a service (which I'm guessing mssearch.exe is), then it is probably running as the "SYSTEM" user, which has higher privileges than even the Administrator account.
You can't log on as the SYSTEM account, but you could probably write a service to manage other services...
As a non-privileged user, you can only end processes you own. In a multiuser environment this can bite you in the ankle, because WMI would return equally named processes from other users as well, unless you write a more specific WQL query.
If your process is a service, and your script runs under a privileged account, you may still need to take "the regular route" to stop it, for example using WScript.Shell to call net stop or sc.exe, or, more elegantly, using the Win32_Service class:
Set Services = objWMIService.ExecQuery _
("SELECT * FROM Win32_Service WHERE Name = '" & ServiceName & "'")
For Each Service In Services
Service.StopService()
WSCript.Sleep 2000 ' wait for the service to terminate '
Next
If you look on this page: http://msdn.microsoft.com/en-us/library/aa393907(VS.85).aspx you would see that error code 2 is access denied instead of file not found

Resources