I need to have a batch file's opening line makeing it run as Admin. I know the Runas command, but can I runas in the batch file already open? - batch-file

I was wondering if there was any code that would make the current script run in Admin privileges. So I can run a batch file and it is something like
run as admin*
{code}
It is an automaticly run script so I can't right click and run as admin, and I want to be clean and not need another script to use runas to run it as an admin.
I've tried runas, and pointing it to that script it is in, with no luck.

Related

FileZilla Pro CLI Batch command file not executing

I am currently attempting to use FileZilla Pro CLI on a Windows machine to connect and upload to a site in that is working in the Site Manager.
The issue is, the command below works perfectly when pasting it directly into the cmd line. However when saving it as a batch file, it simply just gets to the fzcli> prompt and then nothing happens.
The two line breaks are on purposes to override the requirement for a password and it works perfectly when pasted in.
Does anyone know if this is a cmd line issue, or if my commands need to be different to work in batch file mode?
fzcli
connect --site 0testsite01
put C:/inetpub/wwwroot/websites/sftp/files/customer/test-01.txt /test-sftp/testuser01/test/test-01-uploaded.txt
PAUSE
Your batch file executes fzcli in an interactive mode. The fzcli then waits for you to interactively enter the commands. Only after you would exit the fzcli, the batch file would continue. And fail, as it will try to execute connect as a batch file command. The fzcli does not know about the batch file. Nor does the batch file interpreter know about the fzcli commands.
It's a common misconception. You will find plenty of similar questions basically about scripting any tool that has its own commands. For example: sftp, ftp, psftp, winscp.
To provide commands to fzcli, it seems that you need to use --script switch. The fzcli documentation gives this example:
fzcli --mode standalone --script C:\Scripts\script-file

Why does a batch file fail to start an executable with RUNAS a different user, but works on starting it from Windows shell?

I have a .bat file that should start a service as a different user. The different user account has administrator privileges.
Here's the kicker, when I perform Shift + Right-click on the service .exe file, it gives me the option to run as the other user, and prompts for the credentials, and the service runs.
But when I run the batch script which attempts to run the service, it prompts for the user password and then crashes immediately after it starts, and shows the message:
[programName] has stopped working. A problem ... bla bla bla... Windows will close the program and notify you when a solution is available.
The Windows event log gives me exception code: 0xe0434f4d
Fault offset: 0x0000000000033c58
Neither of which leads to anything meaningful that I could find.
I found a page where is written to remove a couple of registry files and start over. However, when I navigated to the registry files to be removed, they were not there in the first place.
Batch file code:
echo off
cd C:\[Path to my company's install directory]
runas /user:local\TestUser DriverProgram.exe

Starting a batch file from another batch file only opens CMD

When I start a batch file from another batch file, it just opens a new CMD window named just "TEST.bat", and doesn't run the actual batch. Running it manually works fine.
cd %~dp0\Colours\TEST.bat
start "TEST.bat"
I have tried many different ways to run the batch, but it all does the same thing. I've also tried to run the batch as administrator but same result again.
Full code(not finished): http://pastebin.com/GE8yJP0J
To run another batch file, use call not start. Also: cd expects a directory, not a filename.
cd "%~dp0\Colours"
call TEST.bat

batch svn checkout windows server 2012

I wrote this .bat file:
runas /savecred /user:Domain\Username "svn checkout https://<Repository> <DestinationLocalFolder>"
To be able to automate the process of downloading source code, it has to be a . bat and it has to run as a different user than the one that is logged in. I tried it in my Windows 7 Workstation and it works perfect. But after trying it on the server, which also has TortoiseSVN, and all user settings that I checked are the same, it just opens an SVN window and immediately closes it.
I have also tried this with powershell:
powershell "runas /savecred /user:Domain\Username ""svn checkout https://<Repository> <DestinationLocalFolder>"""
Any ideas on why this does not work on the server would be greatly appreciated.
I got it, all I needed to do was running an svn cleanup, because in my debugging I had interrupted a previous checkout process. After running an svn cleanup after interrupting the process, it works perfect.

Run a powershell script in batch file as administrator

I have a powershell script. To run this sript, I have written a batch file.
Here is code of batch file:
:: psscript.bat
set psscript='%CD%\Hotfix-Automation-Installer.ps1'
echo Running PowerShell Script: %psscript%
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe ^&%psscript% %*
When I double-click on batch file, I want my script Hotfix-Automation-Installer.ps1 to be run as an administrator.
How I can run this script as administrator?
Read Matt's article on this link:
How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?
He has given complete script to elevate from current session to administrator session. Quiet helpful.

Resources