Mombu the Microsoft Forum

Go Back   Mombu the Microsoft Forum > Microsoft > Change Logon script not working in Vista
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 17th October 17:41
mark moran
External User
 
Posts: 1
Default Change Logon script not working in Vista



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
  Reply With Quote


 


2 17th October 17:41
al dunbar
External User
 
Posts: 1
Default Change Logon script not working in Vista



Does it ever work in vista? when it fails to work, what happens?


I find it a bit surprising that you would want users to be able to change
their logon name - how do you keep track of who is who, and how do you know
people are not inputting the wrong student or guest number? And what account
is it that they are logging onto in the first place? /Al
  Reply With Quote
3 17th October 17:41
richard mueller [mvp]
External User
 
Posts: 1
Default Change Logon script not working in Vista


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
--
  Reply With Quote
Reply


Thread Tools
Display Modes




666