问题
I have a environment where I need to frequently change the parameters to a program that is launched when a user logs in to the terminal server. As of right now we open the computer management snap-in and edit the environment tab for the user and change the parameters by hand under "Start the following program at logon:". I would like to automate the process.
I have been looking in to System.DirectoryServices and System.DirectoryServices.AccountManagement and reading all I can about it. So far my best guess is that the information I need to edit is stored in the "Parameters" Properties (worst name possible for a property, ruins googling). The reason for that guess is when I list all of the Properties I get
(...)
Name: HomeDirDrive
Value:
Name: Parameters
Value: P☺CtxCfgPresent????☺CtxCf
gFlags1????☺CtxShadow????*☻☺CtxMinEncryptionLevel? @☺CtxWorkDirectory???????????
?????????????????????"C☺CtxInitialProgram???????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
???????????????
Name: PrimaryGroupID
Value: 513
(...)
CtxInitialProgram and CtxWorkDirectory seem relevant to what I am working with.
Now I am stuck as I can not figure out how to, or find and resources to help me out, reading and writing the values correctly.
Any help would be greatly appreciated.
EDIT -- I found this answer elsewhere on the internet Asking elsewhere on the internet I found the answer:
Unfortunately this data is encoded in a proprietary format. The only supported way to manage it programmatically is by using the IADsTSUserEx ADSI interface that comes with terminal services. You basically just cast the NativeObject property to this COM interface (after creating the required COM reference) and then access the properties exposed by the interface.
Now my question is how do I set up that COM reference, I have never done anything like that before.
回答1:
Asking elsewhere on the internet I found the answer:
Unfortunately this data is encoded in a proprietary format. The only supported way to manage it programmatically is by using the IADsTSUserEx ADSI interface that comes with terminal services. You basically just cast the NativeObject property to this COM interface (after creating the required COM reference) and then access the properties exposed by the interface.
来源:https://stackoverflow.com/questions/2000544/managing-terminal-users-through-system-directoryservices