1. Script: You can search "create a new user in a Domain with WSH" in google. Here is a sample: This VBScript program uses the ActiveX Directory Service Interface (ADSI) to create a new user in a Domain or on a Workstation. During the processing of the script the state will be shown in dialog boxes. If no user interaction is detected these dialog boxes will be closed automatically after 10 seconds. The script writes also a record into the log file C:\NewUserLog.txt, reporting either the success or the failure of this operation. This allows an unattended execution.The purpose of this script is to demonstrate how to write a script which:shows dialogs which will be closed without user interactions. demonstrates the use of ADSI to create a new user demonstrates how to record script actions into a log file '************************************************ ' File: WSHADSICreateUser.vbs (WSH sample in VBScript) ' Author: Günter Born ' ' Uses ADSI to create a new user in Windows NT. ' Also creates/updates a log file allowing an ' unattended use of this script. ' ' In no way shall the author be liable for any ' losses or damages resulting from the use of this ' program. Use AS-IS at your own risk. ' ' The code is the property of the author. You may ' use the code and modify it, as far as this header ' remains intact. Further updates and other samples ' may be found on my site: ' http://www.borncity.de '************************************************ Option Explicit On Error Resume Next DIM WshShell, objDomain, objUser DIM name, fullname, descript, passw DIM server, title, datimedatime = "[" & date & " " & time & "] " server = "//Wien" name = "Bill" fullname = "Bill Brown" descript = "My favorite user" passw = "Gateway"title = "WSH sample - by Günter Born"Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Popup "Create new user " & name, 5, title, vbOKonlySet objDomain = GetObject("WinNT:" & server) If err.number <> 0 Then AddLog (datime & "*** Error: " & err.number & _ " ADSI not supported on " & server)WshShell.Popup "*** Error: " & err.number & _ " ADSI not supported on " & server, 10, _ title, vbOKonlyWScript.Quit ' Sorry, that's the end ... End if' Now we try to create the user object and set the properties Set objUser = objDomain.Create("user", name) objUser.Description = descript objUser.FullName = fullnameobjUser.SetInfo ' Store settings If err.number = 0 Then ' Success? ' Yes, add record to logfile AddLog datime & "User " & user & " created on " & server ' Inform user with a short message (20 seconds) WshShell.Popup "User " & name & " created", 10, title, vbOKonlyElse ' some problem ### If err.number = -2147022672 then ' User exists, Add error into logfile AddLog datime & "*** Error: User " & name & " already exists" ' Inform user with a short message (20 seconds) WshShell.Popup "*** Error: User " & name & " already exists", _ 10, title, vbOKonly Else ' Add error into logfile AddLog datime & "*** Error: " & err.number & _ " could not create user " & name ' Inform user with a short message (20 seconds) WshShell.Popup "*** Error: " & err.number & _ " could not create user " & name, 10, title, vbOKonly End if End ifSet objUser = Nothing Set objDomain = Nothing'#### Helpers ##### Sub AddLog (txt) ' Add a record to the logfile Const file1 = "C:\NewUserLog.txt" ' Log file name Const ForAppending = 8 ' Append mode Dim fso, fi ' object variable ' Creates a FileSystemObject object Set fso = CreateObject("Scripting.FileSystemObject")' open file, force create, if not exists Set fi = fso.OpenTextFile(file1, ForAppending, true)fi.WriteLine (txt) ' append log Set fi = Nothing End Sub '*** End
2. Java: Runtime.getRuntime().exec("cuid.vbs");
感谢,怎么在调用这个vbs的时候传参数呢? 我会结帖给分的。
I do not know how to pass a parameter to a vbs file , but I know it must can be. try the google search. otherwise, you can use java code to write the user account in a text file , then vbs file to open the file and add the user account.hope help
用vb或者vc写一个com组件,再用java 调用
其实很简单。 Runtime.exec("exe file name"); 下面是从http://forum.java.sun.com/上查到的,有什么问题在那也能得到回答。This topic has 1 reply on 1 page (Most recent message: Aug 20, 2000 9:06 AM) How to Execute another program .exe or .bat in java Author: ali_h_a Aug 19, 2000 9:20 PM
Hi My question is . How can I execute another prog like MS.Word or another exe progs.. or .bat files and so on in vb there is Shell statement is there anything like that in java. send answers at [email protected] Thank Greetings How to Execute another program .exe or .bat in java Author: JavaBug In Reply To: How to Execute another program .exe or .bat in java Aug 20, 2000 2:06 AM Reply 1 of 1
yo ali salaam, use Runtime.exec("exe file name"); to run the exe, is u want to run shell scripts as in .bat files u have to run Runtime.exec("command batfilename");
Then use java to shell this file.
具体可以参见windows自己的Help,
Search "net user"adduser.bat
/***
net user testuser testuer /add
***/
如果bat文件里写的是dir之类的话,就执行不了,如果bat里是执行一个exe文件还可以。
Script:
You can search "create a new user in a Domain with WSH" in google.
Here is a sample:
This VBScript program uses the ActiveX Directory Service Interface (ADSI) to create a new user in a Domain or on a Workstation. During the processing of the script the state will be shown in dialog boxes. If no user interaction is detected these dialog boxes will be closed automatically after 10 seconds. The script writes also a record into the log file C:\NewUserLog.txt, reporting either the success or the failure of this operation. This allows an unattended execution.The purpose of this script is to demonstrate how to write a script which:shows dialogs which will be closed without user interactions.
demonstrates the use of ADSI to create a new user
demonstrates how to record script actions into a log file
'************************************************
' File: WSHADSICreateUser.vbs (WSH sample in VBScript)
' Author: Günter Born
'
' Uses ADSI to create a new user in Windows NT.
' Also creates/updates a log file allowing an
' unattended use of this script.
'
' In no way shall the author be liable for any
' losses or damages resulting from the use of this
' program. Use AS-IS at your own risk.
'
' The code is the property of the author. You may
' use the code and modify it, as far as this header
' remains intact. Further updates and other samples
' may be found on my site:
' http://www.borncity.de
'************************************************
Option Explicit
On Error Resume Next
DIM WshShell, objDomain, objUser
DIM name, fullname, descript, passw
DIM server, title, datimedatime = "[" & date & " " & time & "] "
server = "//Wien"
name = "Bill"
fullname = "Bill Brown"
descript = "My favorite user"
passw = "Gateway"title = "WSH sample - by Günter Born"Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Popup "Create new user " & name, 5, title, vbOKonlySet objDomain = GetObject("WinNT:" & server)
If err.number <> 0 Then
AddLog (datime & "*** Error: " & err.number & _
" ADSI not supported on " & server)WshShell.Popup "*** Error: " & err.number & _
" ADSI not supported on " & server, 10, _
title, vbOKonlyWScript.Quit ' Sorry, that's the end ...
End if' Now we try to create the user object and set the properties
Set objUser = objDomain.Create("user", name)
objUser.Description = descript
objUser.FullName = fullnameobjUser.SetInfo ' Store settings
If err.number = 0 Then ' Success?
' Yes, add record to logfile
AddLog datime & "User " & user & " created on " & server
' Inform user with a short message (20 seconds)
WshShell.Popup "User " & name & " created", 10, title, vbOKonlyElse ' some problem ###
If err.number = -2147022672 then
' User exists, Add error into logfile
AddLog datime & "*** Error: User " & name & " already exists"
' Inform user with a short message (20 seconds)
WshShell.Popup "*** Error: User " & name & " already exists", _
10, title, vbOKonly
Else
' Add error into logfile
AddLog datime & "*** Error: " & err.number & _
" could not create user " & name
' Inform user with a short message (20 seconds)
WshShell.Popup "*** Error: " & err.number & _
" could not create user " & name, 10, title, vbOKonly
End if
End ifSet objUser = Nothing
Set objDomain = Nothing'#### Helpers #####
Sub AddLog (txt)
' Add a record to the logfile
Const file1 = "C:\NewUserLog.txt" ' Log file name
Const ForAppending = 8 ' Append mode
Dim fso, fi ' object variable
' Creates a FileSystemObject object
Set fso = CreateObject("Scripting.FileSystemObject")' open file, force create, if not exists
Set fi = fso.OpenTextFile(file1, ForAppending, true)fi.WriteLine (txt) ' append log
Set fi = Nothing
End Sub
'*** End
2.
Java:
Runtime.getRuntime().exec("cuid.vbs");
我会结帖给分的。
otherwise, you can use java code to write the user account in a text file , then vbs file to open the file and add the user account.hope help
其实很简单。
Runtime.exec("exe file name");
下面是从http://forum.java.sun.com/上查到的,有什么问题在那也能得到回答。This topic has 1 reply on 1 page (Most recent message: Aug 20, 2000 9:06 AM)
How to Execute another program .exe or .bat in java
Author: ali_h_a Aug 19, 2000 9:20 PM
Hi
My question is . How can I execute another prog like MS.Word or
another exe progs.. or .bat files and so on
in vb there is Shell statement is there anything like that in
java.
send answers at [email protected]
Thank
Greetings
How to Execute another program .exe or .bat in java
Author: JavaBug
In Reply To: How to Execute another program .exe or .bat in java Aug 20, 2000 2:06 AM Reply 1 of 1
yo ali salaam,
use
Runtime.exec("exe file name"); to run the exe,
is u want to run shell scripts as in .bat files u have to run
Runtime.exec("command batfilename");