Baboo85

Send multiple commands line in a CMD window

3 posts in this topic

#1 ·  Posted (edited)

Hi all,

I need to start a script that include:

- admin privileges

- multiple cmd commands

- no bat, no exe, no tmp files created anywhere (especially in the user temp folder)

In a bat file it would be simple, but users shouldn't see what commands I'm sending.

Example of the script:

echo off
cls
echo.
echo I AM A TOOL
echo.
echo NOTE:
echo - note 1
echo - note 2
echo - etc
set USER1=0
set COMPUTER1=0
if /i %username% equ user.user (
set USER1=1
set COMPUTER1=1 )
if /i %username% equ another.user set USER1=1
if /i %computername% equ notebook set COMPUTER1=1
if %USER1% EQU 1 ( 
if %COMPUTER1% EQU 1 (
reg delete "HKLM\SOFTWARE\blablabla" /f
) else ( echo Computer not authorized. Contact assistance.)
) else ( echo User not authorized. Contact assistance.)
echo.
pause
exit

With the send("") is a disaster.

I'm a noob here, so what can I do?

 

EDIT: OR ELSE I explain the situation and what I need, so if there is a simple solution I can use that.

 

SITUATION: our domain users have Users rights on the machine. Some of them need administrator rights.

We create a local user with administrator rights, so that the users must insert username and password when asked to run something with administrator rights.

We have an internal domain group policy that blocks EXE, BAT, COM, TMP files from the user local temp directory, for a security reason (malware). That also blocks most software installation.

But some users are often out of office, away from workplace and in another country, they need a complete control on their computers.

 

WHAT I NEED: I need to check the username and the computer name. If the username is the one with local administrator rights and the computer name is a computer that is qualified to temporary remove the policy, then I need to execute a REG DELETE command with administrator rights.

 

I hope I explained myself.

 

Thank you very much.

Edited by Baboo85

Share this post


Link to post
Share on other sites



#2 ·  Posted

Maybe something like:

;~ AdminInfo.ini
;~ [UserName]
;~ Username = Firstname Lastname
;~ [ComputerName]
;~ ComputerName = Domain

#NoTrayIcon
#include <Array.au3>
Global $bUserName = False, $bComputerName = False
Global $sErrorMsg = ""
Global $sAdminInfo = @ScriptDir & "\AdminInfo.ini"
    If FileExists($sAdminInfo) = 0 Then Exit

Global $aUserName = IniReadSection($sAdminInfo, "UserName")
    If @error Then Exit
If _ArraySearch($aUserName, @UserName, 0, 0, 0, 0, 1, 0) > 0 Then $bUserName = True

Global $aComputerName = IniReadSection($sAdminInfo, "ComputerName")
    If @error Then Exit
If _ArraySearch($aComputerName, @ComputerName, 0, 0, 0, 0, 1, 0) > 0 Then $bComputerName = True

MsgBox(0,'', "Username: " & $bUserName & @CRLF & "ComputerName: " & $bComputerName)

If $bComputerName And $bUserName Then
    MsgBox(0,'', 'test')
    RegDelete("HKLM\SOFTWARE\blahblabla", "RegValue")
Else
    If $bComputerName = False Then $sErrorMsg &= @ComputerName & " is not authorised" & @CRLF
    If $bComputerName = False Then $sErrorMsg &= @UserName & " is not authorised"
    MsgBox(4096, "Error", $sErrorMsg)
EndIf

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

RegDelete("HKLM\SOFTWARE\blahblabla", "RegValue")

So this is the command to remove a key from the registry? Nice.

Thank you, I'll try this and I'll let you know, because I can't add files (AdminInfo.ini), I need to keep all into the exe file. I need an array.

It's inconvenient, but users shouldn't see anything.

Also I'll add the #RequireAdmin command

Edited by Baboo85

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • AndreyS
      By AndreyS
      Dear developers and creators of the language, please explain to me why when pressing the combination Crtl + Shift + C from the 5th or the 10th time "sticks / sinks" Ctrl or Shift? And then you need to press Ctrl or Shift again to reset their triggering. I only need to use hot keys like in the example!
      The code is a small example. Its essence is that when a user in the editor selects any number and presses a combination, then it increases by 1. 
      Dim $x HotKeySet("+^c","Calc") While 1 Sleep(10000) WEnd Func Calc() Send("^c") Sleep(50) $x=ClipGet()+1 ClipPut($x) Send("^v") EndFunc I thought that in my program some kind of glitch was searching for a reason for a long time. And it turned out that apparently somehow the work of some functions used in the example is not compatible. 
      Tell me, please, what is the problem?
    • hcI
      By hcI
      Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments).
      For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one.
      That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work).
       
      Thanks
    • Duck
      By Duck
      I'm attempting to capture the output from the command line tool PSEXEC. I'm using AutoIT to run an instance of PSEXEC against a remote PC to audit Local Admins in my environment using net.exe (C:\Windows\System32> net localgroup administrators). However the usual trick I use to capture command line output does not appear to work well with PSEXEC, as the bottom portion of the output is missing from the return. Any ideas or recommendations are greatly appreciated.  
       
      Here is what I'm working with: 
      ;This script will read from a list of hosts and report who has local admin privileges on the machine #RequireAdmin Global $fileName = @ScriptDir & '\test.txt' ;hostlist, one host per line readHostList() ;Read list of hosts Func readHostList() Local $file = FileOpen($fileName, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite($line & @CRLF) ;MsgBox(0,0,$line) getLocalAdmins($line) WEnd FileClose($file) EndFunc ;run PSEXEC to list local admins Func getLocalAdmins($remotePC) Local $testFile = @ScriptDir &'\test234.txt' FileOpen($testFile, 1) Local $psexec = 'psexec \\' & $remotePC & ' net localgroup administrators' FileWriteLine($testFile, _RunCmd($psexec) ) FileClose($testFile) EndFunc ;Used to return CLI output Func _RunCmd($sCommand) Local $nPid = Run(@Comspec & " /c" & $sCommand, @SystemDir, @SW_Hide, 8), $sRet = "" If @Error then Return "ERROR:" & @ERROR ProcessWait($nPid) While 1 $sRet &= StdoutRead($nPID) If @error Or (Not ProcessExists ($nPid)) Then ExitLoop WEnd Return $sRet EndFunc  
      ## If i manually run the command on the remote PC via PSEXEC I will get the following output: 
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Starting net on PCNAME... on PCNAME...
      net exited on PCNAME with error code 0.
      -------------------------------------------------------------------------------
      admin
      Administrator
      Alias name     administrators
      Domain\Domain Admins
      Comment        Administrators have complete and unrestricted access to the computer/domain
      Members
      The command completed successfully.
       
      ## The returned output from running the above script is as follows:
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Alias name     administrators
      Connecting to PCNAME...
      Starting PSEXESVC service on PCNAME...
      Connecting with PsExec service on PCName...
      Starting net on PCNAME..
      net exited on PCNAME with error code 0.
       
      **Note to test this script PSEXEC must be in the system dir or the path in the script changed 
      PSEXEC tool: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
    • ur
      By ur
      If you observe in below code.
      Func _WinWaitActivate($title,$text,$timeout=$time_out) Logging("Waiting for "&$title&":"&$text) $dHandle = WinWait($title,$text,$timeout) if not ($dHandle = 0) then If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) Else Logging("Timeout occured while waiting for the window...") Exit EndIf EndFunc WinActivate("Untitled - Notepad") $p = "Notallowed1!!" Send("{ENTER}{ENTER}{ENTER}{ENTER}"& $p &"{ENTER}create{SPACE}database{SPACE}"& $p &";{ENTER}") In the notepad if you observe, ! is missing in the text got.
       
      Is there way to get that also printed.
    • rawkhopper
      By rawkhopper
      Hello everyone,
      I have a script that is automating a piece of sluggish software.  I want to automate it with a bit of caution and I am not sure the best way to do it.  ControlSend works great most of the time.  If I have it enter 10 into a text box every once in a while it will enter 1 or 11 and then hit enter.
      To overcome this I use MouseClick to select the text I just entered and then see if it matches the string it was supposed to put in before it hits enter.  This seems to work but what I love about ControlSend is there is less room for human interaction messing it up.  
      Yes I could block input but I prefer not to do that (permissions).
      Is there a better way of doing this?  Any Help would be much appreciated.
      Anyway here is the snippet of the script in question:
      Func KVSend () WinActivate ( "Window", "" ) Local $WindowPos = WinGetPos("Window", "") If $kV < 30 Then WinActivate ( "Window", "" ) ControlClick ("Window", "", 1001) ;Click in Accel Voltage box Sleep (100) ControlSend ("Window", "", 1001, $kV) ; \ kV Sleep (100) MouseMove($WindowPos[0]+130,$WindowPos[1]+75,1) MouseClick($MOUSE_CLICK_LEFT) MouseClick($MOUSE_CLICK_LEFT) Send ("^c") Local $clip = ClipGet () If $clip = $kV Then ControlSend ("Window", "", 1001, "{ENTER}") ;Hit ENTER if value is correct Sleep (100) ControlClick ("Window", "", 1518) ;Lens Clear Else Send ("{BACKSPACE}") KVSend() ; If value is incorrect try again EndIf EndIf