2012-04-12 127 views
0

我有下面的代碼,「應」勾選框在下次登錄時更改本地用戶密碼,但我不斷收到錯誤。更改密碼在下次登錄... vbscript

該賬戶已經創建,並在本地服務器上。

請任何幫助。

由於我們環境中的舊服務器,我必須在vbscript中執行此操作,而不是powershell。

代碼:

' get computer name 
Set oWshNet = CreateObject("WScript.Network") 
sComputerName = oWshNet.ComputerName 

'Set Account Testuser Password Expired parameter 
Set objUser = GetObject("WinNT:// " & sComputerName & "/Testuser") 
objUser.Put "PasswordExpired", 1 
objUser.SetInfo 

錯誤:

account.vbs(6,1)(空):網絡路徑沒有被發現。

** * **編輯* ** * ** * ****

想通了:(!感謝谷歌)

Set oShell = CreateObject("WScript.Shell") 
Const SUCCESS = 0 

sUser = "TestUser" 

' get the local computername with WScript.Network, 
' or set sComputerName to a remote computer 
Set oWshNet = CreateObject("WScript.Network") 
sComputerName = oWshNet.ComputerName 

Set oUser = GetObject("WinNT://" & sComputerName & "/" & sUser) 

oUser.Put "PasswordExpired", 1 
oUser.SetInfo 

oShell.LogEvent SUCCESS, "Password Attribute Changed" 
+0

你應該張貼您的「想通了」編輯作爲一個答案,兩天後接受的答案。 – HK1 2012-04-13 12:55:18

回答

0

謝謝。

這個問題的答案是:

Set oShell = CreateObject("WScript.Shell") 
Const SUCCESS = 0 

sUser = "TestUser" 

' get the local computername with WScript.Network, 
' or set sComputerName to a remote computer 
Set oWshNet = CreateObject("WScript.Network") 
sComputerName = oWshNet.ComputerName 

Set oUser = GetObject("WinNT://" & sComputerName & "/" & sUser) 

oUser.Put "PasswordExpired", 1 
oUser.SetInfo 

oShell.LogEvent SUCCESS, "Password Attribute Changed" 
相關問題