I am trying to change the starting program for a particular user. I have some code that works fine on Windows Server 2003:
Set objUser = GetObject("WinNT://localhost/sysadmin")
objUser.TerminalServicesInitialProgram = "C:\myapp.exe"
objUser.TerminalServicesWorkDirectory = "C:\"
objUser.SetInfo
However, when I run it on a 2000 server, it fails on the first line, and I get the following error:
Error: The network path was not found.
Code: 80070035
Source: (null)
I found an alternate way to achieve the same thing:
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set colUsers = GetObject("WinNT://" & strComputer)
colUsers.Filter = Array("user")
For Each objUser In colUsers
If (InStr(objUser.Name, "sysadmin")) Then
objUser.TerminalServicesInitialProgram = "C:\myapp.exe"
objUser.TerminalServicesWorkDirectory = "C:\"
End If
Next
Again, this works in 2003, but in 2000, it fails inside the If
part of the code, and I get the following error:
Error: Object doesn't support this property or method: 'objUser.TerminalServicesInitialProgram'
Code: 800A01B6
Source: Microsoft VBScript runtime error
In both 2000 and 2003, you can go into Administrative Tools->Computer Management->System Tools->Local Users and Groups->Users
, select the properties for the user, go to the Environment
tab, and change the program file name under Starting program
. That would make me think there has to be a way to access that property in 2000 if it can be done in 2003. I've searched the registry for my new app name after adding it, in hopes that I might be able to change the starting program there, but no luck.
EDIT: I added a new test user for this, incorporating the answer from Nilpo, and got past the part of creating the user object with something approximately like this line:
Set objUser = GetObject("LDAP://CN=joe,CN=Users,DC=lab,DC=server,DC=net")
I get the same error I mentioned above: Object doesn't support this property or method: 'objUser.TerminalServicesInitialProgram'
So that means that four alternate methods for attempting to do this have failed. Does anyone have any other ideas for this?