How can i make VBScript work in ASP.net ??

Im new to VBscript and trying to create a User & email in my AD through a VBscript using ASP.net. In addition, I want to make the username and names Dynamic, meaning that the user will be able to type out the name he wants. Moreover, im trying to trigger the Vbscript when the user Clicks a Submit Button.

Note: Im using ASP.net Visual Studio 2005.

this is the VBscript Code:


Const UF_SCRIPT = &H1
Const UF_ACCOUNTDISABLE = &H2
Const UF_HOMEDIR_REQUIRED = &H8
Const UF_LOCKOUT = &H10
Const UF_DONT_EXPIRE_PASSWD = &H10000
Const UF_PASSWORD_CANT_CHANGE = &H40

Dim objDomain, objUser, objGroup, intUserFlags, intNewUserFlags

Dim username, firstname, lastnames, Defaultcn, OUcontainer, OUType, group

' PARAMTERES MUST BE PASSED

username="testme"
firstname="Amer"           <==== all those parameters must be entered by the User from the ASP.net Form and then passed to the VBscript.
lastnames="Bin Test"
group = "grouptest"
fullname= firstname & " " & lastnames


Defaultcn    = "Users"
OUcontainer  = "UsersDirectory"
OUType = "StandardUsers"


Set objDomain = GetObject("LDAP://cn=" & Defaultcn & ",dc=MyDomain,dc=com")
Set objUser = objDomain.Create("user","cn=" & fullname)
objUser.Put "sAMAccountName", username
objUser.Put "userPrincipalName", username & "@MyDomain.com"
objUser.SetInfo
objUser.GetInfo

Thanks, I really appreciate your help.
amersharafAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GavinMannionCommented:
You would want to put all of this in your codebehind. asp.net works very differently from old asp so I would not even try converting your old code. Rather rewrite it in the new way.

Take a look at these articles on how to admin AD from asp.net

http://www.15seconds.com/issue/020730.htm
http://www.asptoday.com/Content.aspx?id=1934
http://www.123aspx.com/redir.aspx?res=29213

0
amersharafAuthor Commented:
Im not sure if i explained the situation clearly.

What im trying to do here is:

1- I have a working VBscript File.
1- I want to Paste the VBscript in ASP.net(or just execute the file from ASP.net) and create a Form.
2- Make the User enter some Values.
3- Toss the values back to the VBscript File.
4- when the User Clicks Submit, the VBscript file is executed.

I forgot to mention that the VBscript File works perfectly when executed outside of ASP.net.

I hope this clears any confusions.
0
GavinMannionCommented:
I would advise against it unless someone else knows how to protect that file. Using ASP.NET you have a lot more security on your application.

If you just pass the variables to a vbscript file to execute then someone can quite easily just call the vbscript file na dpass any variables they want creating as many users as they like without you being able to stop them.

What I would do is create a ASP.Net web form with all the textboxes you require and a button.

On button click rewrite the vbscript code into the codebehind and execute it there.

THis way you have complete control over who and when that code gets executed.

The links i posted explain how you create the AD interface and use it from there.
If someone else has some more experience in doing this please feel free to jump in. My knowledge on this is only theoretical.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

MohamedZakiCommented:
I do Agree with GavinMannion, and in addition to what he said, you should consider that the VBScript is client side code which means it will be executed on the users machine - which may be not connected to your domain directly - so you should run your code through server-side code,other possible solution is to make your vbscript a COM component (with some minor efforts) and call this component from your ASP.NET code and pass to it the parameters you need.
0
amersharafAuthor Commented:
GavinMannion, how can i do as what you suggested ? I tried rewriting the code, but it seems that the VBscript code doesnt get executed. and i dont know how to pass parameters to the vbscript from the code-behind.

Bedies, I forgot to mention that I'll be using the Form and VBscript on my Intranet, so security is not a big concern to me.
0
GavinMannionCommented:
If you have rewritten it into the codebehind then to pass the variables you would do something along the lines of

string username= txtUserName.Text
string firstname= txtFirstName.Text           <==== all those parameters must be entered by the User from the ASP.net Form and then

Even though the form is on the intranet only it doesn't mean someone in the company won't abuse it. Most hacking attacks and destructive actions come from inside your own company.

If you want you can paste your rewritten code into this thread and someone can point out where you are going wrong.
0
MohamedZakiCommented:
AmerSharaf,
if you will rewrite the code, then check this code snippet, it's a sample to how to create a user on the domain in the .NET using DirectoryServices, wish it helps

P.S. the code is from this article ( http://blogs.msdn.com/federaldev/articles/472935.aspx )



namespace ADUserManager
{

    class Program

    {

        static void Main(string[] args)

        {

            string userName="John Smith", sAMAccountName="JSmith", passWord="SomeThingCkrit";

            // Step #1

            // Instantiate a Directory Entry Object to represent the User folder

            DirectoryEntry adUserFolder = new DirectoryEntry("LDAP://CN=Users,DC=RSLAB,DC=Local");

 

            // Step #2

            // Check to make sure the folder is a container object

            if (adUserFolder.SchemaEntry.Name == "container")

            {

                // Step #3

                // Create a Directory Entry Object to represent the user

                DirectoryEntry newADUser = adUserFolder.Children.Add("CN=John Smith", "User");

 

                // Step #4

                // Check to see if there is already someone in the folder with that name (CN)

                // If so, delete that account first

                if(DirectoryEntry.Exists(newADUser.Path))

                {

                    Console.WriteLine("The user: " + userName + " already exists.  The Account will be Overwritten!");

 

                    // Step 4a: Remove the user object first

                    adUserFolder.Children.Remove(new DirectoryEntry(newADUser.Path));

                }

 

                //  Step 5: Add the user optional and required properties (sAMAccountName is ALWAYS REQUIRED!!)

                newADUser.Properties["sAMAccountName"].Add(sAMAccountName);

 

                //  Step 6: Commit the changes to the AD data store

                newADUser.CommitChanges();

 

                //  Step 7: Set the password for the new account, which can only be done AFTER the account exists!

                //          We are using the "Invoke" method on the newADUser object, which uses Native AD Object under the hood to set

                //          the password.  

                newADUser.Invoke("setPassword", passWord);

 

                //  Step 8: Enable the user, if the user wants to, by setting the userAccountControl property

                //          to the magical value of 0x0200.  The disable-user value is 0x0002

                newADUser.Properties["userAccountControl"].Value = 0x0200;

                newADUser.CommitChanges();

 

                Console.WriteLine("User: " + userName + " successfully created!");

                Console.WriteLine("Hit any key to end...");

                Console.ReadLine();

            }

 

        }

    }

}

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.