signalcc Posted January 8, 2019 Posted January 8, 2019 I have been doing nothing but reading and trying to figure this out. It appeared that AutoIT may be my answer, but I'm not sure as I have tried to work it and am not getting far. Here is my issue. I have about 140 Laptops/Tablets in the field. Many of them have not connected to the corporate network in quite some time. I have the install of our Management Software in a ZIP that is accessible from our corporate website. The issue I have is our users do not have Local Admin rights. In looking at the setup.bat file it requires it to be run as an admin. I need a way to get the BAT file to run itself as admin without a UN/PW prompt (I can provide that info for the script) or a separate BAT file that will set the Admin Elevation and then call the Setup file. Is there any way to do this? I have tried the following items installAdmin() Func installAdmin() ; Change the username and password to the appropriate values for your system. Local $sUserName = "xxxxx" Local $sPassword = "xxx" Local $sDirectory = "C:\ASD4VM\Download\" Local $sFiletoRun = "Inst_with_Privileges.bat" RunAsWait($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) EndFunc ;==>Example This compiles and I run it with no result at all, it does nothing, but it also doesn't error. It just does nothing So then I tired the same script with a different folder path C:\directsetup\sertup.bat and the same thing, no result at all and no error in AutoIT Then i found someone say to remove the "" so I did that, still nothing. Then I found and tried this. It just errors on not finding WSSCRIPT Set WshShell=WScript.CreateObject("WScript.Shell") strCmd="\\server\application.exe" strUser="domain\admin" strPass="Password" set WshShell=CreateObject("WScript.Shell") WshShell.Run "runas.exe" & " /u:" & strUser & " " & strCmd WScript.Sleep 1000 WshShell.Sendkeys strPass & "~" Then I tried to uses this code I found. But all it does is error saying it can't parse the file. cd c:\directsetup\ strCmd=setup.bat strUser="bandi\BNIadmin" strPass="BNI@dmin" runaswait($strUser, $strDomain, $strPass, 0, $strCmd) I just need to be able to have an EXE that can run as is, then call the >BAT file running as admin to install the Monitoring Agent. Thanks so much for any assistance!!!
Developers Jos Posted January 8, 2019 Developers Posted January 8, 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.
Nine Posted January 8, 2019 Posted January 8, 2019 1 hour ago, signalcc said: This compiles and I run it with no result at all, it does nothing, but it also doesn't error. How do you know there is no error, you do not have any code to check for error. Put that after the runaswait (...) Local $iReturn = RunAsWait (....) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
signalcc Posted January 8, 2019 Author Posted January 8, 2019 5 minutes ago, Nine said: How do you know there is no error, you do not have any code to check for error. Put that after the runaswait (...) Local $iReturn = RunAsWait (....) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf Result is, >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\directsetup\NewRun.au3" C:\directsetup\NewRun.au3 (11) : ==> Badly formated variable or macro.: Local $iReturn = RunAsWait (....) Local $iReturn = RunAsWait (^ ERROR >Exit code: 1 Time: 0.2974 Maybe I put it in the wrong place? installAdmin() Func installAdmin() ; Change the username and password to the appropriate values for your system. Local $sUserName = "xxxxx" Local $sPassword = "xxx" Local $sDirectory = "C:\ASD4VM\Download\" Local $sFiletoRun = "Inst_with_Privileges.bat" RunAsWait($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) Local $iReturn = RunAsWait (....) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf EndFunc ;==>Example
Nine Posted January 8, 2019 Posted January 8, 2019 (edited) replace the dots by your actual code. Add those includes at the begining of your script : #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> Edited January 8, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
signalcc Posted January 8, 2019 Author Posted January 8, 2019 10 minutes ago, Nine said: replace the dots by your actual code. Ok so I spent a few on this, but a coder I am not. This is what I tried Local $iReturn = RunAsWait ( Func ; Change the username and password to the appropriate values for your system. Local $sUserName = "xxxx" Local $sPassword = "xxxx" Local $sDirectory = "C:\directsetup" Local $sFiletoRun = setup.bat RunAsWait($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) EndFunc If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf Result is >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\directsetup\RunFirst.au3" "C:\directsetup\RunFirst.au3" (2) : ==> Badly formatted "Func" statement.: Func >Exit code: 1 Time: 0.2974 Thank you so much for trying to help me. i really appreciate it.
Dana Posted January 8, 2019 Posted January 8, 2019 Why are you using a function for a few simple lines of code? Try this: #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> ; Change the username and password to the appropriate values for your system. Local $sUserName = "xxxx" Local $sPassword = "xxxx" Local $sDirectory = "C:\directsetup" Local $sFiletoRun = setup.bat $iReturn = RunAsWait($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf
Nine Posted January 8, 2019 Posted January 8, 2019 there is a missing \ at the end of the directory, modify to 7 minutes ago, Dana said: Local $sDirectory = "C:\directsetup\" “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
signalcc Posted January 8, 2019 Author Posted January 8, 2019 18 minutes ago, Dana said: Why are you using a function for a few simple lines of code? Try this: #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> ; Change the username and password to the appropriate values for your system. Local $sUserName = "xxxx" Local $sPassword = "xxxx" Local $sDirectory = "C:\directsetup" Local $sFiletoRun = setup.bat $iReturn = RunAsWait($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf Holy god are you guys amazing!!!! I used #nine "\" and I had to add the same in front of the file name on the next line to get it to work. Now, I have admin rights, so i have to see if it is working on a non admin machine. I'll be in touch but thank you so much to both of you for all of your help!!! #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> ; Change the username and password to the appropriate values for your system. Local $sUserName = "xxxxx" Local $sPassword = "xxxx" Local $sDirectory = "C:\users\%username%\Downloads\FortMyers\FortMyers\directsetup\" Local $sFiletoRun = "\setup.bat" $iReturn = RunAsWait ($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf
signalcc Posted January 8, 2019 Author Posted January 8, 2019 Ok so it works on my PC. Once I extract the ZIP file to a user PC that does not have admin rights and I run the script created about I get an error "Batch file has not run, the system cannot find the file specified" When I click ok on that it then runs the file, but then I get an alert that I do not have the proper permissions and I need to run the file as "Run as Administrator" So really, the script didn't do anything I was hoping for. Did I just go about this the wrong way? Here is the BAT file. Maybe that will help? We need the users to select Option 2. This will install the agent for us. Again, these PC's are all over the country and not connected locally tot he domain. expandcollapse popup@ECHO OFF cls @setlocal enableextensions @cd /d "%~dp0" :README ECHO. ECHO ****************************************************************************** ECHO. ECHO ManageEngine Desktop Central Remote Office Setup Wizard ECHO. ECHO This script will install the Desktop Central agent in this computer and in the computers specified in the computernames.txt.You should have logged in as an administrator to install the Agent. ECHO. ECHO ****************************************************************************** ECHO. ECHO. ECHO 1 - Install WAN Agent to client computers ECHO. ECHO 2 - Install WAN Agent in this computer ECHO. ECHO 3 - Exit ECHO. :GETINPUT set INPUT= set /P INPUT=Enter the option: %=% IF "%INPUT%" == "1" GOTO INSTALLWANAGENT IF "%INPUT%" == "2" GOTO INSTALLAGENT IF "%INPUT%" == "3" GOTO :EOF IF "%INPUT%" == "q" GOTO :EOF if "%INPUT%"=="" GOTO README GOTO INVALID :INSTALLAGENT start /wait msiexec /i DesktopCentralAgent.msi TRANSFORMS="DesktopCentralAgent.mst" ENABLESILENT=yes REBOOT=ReallySuppress INSTALLSOURCE=Manual /lv Agentinstalllog.txt IF "%ERRORLEVEL%" == "0" GOTO AGENTINSTALLSUCCESS IF "%ERRORLEVEL%" == "3010" GOTO AGENTINSTALLSUCCESS IF "%ERRORLEVEL%" == "1603" GOTO AGENTINSTALLFAIL_FATAL IF "%ERRORLEVEL%" == "1612" GOTO AGENTINSTALLFAIL_FATAL IF "%ERRORLEVEL%" == "1619" GOTO AGENTINSTALLFAIL_UNZIP GOTO AGENTINSTALLFAIL :INSTALLWANAGENT ECHO. ECHO Please make sure you have logged in as admin user in this computer ECHO. start /B /wait dcremagentinstaller.exe "dssetup" "dc" IF "%ERRORLEVEL%" == "9059" GOTO AGENTINSTALLFAIL_UNZIP GOTO SEELOGS :AGENTINSTALLFAIL_FATAL set ERROR=%ERRORLEVEL% ECHO. ECHO ----------------------------------------------------------------------------- Msg %username% /TIME:0 /V /W "Please run setup.bat in 'Run as administrator' mode." ECHO. ECHO DesktopCentral Agent installation failed. ErrorCode: %ERROR%" net helpmsg %ERROR% ECHO ----------------------------------------------------------------------------- GOTO ENDFILE :AGENTINSTALLFAIL_UNZIP set ERROR=%ERRORLEVEL% ECHO. ECHO ----------------------------------------------------------------------------- Msg %username% /TIME:0 /V /W "Please Un-Zip/ Extract the contents and try running setup.bat." ECHO DesktopCentral Agent installation failed. ErrorCode: %ERROR%" net helpmsg %ERROR% ECHO ----------------------------------------------------------------------------- GOTO ENDFILE :AGENTINSTALLSUCCESS ECHO. ECHO DesktopCentral Agent installed successfully. ECHO. GOTO ENDFILE :AGENTINSTALLFAIL ECHO. ECHO ----------------------------------------------------------------------------- ECHO DesktopCentral Agent installation failed. ErrorCode: %ERRORLEVEL% net helpmsg %ERRORLEVEL% ECHO ----------------------------------------------------------------------------- GOTO ENDFILE :INVALID Msg %username% /TIME:0 /V /W "Please enter the valid option." ECHO. GOTO GETINPUT :SEELOGS ECHO. ECHO See the logs.txt to verify the status of the installation of the WAN Agents. GOTO ENDFILE :ENDFILE ECHO. PAUSE
Nine Posted January 8, 2019 Posted January 8, 2019 50 minutes ago, signalcc said: Local $sDirectory = "C:\users\%username%\Downloads\FortMyers\FortMyers\directsetup\" Local $sFiletoRun = "\setup.bat" There is 2 successive \\. Remove the \ in front of setup.bat “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
signalcc Posted January 8, 2019 Author Posted January 8, 2019 1 minute ago, Nine said: There is 2 successive \\. Remove the \ in front of setup.bat Ok, that may remove the missing file error, but it is still not doing the run as admin part. It seems to run the Setup.bat as an admin, I guess I need to have the BAT file do a runas /administrator for it to run the MSI properly?
Nine Posted January 8, 2019 Posted January 8, 2019 Put #RequireAdmin as the very first line of the script “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
signalcc Posted January 8, 2019 Author Posted January 8, 2019 1 minute ago, Nine said: Put #RequireAdmin as the very first line of the script On the AU3 script or the setup.bat file?
Nine Posted January 8, 2019 Posted January 8, 2019 script “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
signalcc Posted January 8, 2019 Author Posted January 8, 2019 ok so I removed the "\" as suggest and it failed with "Cannot find the file specified" So I put it back on that "setup.bat" and removed it from the "directsetup" Same error So I put it back on the "directsetup" again and same issue "Cannot find the file specified" Local $sDirectory = "C:\users\%username%\Downloads\FortMyers\FortMyers\directsetup\" Local $sFiletoRun = "\setup.bat" Local $sDirectory = "C:\users\%username%\Downloads\FortMyers\FortMyers\directsetup\" Local $sFiletoRun = "setup.bat" Local $sDirectory = "C:\users\%username%\Downloads\FortMyers\FortMyers\directsetup" Local $sFiletoRun = "\setup.bat" All three ways give the same error now. Thank you so much, again, for all of your help
Nine Posted January 8, 2019 Posted January 8, 2019 (edited) %username% do not work in script, it is dos. replace with @UserName Local $sDirectory = "C:\users\" & @Username & "\Downloads\FortMyers\FortMyers\directsetup\" Local $sFiletoRun = "setup.bat" Edited January 8, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
signalcc Posted January 8, 2019 Author Posted January 8, 2019 6 minutes ago, Nine said: %username% do not work in script, it is dos. replace with @UserName Local $sDirectory = "C:\users\" & @Username & "\Downloads\FortMyers\FortMyers\directsetup\" Local $sFiletoRun = "setup.bat" Same problem System cannot find the file specified #RequireAdmin #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> ; Change the username and password to the appropriate values for your system. Local $sUserName = "administrator" Local $sPassword = "****" Local $sDirectory = "C:\users\@UserName\Downloads\FortMyers\FortMyers\directsetup" Local $sFiletoRun = "setup.bat" $iReturn = RunAsWait ($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf
signalcc Posted January 8, 2019 Author Posted January 8, 2019 Or maybe I don't I realized I was missing the "\" at the end of "directsetup" so I fixed that, but the same issue. Cannot find the file specified #RequireAdmin #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIError.au3> ; Change the username and password to the appropriate values for your system. Local $sUserName = "administrator" Local $sPassword = "***" Local $sDirectory = "C:\users\@UserName\Downloads\FortMyers\FortMyers\directsetup\" Local $sFiletoRun = "setup.bat" $iReturn = RunAsWait ($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) If @error Then Local $sLastError = _WinAPI_GetLastErrorMessage() MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Batch file has not Run :" & @CRLF & @CRLF & $sLastError) Else MsgBox($MB_SYSTEMMODAL, "", "The return code from runaswait was: " & $iReturn) EndIf
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