Func _NetUserChangeName($sUserName, $sNewName, $sSystem = "")
Local $iResult, $tName, $pName, $tUserName, $pUserName
$tName = DllStructCreate("wchar[256]")
$pName = DllStructGetPtr($tName)
DllStructSetData($tName, 1, $sNewName)
$tUserName = DllStructCreate("ptr")
$pUserName = DllStructGetPtr($tUserName)
DllStructSetData($tUserName, 1, $pName)
$iResult = DllCall("netapi32.dll", "dword", "NetUserSetInfo", _
"wstr", $sSystem, "wstr", $sUserName, _
"dword", 0, "ptr", $pUserName, "int*", 0)
$tName = 0
$tUserName = 0
Return SetError($iResult[0], 0, $iResult[0] = 0)
EndFunc ;==>_NetUserChangeName()
使用方法:
_NetUserChangeName("要修改的用户名", "修改后的用户名")
例:
$iResult = _NetUserChangeName("test", "NewName")
If $iResult Then
Msgbox(0, "", "Done!")
Else
Msgbox(0, @error, "Failed")
EndIf