主题:runs怎么实现dos下runas自动输入密码
我是一片叶子
[专家分:210] 发布于 2008-06-04 17:44:00
怎么在BAT里自动输入密码
用BAT调用下面这个命令
runas /profile /user:bolt\administrator "net localgroup administrators test /add"
运行该命令后
提示输入ADMIN的密码
请教有什么办法把这个密码也写到BAT文件里让密码自动输入???
如果有兄弟熟悉VBS
用VBS做也一样
怎么实现dos下runas自动输入密码
怎么实现dos下runas自动输入密码
下面是delphi语言的,我想用VB
怎样用ShellExecute调用runas 自动输入密码(如7758),输入密码后自动按回车.
我是刚学delphi的只会写这么多,有没有高手能给出代码
ShellExecute (Handle,nil,'cmd.exe','/C runas /u:admin cmd.exe',nil,SW_HIDE );
用VB编程下,高手你来吧
最后更新于:2008-06-04 17:57:00
回复列表 (共1个回复)
沙发
我是一片叶子 [专家分:210] 发布于 2008-06-04 20:31:00
刚刚搞到的代码,高手呀!!其实我要的很简单就是只有系统用户才可以运行这个我们指定的程序.受限的用户不可以运行.只有通行密码行可以运行!!
Option Explicit
Private Const LOGON_WITH_PROFILE = &H1&
Private Const CREATE_DEFAULT_ERROR_MODE = &H4000000
Private Const CREATE_NEW_CONSOLE = &H10&
Private Const CREATE_NEW_PROCESS_GROUP = &H200&
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Byte
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Declare Function CreateProcessWithLogon Lib "advapi32" Alias "CreateProcessWithLogonW" (ByVal lpUsername As Long, ByVal lpDomain As Long, ByVal lpPassword As Long, ByVal dwLogonFlags As Long, ByVal lpApplicationName As Long, ByVal lpCommandLine As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInfo As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'以下函数用制定名和密码调用了应用程序
Private Function AnShell(Username As String, Domain As String, Password As String, ApplicationName As String) As Long
Dim lpUsername As String, lpDomain As String, lpPassword As String, lpApplicationName As String, lpCommandLine As String, lpCurrentDirectory As String
Dim StartInfo As STARTUPINFO, ProcessInfo As PROCESS_INFORMATION
lpUsername = Username
lpDomain = Domain
lpPassword = Password
lpApplicationName = ApplicationName
lpCommandLine = vbNullString
lpCurrentDirectory = vbNullString
StartInfo.cb = LenB(StartInfo)
StartInfo.dwFlags = 0&
CreateProcessWithLogon StrPtr(lpUsername), StrPtr(lpDomain), StrPtr(lpPassword), LOGON_WITH_PROFILE, StrPtr(lpApplicationName), StrPtr(lpCommandLine), CREATE_DEFAULT_ERROR_MODE Or CREATE_NEW_CONSOLE Or CREATE_NEW_PROCESS_GROUP, ByVal 0&, StrPtr(lpCurrentDirectory), StartInfo, ProcessInfo
CloseHandle ProcessInfo.hThread
CloseHandle ProcessInfo.hProcess
AnShell = ProcessInfo.dwProcessId
End Function
Private Sub Form_Click()
'用刚刚建立的管理员运行一个程序,这里是记事本,参数1为用户名,参数2为域(一般为空就可以了,因为是本机),参数3为要运行的程序路径和名字(这里调用的是WINDOWS下的程序,所以WINDOWS会自己找到的,程序运行时的几个PATH是WINDOWS,SYSTEM,SYSTEM32,APP.PATH,当然可以通过修改WINDOWS的PATH来改变) 请访问:http://www.cnnic-qd.cn/it/index.html
AnShell "administrator", "", "12", "c:\radmin.exe"
End
End Sub
高兴呀,终于搞定呀!!!
我来回复