new user in windows

Discussion about the open-source Phalanger [?] project.

new user in windows

Postby nagraj@codeplex » October 17th, 2006, 12:51 pm

hi,

I have a question for you. I want to create an useraccount in windows using phalanger. I am able to create it using php, with help of COM as follows.

$obj = new COM("WinNT://.");
$user = $obj->create("user", "test");
$user->Description = "Usertest using php";
$user->setinfo();

when i used the same with phalanger, i am getting an error reporting couldnot cast system::int32 to system::string
nagraj@codeplex
 
Posts: 24
Joined: January 7th, 2012, 8:55 pm

RE: new user in windows

Postby nagraj@codeplex » October 19th, 2006, 7:12 am

I got the code in C#, can you convert it to phalanger.

using System;
using System.DirectoryServices;

class Class1
{
static void Main(string[] args)
{
try
{
DirectoryEntry AD = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add("TestUser1", "user");
NewUser.Invoke("SetPassword", new object[] #12345Abc);
NewUser.Invoke("Put", new object[] Description", "Test User from .NET);
NewUser.CommitChanges();
DirectoryEntry grp;

grp = AD.Children.Find("Guests", "group");
if (grp != null) {grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
Console.WriteLine("Account Created Successfully");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();

}
}
}

nagraj@codeplex
 
Posts: 24
Joined: January 7th, 2012, 8:55 pm

RE: new user in windows

Postby tomasp » October 22nd, 2006, 1:05 am

Hi nagraj, sorry that it took so long, we've been a bit busy lately. Here is the user creation code rewritten to PHP (I tested it so it should work fine!):

<?php

import namespace System;
import namespace System:::DirectoryServices;

$comp = Environment::$MachineName;
$ad = new DirectoryEntry("WinNT://".$comp.",computer");

$newUser = $ad->Children->Add("TestUser1", "user");
$newUser->Invoke("SetPassword", array("#1234p"));
$newUser->Invoke("Put", array("Description", "Test user from .NET!"));
$newUser->CommitChanges();

$grp = $ad->Children->Find("Guests", "group");
$grp->Invoke("Add", array($newUser->Path));

?>

Tomas
tomasp
 
Posts: 46
Joined: January 7th, 2012, 8:37 pm

RE: new user in windows

Postby nagraj@codeplex » October 25th, 2006, 5:50 am

Thanks for your reply. This code works fine. I have also found alternative way to create an user in windows, by using net.exe

Is there any difference by doing so.
nagraj@codeplex
 
Posts: 24
Joined: January 7th, 2012, 8:55 pm


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 22 guests

cron

User Control Panel

Login

Who is online

In total there are 22 users online :: 0 registered, 0 hidden and 22 guests (based on users active over the past 5 minutes)
Most users ever online was 511 on April 27th, 2024, 10:11 pm

Users browsing this forum: No registered users and 22 guests