Madmaxim Posted August 22, 2019 Posted August 22, 2019 Hi. Would anyone share a hint as to why i'm not able to script a Windows batch (Admin permission) ? This below command (or batch, when included in it) is running perfectly OK. Goal: compile a specific dos batch to an .EXE Why: .EXE would be whitelisted for use internally as "pre-elevated". Windows batch: FOR /F "skip=1 tokens=3" %s IN ('query user %USERNAME%') DO (%windir%\System32\tscon.exe %s /dest:console) Source: https://forum.uipath.com/t/uirobot-run-in-remote-desktop/53880/12 Note: Double percentage replaces % when being run through batch (externally). Tried with not luck - RunWait (running @comspec and the command) - preferred ShellExecute (calling a dos batch) - not preferred Run (calling cmd.exe and sending the command) - not preferred, last resort option Result - When running the batch (double %% require for both items) as elevated, works OK When running the line in elevated commandline (single % for both items), works OK Yet, i'm unable to run it as an AutoIT binary, which reports it doesn't know what the 'query is. Thanks.
Developers Jos Posted August 22, 2019 Developers Posted August 22, 2019 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. 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.
Developers Jos Posted August 22, 2019 Developers Posted August 22, 2019 ... I would think it would help when you share the code that isn't working. Jos 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.
Madmaxim Posted August 22, 2019 Author Posted August 22, 2019 #RequireAdmin #include <AutoItConstants.au3> #include <MsgBoxConstants Using @comspec One of these variables first - $batch = " %%s in ('query user %USERNAME%') do (%windir%\System32\tscon.exe %%s /dest:console)" $batch = "FOR /F " & Chr(34) & "skip=1 tokens=3" & chr(34) & " %%s IN ('query user %USERNAME%') DO (%windir%\System32\tscon.exe %%s /dest:console)" $batch = "FOR /F " & Chr(34) & "skip=1 tokens=3" & chr(34) & " %s IN ('query user %USERNAME%') DO (%windir%\System32\tscon.exe %s /dest:console)" $batch = " FOR /F " & Chr(34) & "skip=1 tokens=3" & chr(34) & " %s IN ('query user %USERNAME%') DO (%windir%\System32\tscon.exe %s /dest:console)" $batch = "FOR /F " & Chr(34) & "skip=1 tokens=3" & chr(34) & " %s IN (" & chr(39) & "query user %USERNAME%" & chr(39) & ") DO (%windir%\System32\tscon.exe %s /dest:console)" $batch = "FOR /F " & Chr(34) & "skip=1 tokens=3" & chr(34) & " %s IN (" & chr(39) & "query user " & @UserName & chr(39) & ") DO (%windir%\System32\tscon.exe %s /dest:console)" $batch = "FOR /F " & Chr(34) & "skip=1 tokens=3" & chr(34) & " %s IN ('query user " & @UserName & "') DO (%windir%\System32\tscon.exe %s /dest:console)" $batch = "FOR /F " & '"skip=1 tokens=3"' & " %s IN ('query user " & @UserName & "') DO (%windir%\System32\tscon.exe %s /dest:console)" $batch = "FOR /F " & '"skip=1 tokens=3"' & " %s IN ('query user %USERNAME%') DO (%windir%\System32\tscon.exe %s /dest:console)" Then run it with compspec local $Proc1 = RunWait(@ComSpec & " /c " & $batch,@ScriptDir,@SW_show,$STDERR_CHILD + $STDOUT_CHILD) or Directly without variable - local $Proc1 = RunWait(@ComSpec & " /q /c " & "for /f ""skip=1 tokens=3"" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console)",@ScriptDir,@SW_HIDE) Calling batch (last resort) run(@ScriptDir & "\" & "Disconnect RDC.bat",@ScriptDir,@sw_hide) or ShellExecute("cmd.exe", "/k Disconnect RDC.bat " & @ComSpec & " /k", @ScriptDir) Getting the result / error is getting troubles When running @comspec even with /k I have no luck seeing the result / error. Tried getting the result to external file, but apart from the manual written text, it didn't printed the contents of the STDOUT. ProcessWaitClose($proc1) $sOutput = StdoutRead($Proc1) FileOpen($LogFile, $FO_APPEND) FileWrite($LogFile, "Proc1 = " & @CRLF & $sOutput & @crlf) FileClose($LogFile)
seadoggie01 Posted August 22, 2019 Posted August 22, 2019 Please, use the code tags! It's incredibly hard to read the code without them. I can't read batch files to tell you if something is wrong there, but I would run the batch and pipe the output to a log file (with "> log.txt" in the command). All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Neutro Posted August 22, 2019 Posted August 22, 2019 Hi and welcome Trying to convert a batch to autoit is a bad idea. Instead explain to us what you're trying to achieve and we will be able to guide you to the right tools you need to do it with autoit Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water!
Madmaxim Posted August 22, 2019 Author Posted August 22, 2019 This Windows command should be compiled to an .exe, that the contents is locked and the .exe as such could be fingerprinted (checksum). When running this command from batch, it needs to have one more % in both variables, ie. %%s FOR /F "skip=1 tokens=3" %s IN ('query user %USERNAME%') DO (%windir%\System32\tscon.exe %s /dest:console)
Neutro Posted August 22, 2019 Posted August 22, 2019 (edited) Code is just a way to reach a goal. You keep posting code without explaining what do you want to do You need to explain us what do you want to do, without using code, before we can help you For now it's like you say to us that you have some ingredients to cook a meal and you need help but you still didn't tell us what meal you're cooking 😁 Edited August 22, 2019 by Neutro Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water!
Madmaxim Posted August 22, 2019 Author Posted August 22, 2019 Disconnect Remote Desktop session whilst leaving the GUI on the terminal think that is only locked screen. This command moves current user to console state on the terminal that the interactive tasks can continue running on it.
Neutro Posted August 22, 2019 Posted August 22, 2019 (edited) OK but why do you have to do that? Why can't you just use a normal Windows session instead of using remote desktop? And what's the software with the "interactive task" that needs to continue running? Are you not the administrator of this server? You need to be more specific! Edited August 22, 2019 by Neutro Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water!
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