DCKen Posted April 13, 2018 Share Posted April 13, 2018 Hello Everybody. I'm a beginner in autoit, I'm trying to run .bat with domain permissions. I have local privileges. Can you help me with this code? My code local: installAdmin() Func installAdmin() ; Change the username and password to the appropriate values for your system. Local $sUserName = "user" Local $sPassword = "pass" Local $sDirectory = "C:\" Local $sFiletoRun = "Fix.bat" RunAsWait($sUserName, @ComputerName, $sPassword, 0, $sDirectory & $sFiletoRun) EndFunc ; Link to comment Share on other sites More sharing options...
Subz Posted April 13, 2018 Share Posted April 13, 2018 Why not convert your batch file to Autoit? Can you post it here? Link to comment Share on other sites More sharing options...
DCKen Posted April 13, 2018 Author Share Posted April 13, 2018 13 minutes ago, Subz said: Why not convert your batch file to Autoit? Can you post it here? My files have the effect of running the spooler again. I want it to be run by domain permissions. I do not know how to switch to autoit, so I run .bat Can you help me? @echo off :: BatchGotAdmin (Run as Admin code starts) REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B :gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) pushd "%CD%" CD /D "%~dp0" :: BatchGotAdmin (Run as Admin code ends) echo Stopping print spooler. echo. net stop spooler echo deleting temp files. echo. del %windir%\system32\spool\printers\*.* /q echo Starting print spooler. echo. net start spooler pause Link to comment Share on other sites More sharing options...
Subz Posted April 13, 2018 Share Posted April 13, 2018 When you post code can you use the <> tags, just helps reading the code better: You should be able to use the following, if you're not an Admin it should prompt for Admin credentials. Please test and let us know how it goes? #RequireAdmin RunWait(@ComSpec & " /c net stop spooler", "", @SW_HIDE) FileDelete(@WindowsDir & "\System32\spool\printers\*.*") RunWait(@ComSpec & "/c net start spooler", "", @SW_HIDE) Link to comment Share on other sites More sharing options...
DCKen Posted April 13, 2018 Author Share Posted April 13, 2018 2 minutes ago, Subz said: When you post code can you use the <> tags, just helps reading the code better: You should be able to use the following, if you're not an Admin it should prompt for Admin credentials. Please test and let us know how it goes? #RequireAdmin RunWait(@ComSpec & " /c net stop spooler", "", @SW_HIDE) FileDelete(@WindowsDir & "\System32\spool\printers\*.*") RunWait(@ComSpec & "/c net start spooler", "", @SW_HIDE) When you post code can you use the <> tags, just helps reading the code better: ->Sorry, I understand. its code does not work Link to comment Share on other sites More sharing options...
Subz Posted April 13, 2018 Share Posted April 13, 2018 Can you explain what doesn't work, the code is completely silent, i.e. you won't see command prompt? The following code should remain open and say if it fails to stop/start the spooler. Can you tell me what you see? Also are you an Administrator? If not do you get prompted for Username and Password? #RequireAdmin RunWait(@ComSpec & " /k net stop spooler") FileDelete(@WindowsDir & "\System32\spool\printers\*.*") RunWait(@ComSpec & "/k net start spooler") Link to comment Share on other sites More sharing options...
Subz Posted April 13, 2018 Share Posted April 13, 2018 (edited) Sorry, not enough sleep please try try following: installAdmin() Func installAdmin() ; Change the username and password to the appropriate values for your system. Local $sUserName = "user" Local $sPassword = "pass" Local $sDomain = @ComputerName RunAsWait($sUserName, $sDomain, $sPassword, 0, @ComSpec & " /c net stop spooler", "", @SW_HIDE) RunAsWait($sUserName, $sDomain, $sPassword, 0, @ComSpec & ' /c del "' & @WindowsDir & '\System32\spool\printers\*.*" /q', "", @SW_HIDE) RunAsWait($sUserName, $sDomain, $sPassword, 0, @ComSpec & "/c net start spooler", "", @SW_HIDE) EndFunc Edited April 13, 2018 by Subz Link to comment Share on other sites More sharing options...
DCKen Posted April 13, 2018 Author Share Posted April 13, 2018 1 hour ago, Subz said: Sorry, not enough sleep please try try following: installAdmin() Func installAdmin() ; Change the username and password to the appropriate values for your system. Local $sUserName = "user" Local $sPassword = "pass" RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec & " /c net stop spooler", "", @SW_HIDE) RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec & ' /c del "' & @WindowsDir & '\System32\spool\printers\*.*" /q', "", @SW_HIDE) RunAsWait($sUserName, @ComputerName, $sPassword, 0, @ComSpec & "/c net start spooler", "", @SW_HIDE) EndFunc Sorry, I try everything in your code (remove or change @SW_SHOW) , but it does not work. In your code, can it use user domain? Link to comment Share on other sites More sharing options...
Subz Posted April 13, 2018 Share Posted April 13, 2018 Not sure but are you putting in your domain name in place of @ComputerName,? Link to comment Share on other sites More sharing options...
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