cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jarmopy
Level 3

How can I check in InstallScript that a username exists

Hi all,
I only need to check that a specific username is already defined in the installed machine.

Must I check registry or is there some better way to do it ?

Regards
Jarmo
Labels (1)
0 Kudos
(2) Replies
jarmopy
Level 3

I did not found any better solution.
I started "net user" command and redirected output to a temporary file and modified it a little with vbs script and checked if the username exists in that file.

Seems to work :cool:
0 Kudos
ChristopheOce
Level 7

Hi,

Hm i'm not a expert in installshield but for to verify is a user exist you can use the API windows :Netapi32.dll

In one of my basic msi project, i have a dialog with 3 text box :domain, user and password.
People who installs my product can enter a domain\username and password or specify a local user ComputerName\User name and password

when we click on next button i call a function in a dll (dotnet) with some code installscript.
This function return OK or KO and of course i have a condtion on the next button 🙂 if the user exist i call new dialog ReaduToInstall if the user doesn't exist i send a message !

Here is it some code, this function is OK on palteform win 2000, xp, 2003 and vista
[CODE]
//add this using
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.DirectoryServices;

namespace ...
{
//Load the API
[DllImport("Netapi32.dll")]
extern static int NetUserChangePassword([MarshalAs(UnmanagedType.LPWStr)] string domainname,[MarshalAs(UnmanagedType.LPWStr)] string username,[MarshalAs(UnmanagedType.LPWStr)] string oldpassword,[MarshalAs(UnmanagedType.LPWStr)] string newpassword);


//THE METHOD
public string CheckUser(string domain, string username, string password)
{

string valeur;
valeur = "KO";
int ret;

//Function NetUserChangePassword(domain ,user ,password ,new password)
ret = NetUserChangePassword( domain, username, password, password );
if (ret != 0 && ret != 1327 && ret != 2245)
{
valeur = "KO";
//valeur = string.Format("KO - ret = {0} -{1}-{2}-{3}-", ret, domain, username, password);
MessageBox.Show("Return code: " + ret.ToString());
}
else
{
valeur = "OK";
//valeur = string.Format("OK - ret = {0} -{1}-{2}-{3}-", ret, domain, username, password);
MessageBox.Show("Return code: " + ret.ToString());

}
return valeur;
}

....
[/CODE]

and in the basic msi project , installscript code use the function dotnetcocreatobject



//Call the dll with 3 parameters in the sourcedir
set objectUserLogon = DotNetCoCreateObject(szPathCompletDll, "CheckUserLogon.CheckUserLogon", "");

//CALL the method in the dll dotnet
try
szRet = objectUserLogon.CheckUser( szWinDomain, szWinUser, szWinPass );
//MessageBox(szRet, INFORMATION);

if (szRet = "OK") then

//MessageBox("LogonUser successful!", INFORMATION);
MsiSetProperty(hMSI,"MYPROPERTY", "OK");

.....


As you can see , we use the fonction NetUserChangePassword but don't be afraid we don't change the password !

Hope this few sentence help you
Christophe
0 Kudos