C# 在c中更改本地用户设置

C# 在c中更改本地用户设置,c#,active-directory,C#,Active Directory,我需要编写一个程序,该程序将接受现有的本地windows用户,更改“环境”选项卡中“在登录时启动以下程序”字段,并将密码更改为新密码 我使用的是本地用户而不是广告,System.DirectoryServices是否有效?此外,任何有关使用System.DirectoryServices的教程都会非常有用 编辑- 好的,我可以找到现有的用户,我知道如何更新它。但是我不知道该放什么在???。什么AD属性表示在用户设置页面上的环境选项卡的登录字段启动以下程序 DirectorySea

我需要编写一个程序,该程序将接受现有的本地windows用户,更改“环境”选项卡中“在登录时启动以下程序”字段,并将密码更改为新密码

我使用的是本地用户而不是广告,System.DirectoryServices是否有效?此外,任何有关使用System.DirectoryServices的教程都会非常有用

编辑- 好的,我可以找到现有的用户,我知道如何更新它。但是我不知道该放什么在???。什么AD属性表示在用户设置页面上的环境选项卡的登录字段启动以下程序

        DirectorySearcher search = new DirectorySearcher();
        search.Filter = String.Format("(SAMAccountName={0})", prams.user);
        search.PropertiesToLoad.Add("cn");
        SearchResult result = search.FindOne();
        if (result == null)
        {
            Console.Error.WriteLine("No user of name {0} in the system", prams.user);
            return -2;
        }
        DirectoryEntry entry = result.GetDirectoryEntry();
        entry.InvokeSet("???", new object[] { newProgramLognField });
编辑二-- 我现在知道我需要的字段是参数,但是我很难在MSDN中搜索这个术语,因为它是一个通用术语。我想我有正确的答案,因为当我运行代码时

DirectoryEntry entry = new DirectoryEntry("WinNT://testComputer/testUser");
Console.WriteLine("connected");
string value = (string)entry.Properties["Parameters"].Value;
Console.WriteLine(value);
我得到了结果

P☺CtxCfgPresent????☺CtxCfgFlags1
????☺CtxShadow????*☻☺CtxMinEncryptionLevel? @☺CtxWorkDirectory??????????????????
??????????????"C☺CtxInitialProgram??????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
????????
我猜InitalProgram部分接近我想要的,很可能是???之后是现有的路径,但已被弄糟

现在的问题是我如何正确地写入它

编辑-3 我尝试将强制转换从字符串更改为PropertyValueCollection,但这只会在运行时产生错误

Unhandled Exception: System.InvalidCastException: Unable to cast object of type
'System.String' to type 'System.DirectoryServices.PropertyValueCollection'.
at UserUpdater.Program.Main(String[] args) in e:\Visual Studio 2008\Projects\
UserUpdater\UserUpdater\Program.cs:line 91
我的副本说这个WSH脚本可以用来更改密码

Set objComputer = GetObject _
("LDAP://CN=atl-dc-01,CN=Computers,DC=Reskit,DC=COM")
objComputer.SetPassword "whatever"

提醒我完成后不要运行它