RobertDangerBond Posted March 1, 2022 Posted March 1, 2022 This is my first post, and I want to acknowledge how extremely valuable this forum has been to me over the past couple of months as I've been learning AutoIt. I'd like to say thanks to all the fantastic people out there who have taken time to provide their help and insight. The issue I'm struggling with is related to admin access on Windows 10, but I don't have enough expertise in this area to understand exactly why it's happening and what I can do about it. Context: I have several VM's that I need to switch between periodically, and I can only run one at a time due to resource limitations. I would love to use AutoIt to streamline opening & closing the connection windows (including logging in, etc.). I am trying to use VMConnect (It's the MSTSC/remote desktop program bundled with Hyper-V). The Issue: I cannot launch VMConnect from within a script due to a permissions issue. When I run this program from the command prompt, it works as long as I'm running "as an administrator." If I am not "as an admin" then I get the same exact error I receive in my script (code and error below): #include <AutoItConstants.au3> #RequireAdmin Func TestVMConnect($sVMName) ; Build the full shell command string Local $sProgram = "VMConnect" Local $sShellCommand = $sProgram & " localhost " & $sVMName ; Get admin credentials Local $sUser = "", $sDomain = "", $sPass = "" GetCredentials($sUser, $sDomain, $sPass) ConsoleWrite("$sShellCommand: " & $sShellCommand & @CRLF) ; Output to console is: "$sShellCommand: VMConnect localhost <VM Name Here>" ; Here it goes >>>>>>>> RunAs($sUser, $sDomain, $sPass, $RUN_LOGON_NOPROFILE, $sShellCommand) ; Error message received via Critical Alert MsgBox: ; Title: Virtual Machine Connection ; Text: "An error occured trying to find the virtual machine '<VM Name Here>' on the computer 'localhost'" ; "You do not have the required permission to complete this task. ; ... Contact the administrator of the authorization policy for the computer 'localhost'." EndFunc Func GetCredentials(ByRef $sUser, ByRef $sDomain, ByRef $sPass) $sUser = "<Admin Username Here>" $sDomain = @ComputerName $sPass = "<Password Here>" EndFunc One solution I've tried is opening a PowerShell "as admin" prompt prior to running my script, then having my script feed it commands using Send() from my script. Although this appears to work--it will open the VMConnect session, sadly it isn't able to interact with the VM at all from my script (i.e. win move(), send(), etc. all have no effect). Bottom line is any admin window open PRIOR to my script starting is fair game--I can interact with it just fine, but if the admin window is opened by my script, I seem to be blocked from all interactions. Is anyone familiar with this who can give some guidance? Thanks!
Developers Jos Posted March 1, 2022 Developers Posted March 1, 2022 Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
RobertDangerBond Posted March 2, 2022 Author Posted March 2, 2022 Nevermind--I got it working, it was my fault. I would delete the post but I don't seem to be able to.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now