This question already has answers here:
C#: code error while changing the active directory user's password
(3 answers)
Closed 8 years ago.
I am trying to change the password of a particular user
you can find code below
var directoryEntryObject = new DirectoryEntry("LDAP://<IP>","administraor", "password");
baseObject.directoryEntryObject.Invoke("SetPassword", new object[] { "test#123" });
baseObject.directoryEntryObject.Properties["LockOutTime"].Value = 0;
baseObject.directoryEntryObject.Close();
Now i am getting below Error ::
Unknown name. (Exception from HRESULT: 0x80020006
(DISP_E_UNKNOWNNAME))
administraor -> is this the real username you are trying? Check the spelling of the username, it is administrator.
If you just typed here with this mistake, try
var directoryEntryObject =
new DirectoryEntry("LDAP://<IP>/Dc=domain,DC=local","administrtaor", "password");
Related
This question already has answers here:
When do we need to set ProcessStartInfo.UseShellExecute to True?
(5 answers)
Closed 2 months ago.
I am following this answer about making hyperlink work in a RichTextBox? by adding this:
private void mRichTextBox_LinkClicked (object sender, LinkClickedEventArgs e) {
System.Diagnostics.Process.Start(e.LinkText);
}
(Actually what I'm really doing is to go to the property of the control, click on the LinkClicked action, and just put the Start() method in there.)
However when clicking the link I get this error:
System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'https://example.com' with working directory 'XYZ'. The system cannot find the file specified.'
Why is that?
If you are using .NET 6 or higher, try this:
Process.Start( new ProcessStartInfo { FileName = e.LinkText , UseShellExecute = true } );
This question already has answers here:
How to get client's computer name
(3 answers)
Closed 7 months ago.
The community reviewed whether to reopen this question 7 months ago and left it closed:
Original close reason(s) were not resolved
There is any way to get the PC Name of a client Machine in web application, who is working in different Network, in c# asp.net ?
"This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. showing this error.
By doing the answer given in this
How to get client's computer name ,
I think this will help you:
string clienIp = Request.UserHostName;
string computenMame = CompName(clientIp);
public static string CompName(string clienIp)
{
IPAddress myIP = IPAddress.Parse(clienIp);
IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
List<string> compName =
GetIPHost.HostName.ToString().Split('.').ToList();
return compName.First();
}
This question already has answers here:
Set .NET CLR Version to No Managed Code
(3 answers)
Closed 2 years ago.
When trying to assign a Managed RunTime Version version with this code:
using (ServerManager serverManager = new ServerManager())
{
ApplicationPool newAppPool = serverManager.ApplicationPools.Add("HICS");
newAppPool.ManagedRuntimeVersion = "No Managed Code";
}
It sets the version to "No Managed Code", but it's not the right selection. I end up with this:
If I select the other "No Managed Code", the App Pool works just fine. Why is it creating a duplicate option? How can I select the existing "No Managed Code"? Using C# code of course..
Try setting it to "", like in this answer. It should still work, although they are setting this value in a slightly different method.
using (ServerManager serverManager = new ServerManager())
{
ApplicationPool newAppPool = serverManager.ApplicationPools.Add("HICS");
newAppPool.ManagedRuntimeVersion = "";
}
This question already has answers here:
Substring index and length must refer to a location within the string
(9 answers)
Closed 5 years ago.
I am trying to log errors that may happened within my application and insert it into oracle database as below, but I am getting error at substring that says
Index and length must refer to a location within the string.
catch (Exception EX)
{
string ErrorMsg = EX.Message.Substring(1, 1024);
Error_log(ErrorMsg, null, "InsertProductData", "F0103", null);
MessageBox.Show("Please call technical support", "ُError Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
anyone can help please ? is there more infroamtion I can save too ? anyway to extract error code ? not only the error message ?
Sutloion Feedback
Thank you all ..
just want to give feedback for other on how solved issue like this
I solved by using below code
string ErrorMsg = ex.Message.Substring(0, Math.Min(ex.Message.Length, 1024));
change EX.Message.Substring(1, 1024) to EX.Message.Substring(1,Math.Min(Ex.Message.Length - 1,1024))
I need to write a program that will take a existing local windows user, change the "Start the following program at logon field" in their environment tab and change the password to a new password.
I am using local users instead of AD, will System.DirectoryServices work? Also any tutorials on using System.DirectoryServices would be very helpful.
EDIT --
Ok, so I can find the existing user and I know how to update it. However I do not know what to put in the ???. What AD property represents "Start the following program at logon field" in their environment tab on the user settings page?
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 });
EDIT two---
I now know that the field I need is "Parameters" however I this term is very hard to search for in the MSDN because it is such a generic term. I think I have the correct one because when i run the code
DirectoryEntry entry = new DirectoryEntry("WinNT://testComputer/testUser");
Console.WriteLine("connected");
string value = (string)entry.Properties["Parameters"].Value;
Console.WriteLine(value);
I get the result
P☺CtxCfgPresent????☺CtxCfgFlags1
????☺CtxShadow????*☻☺CtxMinEncryptionLevel? #☺CtxWorkDirectory??????????????????
??????????????"C☺CtxInitialProgram??????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????
????????
I am guessing that InitalProgram portion is close to what I want, most likely the ??? after is is the existing path that is there but has be mucked up.
Now the question is how do I write correctly to it?
Edit-3
I try changing the casting from a string to a PropertyValueCollection however that just gives me the error at run time
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
My copy of the TechNet Script Repository says that this WSH script can be used to change the password.
Set objComputer = GetObject _
("LDAP://CN=atl-dc-01,CN=Computers,DC=Reskit,DC=COM")
objComputer.SetPassword "whatever"