I have come across an annoying problem with vba code (in MSAccess)
because I am wanting to make the command prompt open admin items like active directory and remote desktop with sign in as password after entering the admin username in a form.
This almost works except for one problem, if the mouse moves off the command window (command.com or cmd.exe) the code for send keys stops working and I am having trouble finding another way around this issue as call shell does not seem to like the amount of code. So please comment if you know a way round this please.
sample code below;
Option Compare Database
Option Explicit
Private Sub cmdUserNameAuckland_Click()
Dim PauseTime, Start, Finish, TotalTime
Dim p As Variant
Dim adminUsername As String
adminUsername = txtUserName
Call Shell("c:\windows\system32\CMD.EXE", vbNormalFocus)
PauseTime = 5 ' Set duration.
Start = Timer ' Set start time.
Do While Timer <>
DoEvents
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
SendKeys "cd c:\", True
SendKeys "{ENTER}", True
SendKeys "runas /user:domainname\", True
SendKeys adminUsername, True
SendKeys " ", True
SendKeys """mmc dsa.msc /server=server""", True
SendKeys "{ENTER}", True
Exit Sub
End Sub
No comments:
Post a Comment