使用runas命令以VB的管理员帐户身份运行cmd.exe无效 [英] use the runas command to run cmd.exe as admin account from VB doesnt work
问题描述
我有一个MS Access数据库,该数据库具有一些带按钮的按钮,可以执行某些任务-控制台"和控制台".或工具箱".我正在尝试使用此命令以本地管理员身份运行cmd.exe ....
I have an MS access database that has fomrs with buttons to do certain tasks - a "console" or "toolkit". I am trying to run cmd.exe as the local administrator using this command....
调用Shell("C:\ WINDOWS \ system32 \ runas.exe/noprofile/user:administrator cmd.exe")
如果我的域帐户已添加到本地管理员,则工作正常(它要求输入密码-可以解决这个问题吗?)
如果我访问了我不是本地管理员的域中的另一台PC,它将无法正常工作,我也不知道为什么
/>在这两种情况下,我都可以手动浏览到cmd.exe,然后右键单击并以其他用户身份运行而没有任何问题
此外,还有没有更有效的方法来运行此命令?
感谢您的帮助
Call Shell("C:\WINDOWS\system32\runas.exe /noprofile /user:administrator cmd.exe")
If my domain account is added to the local administrators this works fine (it asks for a password - is there any way round this?)
If i visit another PC in the domain on which i am not a local administrator, it doesnt work and i don't know why
In both scenarios i can manually browse to cmd.exe and right click and runas a differnt user without any problems
Also, is there a more efficient way of running this command?
Thanks for any help
推荐答案
尝试使用VB.NET
Try this for VB.NET
Sub RunAdmin(ByVal fileToExecute As String)
Dim process As System.Diagnostics.Process = Nothing
Dim processStartInfo As System.Diagnostics.ProcessStartInfo
processStartInfo = New System.Diagnostics.ProcessStartInfo
processStartInfo.FileName = fileToExecute
processStartInfo.Verb = "runas"
processStartInfo.Arguments = ""
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
processStartInfo.UseShellExecute = True
Try
process = System.Diagnostics.Process.Start(processStartInfo)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
If Not (process Is Nothing) Then
process.Dispose()
End If
End Try
End Sub
kaymaf
这篇关于使用runas命令以VB的管理员帐户身份运行cmd.exe无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!