MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Testing Your MSI[Next]: Query MSI Table Data
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->User Creation

User Creation

The following shows how you can create a local user:

;--- Hard coded here but could be properties etc ----------------------------
#define USER_USERID       TestUser
#define USER_PASSWORD     SomePassword
#define USER_FULLNAME     Account required for testing
#define USER_DESCRIPTION  Created by <$ProdInfo.ProductName> version <$ProductVersion>

;--- The custom action ------------------------------------------------------
<$VbsCa Binary="CreateLocalUserAccount.VBS">
   ;--- Initialization ------------------------------------------------------
   const ADS_UF_SCRIPT                                 = &H000001
   const ADS_UF_ACCOUNTDISABLE                         = &H000002
   const ADS_UF_HOMEDIR_REQUIRED                       = &H000008
   const ADS_UF_LOCKOUT                                = &H000010
   const ADS_UF_PASSWD_NOTREQD                         = &H000020
   const ADS_UF_PASSWD_CANT_CHANGE                     = &H000040
   const ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED        = &H000080
   const ADS_UF_TEMP_DUPLICATE_ACCOUNT                 = &H000100
   const ADS_UF_NORMAL_ACCOUNT                         = &H000200
   const ADS_UF_INTERDOMAIN_TRUST_ACCOUNT              = &H000800
   const ADS_UF_WORKSTATION_TRUST_ACCOUNT              = &H001000
   const ADS_UF_SERVER_TRUST_ACCOUNT                   = &H002000
   const ADS_UF_DONT_EXPIRE_PASSWD                     = &H010000
   const ADS_UF_MNS_LOGON_ACCOUNT                      = &H020000
   const ADS_UF_SMARTCARD_REQUIRED                     = &H040000
   const ADS_UF_TRUSTED_FOR_DELEGATION                 = &H080000
   const ADS_UF_NOT_DELEGATED                          = &H100000
   const ADS_UF_USE_DES_KEY_ONLY                       = &H200000
   const ADS_UF_DONT_REQUIRE_PREAUTH                   = &H400000
   const ADS_UF_PASSWORD_EXPIRED                       = &H800000
   const ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION = &H100000
   dim oDomain

   ;--- CREATE USER (Custom Action Entry point) -----------------------------
   <$VbsCaEntry "UserCreate">
       ;--- Get object to local computer ------------------------------------
       GetDomainObject()

       ;--- Make sure the user doesn't already exist! -----------------------
       DeleteUserIgnoreErrors()

       ;--- Create a new user -----------------------------------------------
       dim oUser, UserFlags
       CaDebug 0, "Creating user: <$USER_USERID>."
       set oUser   = oDomain.Create("user", "<$USER_USERID>")
           ;--- Basic properties --------------------------------------------
           oUser.put "FullName"   , "<$USER_FULLNAME>"
           oUser.put "Description", "<$USER_DESCRIPTION>"
           oUser.SetPassword        "<$USER_PASSWORD>"

           ;--- User attributes ---------------------------------------------
           oUser.SetInfo                    'Required!
           UserFlags = oUser.Get("UserFlags")
           CaDebug 0, "User Flags BEFORE = 0x" & hex(UserFlags)
           UserFlags = UserFlags or ADS_UF_DONT_EXPIRE_PASSWD or ADS_UF_PASSWD_CANT_CHANGE
           oUser.Put "UserFlags", UserFlags
           CaDebug 0, "User Flags AFTER  = 0x" & hex(UserFlags)
       oUser.SetInfo
   <$/VbsCaEntry>

   ;--- DELETE USER (Custom Action Entry point) -----------------------------
   <$VbsCaEntry "UserDelete">
       ;--- Get object to local computer ------------------------------------
       GetDomainObject()

       ;--- Make sure the user doesn't already exist! -----------------------
       DeleteUserIgnoreErrors()
   <$/VbsCaEntry>

   <?NewLine>
   '===========================================
   sub GetDomainObject()
   '===========================================
       ;--- Create object to local box --------------------------------------
       dim Where : Where = "WinNT://" & VbsCaPropertyGet("ComputerName", "<??*COMPUTERNAME>", "")
       CaDebug 0, "Getting object: " & Where
       set oDomain = GetObject(Where)
   end sub

   <?NewLine>
   '===========================================
   sub DeleteUserIgnoreErrors()
   '===========================================
       on error resume next
       CaDebug 0, "Deleting user: <$USER_USERID>"
       oDomain.Delete "user", "<$USER_USERID>"
       CaDebug 0, "   RC : " & err.number & " - " & err.description
   end sub
<$/VbsCa>
<$VbsCaSetup Type="IMMEDIATE" Binary="CreateLocalUserAccount.VBS" Entry="UserCreate" Seq="<-CreateFolders" CONDITION=^<$CONDITION_EXCEPT_UNINSTALL>^>


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Testing Your MSI[Next]: Query MSI Table Data


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday August 13 2017 at 2:39pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.