Created
November 27, 2015 16:19
-
-
Save WildGenie/546a562977b4e7e84c59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.DirectoryServices; | |
using System.Runtime.InteropServices; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
DirectoryEntry localDir = new DirectoryEntry("WinNT://" + Environment.MachineName + ",Computer"); | |
foreach (DirectoryEntry nodeDir in localDir.Children) | |
{ | |
if (nodeDir.SchemaClassName == "User") | |
{ | |
Console.WriteLine("USER={0}", nodeDir.Name); | |
} | |
} | |
string nameUser; | |
Console.WriteLine("name? "); | |
nameUser = Console.ReadLine(); | |
try | |
{ | |
DirectoryEntry user_ = new DirectoryEntry("WinNT://" + Environment.MachineName + "/" + nameUser); | |
ActiveDs.IADsUser localUser = (ActiveDs.IADsUser)user_.NativeObject; | |
string s = ((TSUSEREXLib.IADsTSUserEx)localUser).TerminalServicesInitialProgram; | |
Console.WriteLine(s); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("{0} Exception caught.", e); | |
} | |
try | |
{ | |
DirectoryEntry userDE = localDir.Children.Find(nameUser, "user"); | |
ActiveDs.IADsUser iADsUser = (ActiveDs.IADsUser)userDE.NativeObject; | |
TSUSEREXLib.IADsTSUserEx m_TsUser = (TSUSEREXLib.IADsTSUserEx)iADsUser; | |
m_TsUser.TerminalServicesInitialProgram = "c:\\progra~1\\1cv8\\bin\\1cv8.exe"; | |
m_TsUser.TerminalServicesWorkDirectory = Environment.GetEnvironmentVariable("windir"); | |
userDE.CommitChanges(); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("{0} Exception caught.", e); | |
} | |
Console.WriteLine("Write successful"); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment