new user in windows
4 posts
• Page 1 of 1
new user in windows
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
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
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();
}
}
}
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
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
<?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
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.
Is there any difference by doing so.
- nagraj@codeplex
- Posts: 24
- Joined: January 7th, 2012, 8:55 pm
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 22 guests