Command Prompt Runas cscript - batch-file

I have get_data.vbs located in C:/test/source/. I've created run.bat file in C:/test/bin.
I'm able to run vbs script when I put the following in bat file:
cscript ../source/get_data.vbs
Q: Why it doesn't work when I use runas command:
runas /user:domain\username "cscript \"../source/get_data.vbs""
If I put full path, it works without any issues:
runas /user:domain\username "cscript \"C:/test/source/get_data.vbs""
Thanks in advance

It didn't work because runas is started on its current directory %windir%\System32 and there is no /source/get_data.vbs there.
If you want to make sure of this, try this code:
start /separate runas /user:domain\username "cscript \"../source/get_data.vbs""
You will see on title of the Window that opened something like C:\Windows\System32\runas.exe

Related

.bat file running cmd with specific command lines

I need to create a batch file that will open cmd.exe (as a administrator) with these lines:
cd C:\Program Files\Putty
cd C:\Program Files\Putty>psftp -i XXXXXXXXX.ppk xxxx_test#111.111.111.11 -b C:\UPLOAD\upload.ftp
Can anyone help me?
DoStuff.bat
#echo off
runas /user:%USERDOMAIN%\%USERNAME% "cmd.exe /K \"cd C:\Program Files\Putty\" & psftp -i XXXXXXXXX.ppk xxxx_test#111.111.111.11 -b C:\UPLOAD\upload.ftp"
runas will let you run a command as Administrator (you may need to change the domain/user to match your system, and enter a password).
Running cmd.exe /K will run the following commands.
The quotes around the commands need to be escaped with \"
I'm having a hard time seeing the difficulty.
Can you explain what you tried, and why it didn't work?

Can't manage to make CMD launch a program using start

I made a .bat file which is supposed to run Thunderbird minimized.
Here's what I put in it so far:
start /min "" C:\"Program Files (x86)"\"Mozilla Thunderbird"\thunderbird.exe runas /user:Administrator
I tried several tests:
- Removing /min
- Adding the runas option for administrator rights
- Adding the first empty quotes after start
- Writing the whole path into quotes
- ...etc.
Everything that happens is the .bat launches, but nothing furthermore happens.
I have no error in the CMD window.
Why isn't it working ??
My purpose is to put that .bat in startup folder so that Thunderbird launches minimized on startup.
I used to use an extension (MinimizeOnStartup) for Thunderbird, but it's no longer compatible with latest version and I couldn't manage to find any alternative.
I read through here, it wasn't enough to help:
A batch file to minimize other applications
Can you help me?
Thank you.
Using Windows 10.
Try the following (modify it accordingly)
cd C:\Program Files (x86)\Mozilla Thunderbird\
start /min thunderbird.exe runas /user:Administrator
A solution posted on reddit https://www.reddit.com/r/Thunderbird/comments/bnt6u3/ive_created_a_small_script_to_minimize/ ...
This is Windows only. You'll need NirCMD for this. NirCMD will trigger the "Minimize" Event after we've started Thunderbird. Get it here: https://www.nirsoft.net/utils/nircmd.html
The script:
START "" "C:\Program Files\Mozilla Thunderbird\thunderbird.exe"
timeout /T 3 /nobreak
"nircmd.exe" win min process "thunderbird.exe"

How to run another batch script with different privilege?

I want to run a batch script as Administrator which, in turn, starts another batch script (start "title" /b /wait), but with current user's privilege.
Is this possible? What's the best way to do it?
Or how can I get the current logged in user name?
The command you want is runas - this command runs batchfile with the domain and username of the currently logged in user (you could also hardcode the domain and username if you wanted a specific user):
runas /noprofile /user:%USERDOMAIN%\%USERNAME% C:\batchfile.bat
The runas command requires an external program as the last argument so it doesn't handle built in commands like dir or copy. But you can run a built in command like copy with:
runas /noprofile /user:%USERDOMAIN%\%USERNAME% "cmd /c copy C:\source.txt C:\dest.txt"
You can also run things as Administrator like this:
runas /noprofile /user:Administrator "cmd /c copy C:\file.txt C:\Windows\System"
Here is some more info:
https://www.windows-commandline.com/windows-runas-command-prompt/

How run file .bat as admin

I have question how run file .bat as admin? How run cmd as admin in file bat?
I must run command on cmd:
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -px "MyKey" c:\key.xml -pri
Please help and have any tips or any good material.
Use RUNAS command for this purpose like below. See help using runas /? in command prompt
runas /user:administrator "%windir%\Microsoft.NET\Framework\v2.0.5
0727\aspnet_regiis.exe -px "MyKey" d:\key.xml -pri"
Enter the password for administrator:
open start menu by pressing windows key type cmd right click cmd and select Run as administrator this will open the command prompt in administrator mode and then you can run your command as an administrator.

How to get direct path using Batch File

I want to write simple Batch file will click on the batch file
I should go to my directory path should be D:\DS\Install
At present i am doing every 1hr go to
RUN command and typing to cmd and connect to D:\DS\Install
Instead of this I want short cut option.. :-)
If I understand your question correctly,
You want a shortcut on desktop which will open a command prompt and change directory to D:\DS\Install
This is pretty straight forward:
Go to C:\windows\system32 and copy cmd.exe to D:\DS\Install folder
Now right click on the cmd.exe in D:\DS\Install folder and send it to desktop create shortcut.
You will have a shortcut on desktop which will take you to the required folder everytime..
Just FYI... cmd.exe will always open from the directory where it is placed.
Just create a shortcut in your desktop, and when asked for the location, type this command
cmd.exe /k "cd /d "d:\ds\install""
This shortcut will call cmd to execute the cd to change the drive/folder and keep the window open to continue working with it.
You can also make a batch file called ds.bat and put it in c:\windows or any other folder that is on the path.
You can then use the WIN+R hotkey and type ds and enter.
#echo off
cd /d "d:\ds\install"
cmd /k
#echo off
cd /d "d:\ds\install"
cmd /k

Resources