![]() |
|
|
|
|
1
17th October 17:41
External User
Posts: 1
|
Hi guys,
I need some help with this.. I have a script that changes the user's logon name (local workstation logon name) in Win 2000/XP but it very often fails to work in Vista. Is there any alternative code to what I've reproduced below? Perhaps there's some code being used that has been replaced by something new in Vista? 'Get current username Set oWshNet = CreateObject("WScript.Network") sOldUser = oWshNet.UserName ' get input data dim RetVal RetVal = "" do RetVal = UCase(InputBox("If you are a student press S" & vbcrlf & "If you are a guest press G" & vbcrlf & vbcrlf & "And then click OK","Change Current Windows Logon Name")) if RetVal = "" then WScript.Quit loop until RetVal = "S" or RetVal = "G" Select Case RetVal Case "S" do if sNewUser <> "" then MsgBox "The data entered is incorrect.",vbOK,"Change Current Windows Logon Name" sNewUser = InputBox("Please enter your 8 digit Student Number.", "Change Current Windows Logon Name") if sNewUser = "" then WScript.Quit vNewUser = InputBox("Please confirm your 8 digit Student Number.", "Change Current Windows Logon Name") loop until len(sNewUser)=8 and IsNumeric(sNewUser) and sNewUser=vNewUser Case "G" do if sNewUser <> "" then MsgBox "The data entered is incorrect.",vbOK,"Change Current Windows Logon Name" sNewUser = InputBox("Please enter your 10 digit Guest Card Number.", "Change Current Windows Logon Name") if sNewUser = "" then WScript.Quit vNewUser = InputBox("Please confirm your 10 digit Guest Card Number.", "Change Current Windows Logon Name") loop until len(sNewUser)=10 and IsNumeric(sNewUser) and sNewUser=vNewUser end select sNewUser = Ucase(sNewUser) Res = Msgbox ("Your current Windows Logon Name ''" & sOldUser & "'' will be changed to ''" & sNewUser & "''" & vbcrlf & "Do You wish to proceed?", vbYesNo,"Confirm Action") if Res = vbNo then WScript.Quit ' get computer name for local computer sComputerName = oWshNet.ComputerName Set oComputer = GetObject("WinNT://" & sComputerName) ' Turn off internal error handling On Error Resume Next ' connect to user object Set oUser = GetObject("WinNT://" & sComputerName & "/" & sOldUser & ",user") ' rename user Set oNewUser = oComputer.MoveHere(oUser.ADsPath, sNewUser) If Err.Number <> 0 Then WScript.Echo "Failed to rename user " & sOldUser Else WScript.Echo "User is renamed to " & sNewUser & vbcrlf & "You must restart your computer for changes to take effect." End If On Error Goto 0 Any help would be appreciated. Mark. Mark Moran IT Support UCDCopi-Print Main Library Building Belfield Dublin 4 Tel: +353 1 7167180 E-mail: mark.moran@ucd.ie |
|
|
|
|
3
17th October 17:41
External User
Posts: 1
|
I would not expect users would have permission to change the name of the
account they logon with. This would be true with any OS, but Vista probably requires elevated permissions even if the user has local administrator privileges. In other words, if the script works, it probably must be run using "Run as administrator". -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
|