Create Windows User in Local Machine

Creating windows users in Local Machine using coldfusion 8 & .Net

Steps to be Followed :

Create a .Net Class Library to Create Windows NT Userccount in local machine using VB as Language

Write a Coldfuusion Entry form to Enter the necessary information to Create the user account

Write a Coldfuusion Action page to call the .Net Method to create the user account in local windows machine

Code Snippets

CFM Code

Entry form Code

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”&gt;
<html xmlns=””&gt;
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Entry Form</title>
Password needs to be given as Pasword policy set in that machine
Paramenter to be passed
First Parameter : Username
Second Parameter : Password
Third Parameter : Description
Fourth Parameter : FullName
Fifth Parameter : Machine name like WinNT://machinenameNote : As this is Just a sample there is no Validation or exception Handling
This Example will work only in Windows OS ....
---><cfform name="Adsample" method="post" action="Act_ADSample.cfm" >
<strong>Username </strong><cfinput required="yes" message="Username Required" name="LclUsername" size="10"><br />
<strong>Password</strong><cfinput required="yes" message="Password Required" name="LclPassword" size="10"><br />
<strong>Description </strong><cfinput required="yes" message="Description Required" name="LclDescription" size="10"><br />
<strong>Full Name</strong><cfinput required="yes" message="Full Name Required" name="LclFullName" size="20"><br />
<strong>Machine name </strong><cfinput required="yes" message="Machine Name Required" name="LclPcName" size="10"><br />
<cfinput type="submit" name="Createuser" value="Create USer">
Actionpage Code
type = "dotnet"
name = "MDBDTable"
class = "ADintegration.ADintegration"
assembly ="d:/Vishnu/ADintegration.dll">#Dummy1#

.Net Code

Imports System.DirectoryServices
Public Class ADintegration
  Dim outputval As String
  Public Function ADuser(ByVal uname As String, ByVal pass As String, ByVal desc As String, ByVal fullname As String, ByVal PCname As String) As String
'First(Parameter) : Username
  'Second(Parameter) : Password
  'Third(Parameter) : Description
  'Fourth(Parameter) : fullname
  'Fourth(Parameter) : PC name : eg: Winnt://Machinename
Dim lblDMBase As String
  lblDMBase = PCname
  REM opens a connection to the local machine. It does not necessarily need to be
  REM the machine the web page is running on.
  Dim adsComputer As New DirectoryEntry(lblDMBase)
  Dim adsUser As DirectoryEntry
  REM Open a connection to the Group
  Dim adsGroup As New DirectoryEntry(lblDMBase & "/Users")
  REM You can also open the object by:
  'Dim adsGroup As DirectoryEntry
  'adsGroup.Path = lblDMBase & "/Users"
  REM Add a user to the defined computer object
  adsUser = adsComputer.Children.Add(uname, "User")
  REM Populate the FullName and Description Properties
  REM Set the password (a random password function would be good here).
  adsUser.Invoke("SetPassword", pass)
  REM Identical to .SetInfo
REM Add the User to the Group
  adsGroup.Invoke("Add", New Object() {adsUser.Path.ToString()})
outputval = "User Created"
  Catch ex As Exception
  outputval = ex.Message.ToString()
  End Try
  Return outputval
  End Function
End Class

.Net and Coldfusion Templates used in this sample can be get from


4 thoughts on “Create Windows User in Local Machine

  1. Pingback: Cheap views

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s