|
s3rro wrote: Private Sub Form_Load()
You have to change its structure like this:
Private Sub Form_Load(sender as Object,e as System.EventArgs) handles MyBase.Load
'Additional Code here
End Sub
Hope it helps !
AliAmjad(MCP)
|
|
|
|
|
|
I am in the final throws of my development for an app so I have started my testing.
One of my scenarios is a the removal of the SQL Native Client driver (Windows XP). After the uninstall, I attempt to run the app and am always presented with this error message, which is expected as the native client was required.
The problem I have is that I did not write in a message box to display this error!
I've searched through the code to find a rouge msgbox but found nothing that would present this error.
Any suggestions to suppress this so I can present something more friendly?
Here's how i create connection, if needed
<br />
<br />
Try<br />
Using connection As New OdbcConnection(ConnectionString)<br />
Dim command As New OdbcCommand(queryString, connection)<br />
connection.Open()<br />
<br />
Dim reader As OdbcDataReader = command.ExecuteReader()<br />
<br />
While reader.Read()<br />
count = reader(0).ToString<br />
End While<br />
<br />
connection.Close()<br />
reader.Close()<br />
End Using<br />
Catch ex As Exception<br />
SQLERROR = True<br />
WriteErrorLog(ex.ToString)<br />
Exit Sub<br />
<br />
End Try<br />
|
|
|
|
|
I think this is an unhandled exception error message try to use this code to handle it:
Dim withevents ap as AppDomain
Private Sub ap_UnhandledException(ByVal sender As Object, ByVal e As System.UnhandledExceptionEventArgs) Handles ap.UnhandledException
'Additional Code
End Sub
hope it helps !
AliAmjad(MCP)
|
|
|
|
|
Exactly what it was! Thanks for letting me know, YTMND!
|
|
|
|
|
??? I wasn't letting u know that Its an unhandled exception but rather tried to give you the solution.
AliAmjad(MCP)
|
|
|
|
|
If you're running on SQL Server, why are you bothering with the ODBC provider?? It's slower and doesn't use any features or optimizations that are specific to using SQL Server.
|
|
|
|
|
Its the only way i know how to do it programmatically...
|
|
|
|
|
It's not very different from what you already have. You're just using the OdbcXXX classes instead of the SqlXXXX set of classes.
|
|
|
|
|
After I finished converting(with visual studio 2005 automatic convertor) a windows application written in vb.net 2002 to vb.net 2005
I recieved few syntax errors that I did not find a sulution for them yet.
The first one is:
The error line - If TypeOf Me.WorkingTable.Column(i).DataType is Boolean Then
The error message- Expression of type 'system.Type' can never be of type 'Boolean'.
finally worked like this:
If Me.WorkingTable.Columns(i).DataType is GetType(Boolean) Then
-- modified at 12:25 Wednesday 31st October, 2007
|
|
|
|
|
Hi all...
I am using the following code: Shell("cmd.exe /c cscript C:\Projects\TEST\FileMonitor.vbs", AppWinStyle.Hide, True, -1) in vb.net
Now... the FileMonitor.vbs section is a vbscript file that contains code to monitor a folder for any new file creations... when it gets the file i can have cmd prompt display the filepath\filename. Is it possible to send this filename\filepath back to vb.net as i run the Shell("cmd.exe /c cscript C:\Projects\TEST\FileMonitor.vbs", AppWinStyle.Hide, True, -1) in vb.net??? I want add this filename into a variable.
Thank you in advance.
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Would it be possible to have the VBS write the filepath/filename to a textfile and then just have the VB app read that?
|
|
|
|
|
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
|
|
|
|
|