|
You are a geniuse... Thank you... i did not think of that
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
I don't know about genius. I was trying to think of the easiest/laziest way possible
Let me know if you run across any more questions.
|
|
|
|
|
There's several ways of doing this. The 2nd easiest is, like the other person said, to have the script write it to a file.
The 3rd easiest is to rewrite your Shell statement into a .NET Framework Process object and use that to redirect the console output to a stream in your code.
The very easiest way to do this would be to scrap the VBScript part entirely and just use the .NET Frameworks FileSystemWatcher class, which will tell you if a file was created in the folder it's watching and what the new filename is.
|
|
|
|
|
Dave
I seem to have read somewhere that FileSystemWatcher has a problem when too many events hit it too quickly. We looked at it 2 yrs ago and decided to do it manually as we had 1000s of file to process.
|
|
|
|
|
True, if you have a bunch of files being created at once.
|
|
|
|
|
Hi guys.
I wanna pass an event to a sub but i dono how to perform it.
Some thing like this:
Private Sub Event_Performer (ByVal arg1 as ????)<br />
RaiseEvent arg1<br />
End Sub
|
|
|
|
|
Would this help?
http://www.codeproject.com/vb/net/StepByStepEventsInVBNET.asp
|
|
|
|
|
What you really want to accomplish??? why are you doing this !
AliAmjad(MCP)
|
|
|
|
|
You're can not pass an event. You can, however, pass an event arguments object, or EventArgs.
But, depending on what you're really trying to do with this, normally, the only thing that gets the eventargs is the event handler. The handler then picks out what pieces of information it needs and passes those processed pieces to other methods. You would just about never pass an entire eventargs object to a method that is, itself, not an event handler.
It looks like you're trying to raise an event, but the parameters in your header are confusing. What are you really trying to do with this code?? Why does this code exist?
|
|
|
|
|
tnx Guys. I'm implementing and error generator sub that take error code and message from various exeption handlings and it should raise respective events.
|
|
|
|
|
I'm very new to vb.net 2005
Im now the next step of learning and want to connect a Microsort Access database to visual basic.net 2005.
I have tryed to follow an example in Microsoft Visual basic 2005 Reloaded book by Richard A. Johnson. But i'm not getting the same results as he's book?
I designed a database in microsoft access 2007, and saved it in formats 2007 & 2003. (I have tried both formats in tying to connect the database to VB.net 2005).
I connected the database using the 'add new Date Source' in the Data Source window in Visual Basic.net 2005. In the configuration wizard i selected Database, then i select 'new Connection', chose ' Microsoft Access Database File (OLE DB)' as the data source, then added my database. Tested the connection and then clicked 'next'. I saved a copy of the database, selected the database object i wanted in my dataset. I know have a datasource in Vb. I can view all the table and preview the data in the tables......all looking good.
I then click on the datasource and select 'Details', then drag the datasource over onto my vbform. All the fields are displayed ok. I also have a dataset, a bindingSource, a tableAdapter and a BindingNavigator at the bottom on my vbform.
The problem I have, is when I run the program, I can not display the data in the tables (fields)they are empty.
What part did I do wrong and how can I display the data in the database and display it in the vbForm?
Any help will be much appreciated.
Ian Wells
Ian Wells irwells@hotmail.com
|
|
|
|
|
Does this help?
http://www.vbdotnetheaven.com/UploadFile/mahesh/CreateSQLDatabase04252005064419AM/CreateSQLDatabase.aspx
http://www.connectionstrings.com/
Personally I never use the way you are setting up a connection. I find it shakey.
<br />
ConnectionString = "Provider=" + Provider + "Driver=" + Driver + "Server=" + Server + "; Database=" + DB + "; UID=" + UserName + "; PWD=" + Password + ";Trusted_Connection=yes;"<br />
<br />
queryString = "SELECT Names FROM MYTABLE"<br />
<br />
Try<br />
Using connection As New OdbcConnection(ConnectionString)<br />
Dim command As New OdbcCommand(query, connection)<br />
connection.Open()<br />
<br />
Dim reader As OdbcDataReader = command.ExecuteReader()<br />
<br />
While reader.Read()<br />
StringArray(i) = reader(0).ToString<br />
i += 1<br />
End While<br />
<br />
connection.Close()<br />
reader.Close()<br />
End Using<br />
Catch ex As Exception<br />
<br />
End Try<br />
|
|
|
|
|
hi,
i am designing an application which helps in creating a user account.
the problem i am stuck with is i want the user accounts to be created in there respective OUs but the application is creating the user accounts in default users container.
here is the code that i have written.
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Inclive;
using System.DirectoryServices;
namespace ADHelp
{
///
/// Summary description for Form1.
///
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button CmdClose;
private System.Windows.Forms.Button CmdCreate;
private System.Windows.Forms.TextBox TxtUsername;
private System.Windows.Forms.TextBox TxtDescription;
private System.Windows.Forms.TextBox TxtDomain;
private System.Windows.Forms.TextBox TxtDomainController;
private System.Windows.Forms.TextBox TxtAdminUser;
private System.Windows.Forms.TextBox TxtAdminPassword;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button CmdEnable;
private System.Windows.Forms.Button CmdDisable;
private System.Windows.Forms.Button CmdExists;
private System.Windows.Forms.TextBox TxtUserPassword;
private System.Windows.Forms.TextBox TxtUserGroup;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button CmdPassword;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Button CmdGroup;
private System.Windows.Forms.Label label8;
private LinkLabel lnkWrapper;
private Label label9;
private Label labelDept;
private RadioButton OU1;
private RadioButton OU2;
private RadioButton OU3;
private Label hdrive;
private TextBox TXTHDrive;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.CmdClose = new System.Windows.Forms.Button();
this.CmdCreate = new System.Windows.Forms.Button();
this.TxtUsername = new System.Windows.Forms.TextBox();
this.TxtDomain = new System.Windows.Forms.TextBox();
this.TxtDomainController = new System.Windows.Forms.TextBox();
this.TxtAdminUser = new System.Windows.Forms.TextBox();
this.TxtAdminPassword = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.CmdEnable = new System.Windows.Forms.Button();
this.CmdDisable = new System.Windows.Forms.Button();
this.CmdExists = new System.Windows.Forms.Button();
this.TxtUserPassword = new System.Windows.Forms.TextBox();
this.TxtUserGroup = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.CmdPassword = new System.Windows.Forms.Button();
this.label7 = new System.Windows.Forms.Label();
this.CmdGroup = new System.Windows.Forms.Button();
this.label8 = new System.Windows.Forms.Label();
this.lnkWrapper = new System.Windows.Forms.LinkLabel();
this.label9 = new System.Windows.Forms.Label();
this.TxtDescription = new System.Windows.Forms.TextBox();
this.labelDept = new System.Windows.Forms.Label();
this.OU1 = new System.Windows.Forms.RadioButton();
this.OU2 = new System.Windows.Forms.RadioButton();
this.OU3 = new System.Windows.Forms.RadioButton();
this.hdrive = new System.Windows.Forms.Label();
this.TXTHDrive = new System.Windows.Forms.TextBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// CmdClose
//
this.CmdClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CmdClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.CmdClose.Location = new System.Drawing.Point(232, 366);
this.CmdClose.Name = "CmdClose";
this.CmdClose.Size = new System.Drawing.Size(75, 23);
this.CmdClose.TabIndex = 0;
this.CmdClose.Text = "Close";
this.CmdClose.Click += new System.EventHandler(this.CmdClose_Click);
//
// CmdCreate
//
this.CmdCreate.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.CmdCreate.Location = new System.Drawing.Point(233, 195);
this.CmdCreate.Name = "CmdCreate";
this.CmdCreate.Size = new System.Drawing.Size(75, 23);
this.CmdCreate.TabIndex = 1;
this.CmdCreate.Text = "Create";
this.CmdCreate.Click += new System.EventHandler(this.CmdCreate_Click);
//
// TxtUsername
//
this.TxtUsername.Location = new System.Drawing.Point(88, 195);
this.TxtUsername.Name = "TxtUsername";
this.TxtUsername.Size = new System.Drawing.Size(136, 20);
this.TxtUsername.TabIndex = 2;
//
// TxtDomain
//
this.TxtDomain.Enabled = false;
this.TxtDomain.Location = new System.Drawing.Point(156, 28);
this.TxtDomain.Name = "TxtDomain";
this.TxtDomain.Size = new System.Drawing.Size(128, 20);
this.TxtDomain.TabIndex = 3;
this.TxtDomain.Text = "testing.com";
//
// TxtDomainController
//
this.TxtDomainController.Enabled = false;
this.TxtDomainController.Location = new System.Drawing.Point(156, 56);
this.TxtDomainController.Name = "TxtDomainController";
this.TxtDomainController.Size = new System.Drawing.Size(128, 20);
this.TxtDomainController.TabIndex = 4;
this.TxtDomainController.Text = "192.168.1.3";
//
// TxtAdminUser
//
this.TxtAdminUser.Location = new System.Drawing.Point(156, 84);
this.TxtAdminUser.Name = "TxtAdminUser";
this.TxtAdminUser.Size = new System.Drawing.Size(128, 20);
this.TxtAdminUser.TabIndex = 5;
this.TxtAdminUser.Text = "Administrator";
//
// TxtAdminPassword
//
this.TxtAdminPassword.Location = new System.Drawing.Point(156, 112);
this.TxtAdminPassword.Name = "TxtAdminPassword";
this.TxtAdminPassword.PasswordChar = '*';
this.TxtAdminPassword.Size = new System.Drawing.Size(128, 20);
this.TxtAdminPassword.TabIndex = 6;
this.TxtAdminPassword.Text = "Password";
//
// label1
//
this.label1.Location = new System.Drawing.Point(12, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 16);
this.label1.TabIndex = 7;
this.label1.Text = "Domain Name:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(12, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(148, 16);
this.label2.TabIndex = 8;
this.label2.Text = "Domain Computer Name/IP:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(12, 84);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(136, 16);
this.label3.TabIndex = 9;
this.label3.Text = "Administrator Username:";
//
// label4
//
this.label4.Location = new System.Drawing.Point(12, 112);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(136, 16);
this.label4.TabIndex = 10;
this.label4.Text = "Administrator Password:";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.TxtAdminUser);
this.groupBox1.Controls.Add(this.TxtDomainController);
this.groupBox1.Controls.Add(this.TxtDomain);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.TxtAdminPassword);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox1.Location = new System.Drawing.Point(20, 35);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(296, 144);
this.groupBox1.TabIndex = 11;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Connection Information";
//
// label5
//
this.label5.Location = new System.Drawing.Point(12, 199);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(64, 16);
this.label5.TabIndex = 12;
this.label5.Text = "Username:";
//
// CmdEnable
//
this.CmdEnable.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.CmdEnable.Location = new System.Drawing.Point(233, 281);
this.CmdEnable.Name = "CmdEnable";
this.CmdEnable.Size = new System.Drawing.Size(75, 23);
this.CmdEnable.TabIndex = 13;
this.CmdEnable.Text = "Enable";
this.CmdEnable.Click += new System.EventHandler(this.CmdEnable_Click);
//
// CmdDisable
//
this.CmdDisable.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.CmdDisable.Location = new System.Drawing.Point(233, 310);
this.CmdDisable.Name = "CmdDisable";
this.CmdDisable.Size = new System.Drawing.Size(75, 23);
this.CmdDisable.TabIndex = 16;
this.CmdDisable.Text = "Disable";
this.CmdDisable.Visible = false;
this.CmdDisable.Click += new System.EventHandler(this.CmdDisable_Click);
//
// CmdExists
//
this.CmdExists.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.CmdExists.Location = new System.Drawing.Point(233, 224);
this.CmdExists.Name = "CmdExists";
this.CmdExists.Size = new System.Drawing.Size(75, 23);
this.CmdExists.TabIndex = 17;
this.CmdExists.Text = "Exists";
this.CmdExists.Click += new System.EventHandler(this.CmdExists_Click);
//
// TxtUserPassword
//
this.TxtUserPassword.Location = new System.Drawing.Point(88, 219);
this.TxtUserPassword.Name = "TxtUserPassword";
this.TxtUserPassword.PasswordChar = '*';
this.TxtUserPassword.Size = new System.Drawing.Size(136, 20);
this.TxtUserPassword.TabIndex = 18;
//
// TxtUserGroup
//
this.TxtUserGroup.Enabled = false;
this.TxtUserGroup.Location = new System.Drawing.Point(87, 321);
this.TxtUserGroup.Name = "TxtUserGroup";
this.TxtUserGroup.Size = new System.Drawing.Size(137, 20);
this.TxtUserGroup.TabIndex = 19;
this.TxtUserGroup.Visible = false;
//
// label6
//
this.label6.Location = new System.Drawing.Point(12, 223);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(64, 16);
this.label6.TabIndex = 20;
this.label6.Text = "Password:";
//
// CmdPassword
//
this.CmdPassword.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.CmdPassword.Location = new System.Drawing.Point(233, 252);
this.CmdPassword.Name = "CmdPassword";
this.CmdPassword.Size = new System.Drawing.Size(75, 23);
this.CmdPassword.TabIndex = 21;
this.CmdPassword.Text = "Set Password";
this.CmdPassword.Click += new System.EventHandler(this.CmdPassword_Click);
//
// label7
//
this.label7.Enabled = false;
this.label7.Location = new System.Drawing.Point(9, 325);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(72, 16);
this.label7.TabIndex = 22;
this.label7.Text = "Group Name:";
this.label7.Visible = false;
//
// CmdGroup
//
this.CmdGroup.Enabled = false;
this.CmdGroup.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.CmdGroup.Location = new System.Drawing.Point(233, 339);
this.CmdGroup.Name = "CmdGroup";
this.CmdGroup.Size = new System.Drawing.Size(75, 23);
this.CmdGroup.TabIndex = 23;
this.CmdGroup.Text = "Set Group";
this.CmdGroup.Visible = false;
this.CmdGroup.Click += new System.EventHandler(this.CmdGroup_Click);
//
// label8
//
this.label8.BackColor = System.Drawing.Color.Transparent;
this.label8.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label8.ForeColor = System.Drawing.Color.SaddleBrown;
this.label8.Location = new System.Drawing.Point(16, 8);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(284, 24);
this.label8.TabIndex = 24;
this.label8.Text = "Create User Account";
//
// lnkWrapper
//
this.lnkWrapper.Location = new System.Drawing.Point(-1, 370);
this.lnkWrapper.Name = "lnkWrapper";
this.lnkWrapper.Size = new System.Drawing.Size(144, 20);
this.lnkWrapper.TabIndex = 25;
this.lnkWrapper.TabStop = true;
this.lnkWrapper.Text = "Created by Hitender Yadav";
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(12, 246);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(67, 13);
this.label9.TabIndex = 26;
this.label9.Text = "Employee ID";
//
// TxtDescription
//
this.TxtDescription.Location = new System.Drawing.Point(88, 243);
this.TxtDescription.Name = "TxtDescription";
this.TxtDescription.Size = new System.Drawing.Size(136, 20);
this.TxtDescription.TabIndex = 27;
//
// labelDept
//
this.labelDept.AutoSize = true;
this.labelDept.Location = new System.Drawing.Point(11, 271);
this.labelDept.Name = "labelDept";
this.labelDept.Size = new System.Drawing.Size(62, 13);
this.labelDept.TabIndex = 28;
this.labelDept.Text = "Department";
//
// OU1
//
this.OU1.AutoSize = true;
this.OU1.Location = new System.Drawing.Point(87, 271);
this.OU1.Name = "OU1";
this.OU1.Size = new System.Drawing.Size(46, 17);
this.OU1.TabIndex = 29;
this.OU1.TabStop = true;
this.OU1.Text = "OU1";
this.OU1.UseVisualStyleBackColor = true;
//
// OU2
//
this.OU2.AutoSize = true;
this.OU2.Location = new System.Drawing.Point(137, 271);
this.OU2.Name = "OU2";
this.OU2.Size = new System.Drawing.Size(43, 17);
this.OU2.TabIndex = 30;
this.OU2.TabStop = true;
this.OU2.Text = "OU2";
this.OU2.UseVisualStyleBackColor = true;
//
// OU3
//
this.OU3.AutoSize = true;
this.OU3.Location = new System.Drawing.Point(180, 271);
this.OU3.Name = "OU3";
this.OU3.Size = new System.Drawing.Size(47, 17);
this.OU3.TabIndex = 31;
this.OU3.TabStop = true;
this.OU3.Text = "OU3";
this.OU3.UseVisualStyleBackColor = true;
//
// hdrive
//
this.hdrive.AutoSize = true;
this.hdrive.Location = new System.Drawing.Point(11, 291);
this.hdrive.Name = "hdrive";
this.hdrive.Size = new System.Drawing.Size(63, 13);
this.hdrive.TabIndex = 32;
this.hdrive.Text = "Home Drive";
//
// TXTHDrive
//
this.TXTHDrive.Enabled = false;
this.TXTHDrive.Location = new System.Drawing.Point(88, 293);
this.TXTHDrive.Name = "TXTHDrive";
this.TXTHDrive.Size = new System.Drawing.Size(136, 20);
this.TXTHDrive.TabIndex = 33;
this.TXTHDrive.Text = "\\\\in-ndafs01\\user\\";
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(322, 402);
this.Controls.Add(this.TXTHDrive);
this.Controls.Add(this.hdrive);
this.Controls.Add(this.OU3);
this.Controls.Add(this.OU2);
this.Controls.Add(this.OU1);
this.Controls.Add(this.labelDept);
this.Controls.Add(this.TxtDescription);
this.Controls.Add(this.label9);
this.Controls.Add(this.lnkWrapper);
this.Controls.Add(this.label8);
this.Controls.Add(this.CmdGroup);
this.Controls.Add(this.label7);
this.Controls.Add(this.CmdPassword);
this.Controls.Add(this.label6);
this.Controls.Add(this.TxtUserGroup);
this.Controls.Add(this.TxtUserPassword);
this.Controls.Add(this.CmdExists);
this.Controls.Add(this.CmdDisable);
this.Controls.Add(this.CmdEnable);
this.Controls.Add(this.label5);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.TxtUsername);
this.Controls.Add(this.CmdCreate);
this.Controls.Add(this.CmdClose);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "MainForm";
this.Text = "Create New User Accounts";
this.Load += new System.EventHandler(this.MainForm_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
private void CmdClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void CmdCreate_Click(object sender, System.EventArgs e)
{
if (!this.IsValid())
return;
try
{
DotnetAD.ADAdminUser = this.TxtAdminUser.Text;
DotnetAD.ADAdminPassword = this.TxtAdminPassword.Text;
DotnetAD.ADFullPath = "LDAP://" + this.TxtDomainController.Text;
DotnetAD.ADServer = this.TxtDomain.Text;
DirectoryEntry user = DotnetAD.CreateNewUser(this.TxtUsername.Text);
if (user != null)
{
MessageBox.Show(this, "The user has been created.", "Create User");
user.Close();
user.Dispose();
}
else
MessageBox.Show(this, "Unable to create user.", "Create User");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
DirectoryEntry Description = DotnetAD.SetProperty(Description, "description", TxtDescription.Text);
if (OU1.Select=true)
{
try
{
// Bind to the OU1 container, add a new User.
DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU1,DC=Testing,DC=com");
}
catch (Exception Exception1)
{
// If a COMException is thrown, then the following code example can catch the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
Console.WriteLine(COMEx.ErrorCode);
}
//DirectoryEntry newGroup = de.Children.Add("CN=Sales", "group");newGroup.CommitChanges();
//DirectoryEntry newContact = de.Children.Add("CN=New Contact", "contact");newContact.CommitChanges();
}
if (OU2.Select = true)
{
try
{
// Bind to the OU2 container, add a new User.
DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU2,DC=Testing,DC=com");
}
catch (Exception Exception1)
{
// If a COMException is thrown, then the following code example can catch the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
Console.WriteLine(COMEx.ErrorCode);
}
//try
//{
// DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU2,DC=Testing,DC=com");
//}
}
if (OU3.Select = true)
{
try
{
// Bind to the OU3 container, add a new User.
DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU3,DC=Testing,DC=com");
}
catch (Exception Exception1)
{
// If a COMException is thrown, then the following code example can catch the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
Console.WriteLine(COMEx.ErrorCode);
}
// try
//{
//DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU3,DC=Testing,DC=com");
//}
}
//DirectoryEntry description = DotnetAD.SetProperty(Description,"description",TxtDescription);
}
private bool IsValid()
{
if (this.TxtAdminUser.Text.Length <= 0)
{
MessageBox.Show(this, "Must provide an administrative user to connect with.", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (this.TxtAdminPassword.Text.Length <= 0)
{
MessageBox.Show(this, "Must provide a password for the administrative user.", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (this.TxtDomain.Text.Length <= 0)
{
MessageBox.Show(this, "Must provide a domain name to connect with.", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (this.TxtDomainController.Text.Length <= 0)
{
MessageBox.Show(this, "Must provide the name of the domain controller.", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (this.TxtUsername.Text.Length <= 0)
{
MessageBox.Show(this, "Must provide the username of the user to create/modify.", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
private void CmdEnable_Click(object sender, System.EventArgs e)
{
if (!this.IsValid())
return;
try
{
DotnetAD.ADAdminUser = this.TxtAdminUser.Text;
DotnetAD.ADAdminPassword = this.TxtAdminPassword.Text;
DotnetAD.ADFullPath = "LDAP://" + this.TxtDomainController.Text;
DotnetAD.ADServer = this.TxtDomain.Text;
DotnetAD.EnableUserAccount(this.TxtUsername.Text);
MessageBox.Show(this, "User has been enabled.", "Enable User");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void CmdDisable_Click(object sender, System.EventArgs e)
{
if (!this.IsValid())
return;
try
{
DotnetAD.ADAdminUser = this.TxtAdminUser.Text;
DotnetAD.ADAdminPassword = this.TxtAdminPassword.Text;
DotnetAD.ADFullPath = "LDAP://" + this.TxtDomainController.Text;
DotnetAD.ADServer = this.TxtDomain.Text;
DotnetAD.DisableUserAccount(this.TxtUsername.Text);
MessageBox.Show(this, "User has been disabled.", "Disable User");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void CmdExists_Click(object sender, System.EventArgs e)
{
if (!this.IsValid())
return;
try
{
DotnetAD.ADAdminUser = this.TxtAdminUser.Text;
DotnetAD.ADAdminPassword = this.TxtAdminPassword.Text;
DotnetAD.ADFullPath = "LDAP://" + this.TxtDomainController.Text;
DotnetAD.ADServer = this.TxtDomain.Text;
if (DotnetAD.UserExists(this.TxtUsername.Text))
MessageBox.Show(this, "The user exists.", "User Exists");
else
MessageBox.Show(this, "The user does not exist.", "User Exists");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void CmdPassword_Click(object sender, System.EventArgs e)
{
if (!this.IsValid())
return;
if (this.TxtUserPassword.Text.Length <= 0)
{
MessageBox.Show(this, "Must provide a password for the user.", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
DotnetAD.ADAdminUser = this.TxtAdminUser.Text;
DotnetAD.ADAdminPassword = this.TxtAdminPassword.Text;
DotnetAD.ADFullPath = "LDAP://" + this.TxtDomainController.Text;
DotnetAD.ADServer = this.TxtDomain.Text;
DotnetAD.SetUserPassword(this.TxtUsername.Text, this.TxtUserPassword.Text);
MessageBox.Show(this, "Password has been set.", "Set Password");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void CmdGroup_Click(object sender, System.EventArgs e)
{
if (!this.IsValid())
return;
if (this.TxtUserGroup.Text.Length <= 0)
{
MessageBox.Show(this, "Must provide a group for the user.", "Required Field", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
DotnetAD.ADAdminUser = this.TxtAdminUser.Text;
DotnetAD.ADAdminPassword = this.TxtAdminPassword.Text;
DotnetAD.ADFullPath = "LDAP://" + this.TxtDomainController.Text;
DotnetAD.ADServer = this.TxtDomain.Text;
DotnetAD.AddUserToGroup(this.TxtUsername.Text, this.TxtUserGroup.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void lnkWrapper_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
// Determine which link was clicked within the LinkLabel.
lnkWrapper.Links[lnkWrapper.Links.IndexOf(e.Link)].Visited = false;
// Display the appropriate link based on the value of the
// LinkData property of the Link object.
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
private void MainForm_Load(object sender, System.EventArgs e)
{
this.lnkWrapper.Links.Add(0,this.lnkWrapper.Text.Length,"hyadav@csc.com");
}
}
}
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
Please help me to get this thing done as soon as possible.
Need Help urgently and Badly.
KingPin
|
|
|
|
|
OK. First, read this[^], specifically, point number 4.
Noone is going to read all that code.
Without looking at your code, you're probably opening a connection to the top of a domain controller, and not the OU path that you want the objects created in. I'm willing to bet that your LDAP string looks something like:
LDAP:
Correct??
Open the path you want the objects created in instead:
LDAP:
|
|
|
|
|
i want to implement if condition because i want to get users created in there respective OU.
if you take a look at the following code :
private void CmdCreate_Click(object sender, System.EventArgs e)
{
if (!this.IsValid())
return;
try
{
DotnetAD.ADAdminUser = this.TxtAdminUser.Text;
DotnetAD.ADAdminPassword = this.TxtAdminPassword.Text;
DotnetAD.ADFullPath = "LDAP://" + this.TxtDomainController.Text;
DotnetAD.ADServer = this.TxtDomain.Text;
DirectoryEntry user = DotnetAD.CreateNewUser(this.TxtUsername.Text);
if (user != null)
{
MessageBox.Show(this, "The user has been created.", "Create User");
user.Close();
user.Dispose();
}
else
MessageBox.Show(this, "Unable to create user.", "Create User");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
DirectoryEntry Description = DotnetAD.SetProperty(Description, "description", TxtDescription.Text);
if (OU1.Select=true)
{
try
{
// Bind to the OU1 container, add a new User.
DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU1,DC=Testing,DC=com");
}
catch (Exception Exception1)
{
// If a COMException is thrown, then the following code example can catch the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
Console.WriteLine(COMEx.ErrorCode);
}
//DirectoryEntry newGroup = de.Children.Add("CN=Sales", "group");newGroup.CommitChanges();
//DirectoryEntry newContact = de.Children.Add("CN=New Contact", "contact");newContact.CommitChanges();
}
if (OU2.Select = true)
{
try
{
// Bind to the OU2 container, add a new User.
DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU2,DC=Testing,DC=com");
}
catch (Exception Exception1)
{
// If a COMException is thrown, then the following code example can catch the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
Console.WriteLine(COMEx.ErrorCode);
}
//try
//{
// DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU2,DC=Testing,DC=com");
//}
}
if (OU3.Select = true)
{
try
{
// Bind to the OU3 container, add a new User.
DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU3,DC=Testing,DC=com");
}
catch (Exception Exception1)
{
// If a COMException is thrown, then the following code example can catch the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
System.Runtime.InteropServices.COMException COMEx =
(System.Runtime.InteropServices.COMException)Exception1;
Console.WriteLine(COMEx.ErrorCode);
}
// try
//{
//DirectoryEntry de = new DirectoryEntry("LDAP://CN=OU3,DC=Testing,DC=com");
//}
}
//DirectoryEntry description = DotnetAD.SetProperty(Description,"description",TxtDescription);
this helps in creating a user account, now i am trying to use if condition so that if ou1 or ou2 or ou3 the user should be created in that respective OU.
so please let me know how and what should i change in that code so that the user should get created in there respective OU.
Kingpin
|
|
|
|
|
Hi,
I have an array declared as a structure. The structure has n members.
I was wondering is this posible:
for i = 0 to array(index)
for each object in array(index)
do some work o the member of the stucture...
next
next
This particular code does not work. But you get the idea. My specific problem is that I have n array indexes (array items) and each item of that array has a structure of approxx. 9 members i need to iterate through each of those members and give them some value...
Thank You!
|
|
|
|
|
Something like this should work:
For Each MyStruct struct In MyArray
' Do something with struct
Next
Change MyStruct to whatever your structure type is.
Paul Marfleet
|
|
|
|
|
The description is pretty bad, so anything we say would mearly be guessing. A more accurate description would come from seeing the code defining your structure and the code defining your array.
|
|
|
|
|
How can I know the location of the Application where it is installed. I want to know where in the system 'Microsoft Office Document Imaging' has been installed. It can be installed in different locations in different machines. Is there any API or some kind of functions that can return back the path location to the installed application.
Any advice will help a lot.
Sekhar
|
|
|
|
|
Well, there is the "official way", using the MS Installer API functions, and there is the "quick'n'dirty" method.
The Offical method would be to use the MSI API to lookup the product code of the versions of Office you want to support, then look up the feature to see if it's installed, then get the feature information to get the installation path.
The quick'n'dirty method is to look in the Registry and find the "mspview.exe" key under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrnetVersion\App Paths\ key. If the "mspview.exe" key is there, you can look inside that for the "Path" value, which will give you the path to the Document Viewer executable.
|
|
|
|
|
Thanks Dave for the advice.
One more thing I wanted to know is that Is this the location(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrnetVersion\App Paths) where we can get all the applications that has been loaded to the system ?
That is if I want to know any other application's Path then I have to search it here only ? And how can I access this path from the registry editor ? I used the GetSetting function, but it doesn't seem to work for that location.
Sekhar
|
|
|
|
|
Hi
i have form with some text boxes and grids on it now i want to handle key or shortcuts for save, new etc
at one time you have focus in text box or grid is there any way to trapp the keys for whole form instead of writing code in keypress event of every control separately
plz help
faisal iqbal ch
Love The Process Not The Result, Faiz H Sail
|
|
|
|
|
i think you are looking for mnemonics for buttons on your form as you want that when user is typing in some textbox and press a key and automatically a button pressed for this purpose you should change the caption of button in following way
&Save for save button now from anywhere on a form if user press Alt + S the button Save is pressed and code for its click event is invoked
Salman Sheikh
|
|
|
|
|
Which method is better for data binding (Design Time or Run Time).I have more than 1,00,000 records in the table which I want to show on the form.I this better to bind signle record at a time at run time or load the full table at once at design time.I knowat design time it will slow down the application as it will load the full table.
If I try at run time then how I can move to the next or previous record?
Any idea or sample code will be greatly appriciated.
Thanks In advance.
Ejaz
|
|
|
|
|
ejaz_pk wrote: Which method is better for data binding (Design Time or Run Time).
Neither. Which one you use depends on your requirements.
ejaz_pk wrote: I have more than 1,00,000 records in the table which I want to show on the form.
No, you don't. You have 1,000,000 records in a database, from which you retrieve an appropriate number of for display. Trying to show 1,000,000 records will do nothing but needly slow down the users experience. Holding that many records would also consume a enormous amount of memory.
The only time you'd ever retrieve that many records is if you're doing processing on each and every one of them. You never just retrieve that many "just because I might need them".
It will take a considerable amount of time to retrieve those records if the database is on the same machine as your application, and will take much, much longer if you have to get them over a network.
If you wanted to show that many records, depending on the control used, you would either use a Virtual mode of the control, like in a DataGridView, or implement some kind of paging operation.
ejaz_pk wrote: If I try at run time then how I can move to the next or previous record?
That's what the BindingNavigator class is for.
|
|
|
|
|