473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Creating Local User with Web Service

Hi I am very new to .NET and I am programmatically trying to create a windows
users (not using AD) and am having a little trouble. The OS is 2003 Server
and I am trying to use System.Diagnostics.Process with "net.exe". The
argument does not seem to take, here is the code (this is my first crack at
web services or any real .net project so not sure if this the best way to do
this either - also please do not bash my code again it is my first try):

[WebMethod(Description = "Create Windows User and Custom Group.")]
public string CreateLocalUser(string username, string password)
{
Process MyProc = new Process();
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

try
{
//this is the part that does not work
MyProc.StartInfo.Arguments = @"net.exe user " + username + @" " + password
+ @" /ADD /ACTIVE:YES " +@"/EXPIRES:NEVER /FULLNAME:" + username + @"
/PASSWORDCHG:NO /PASSWORDREQ:YES";
//

MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}
catch(Exception e)
{
Console.WriteLine(e.GetType());
Console.WriteLine(e.Message);
}

return "completed";
}
Mar 24 '06 #1
2 1273
q
Nice job so far... but please make your variables camelCased. It was
rather confusing reading that. I thought you were using static classes
for a minute...

Process MyProc = new Process();

should be

Process myProc = new Process();

Properties, types (i.e. classes), and methods should be PascalCased.

As far as your problem...

If you're doing AD stuff see this video:
http://channel9.msdn.com/Showpost.aspx?postid=132400

Otherwise, your arguments do look rather odd. Try removing the net.exe
from your arguments...

Mar 24 '06 #2
Okay I saw that I had net.exe twice but here is the new code:

Process myProcess = new Process();
myProcess3 = Process.Start("C:\\WINDOWS\\system32\\Net.exe", "user " +
username + " " + password + " /ADD /ACTIVE:YES " + "/EXPIRES:NEVER
/FULLNAME:" + username + " /PASSWORDCHG:NO /PASSWORDREQ:YES");

myProcess.WaitForExit();
myProcess.Close();

It throws no errors but does nothing, how can I make it so I can see what is
happening in the process to debug? Thanks for any help.

"Shannon Thompson" wrote:
Hi I am very new to .NET and I am programmatically trying to create a windows
users (not using AD) and am having a little trouble. The OS is 2003 Server
and I am trying to use System.Diagnostics.Process with "net.exe". The
argument does not seem to take, here is the code (this is my first crack at
web services or any real .net project so not sure if this the best way to do
this either - also please do not bash my code again it is my first try):

[WebMethod(Description = "Create Windows User and Custom Group.")]
public string CreateLocalUser(string username, string password)
{
Process MyProc = new Process();
MyProc.StartInfo.FileName = "net.exe";
MyProc.StartInfo.UseShellExecute = false;
MyProc.StartInfo.RedirectStandardError = true;
MyProc.StartInfo.RedirectStandardInput = true;
MyProc.StartInfo.RedirectStandardOutput = true;
MyProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

try
{
//this is the part that does not work
MyProc.StartInfo.Arguments = @"net.exe user " + username + @" " + password
+ @" /ADD /ACTIVE:YES " +@"/EXPIRES:NEVER /FULLNAME:" + username + @"
/PASSWORDCHG:NO /PASSWORDREQ:YES";
//

MyProc.Start();
MyProc.WaitForExit();
MyProc.Close();
}
catch(Exception e)
{
Console.WriteLine(e.GetType());
Console.WriteLine(e.Message);
}

return "completed";
}

Mar 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rob | last post by:
Hi, I am working on a project that requires a Windows Service which performs the following file transfer functions. 1. It monitors a specific local directory on a Windows 2003 Server. 2. When...
1
by: Al | last post by:
I have a single project that contains 8 different windows services. There is a seperate installation project in the solution for the Windows Services. Both projects build fine with no errors. The...
9
by: Rotzooi | last post by:
Hi, I have a VB.NET Service application that's running fine under the Local System account. But for configuration purposes I don't want to be dependent on modifying the registry manually or...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
3
by: clsmith66 | last post by:
I hope this is just something stupid I'm missing and someone can easily point out my error. I'm trying to do a few turorials on windows services, and the couple I found so far just create an event...
2
by: ABCL | last post by:
Hi All, Can any one tell me that what is the difference between Network Service, Local Service and Local System ACcount for window services ABCL
3
by: SugarDaddy | last post by:
Here's my problem. I have an NT service (really a .NET service) running as local system. I have a .NET form running on the user account. The form and the service communicate via an IPC Channel...
5
by: =?Utf-8?B?cnZhbmdlbGRyb3A=?= | last post by:
Hello, I have a problem with our OnlineBackupService.exe. This is a Windows Service which is built in .Net 1.1 and basically grabs files from the file system and will try to upload them using...
11
by: cj | last post by:
Perhaps someone knows how to do this. When I open a new ASP.NET web service application in VS 2008, it opens with a simple Hello World web service already written. I want to see this work. ...
4
by: sujatha k | last post by:
I want to create one window service to synchronice my local database with server database.i've done the synchronization process in .net application it is working fine. i copied tat code and put it in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.