I
I
Ivanq2015-10-22 19:47:58
cmd/bat
Ivanq, 2015-10-22 19:47:58

Run BAT as administrator?

Good evening!
There was a problem - you need to run BAT as an administrator.
At first I tried to solve it through runas code.bat(I don’t remember what else I wrote there).
There was nausea Введите пароль для Администратор:.
The user will definitely delete the program. Found a solution with VBS and BAT:
code.bat :

net session 2>nul >nul
if not errorlevel 1 (
  echo ==== Success: Administrator
  pause >nul
) else (
  code.vbs
  exit /b
)

code.vbs :
Set WshShell = CreateObject("Shell.Application")
WshShell.ShellExecute "code.bat", "", "", "runas", 0
Set WshShell = Nothing

Everything seems to be fine, but I want to add this option: the user enters a password, and next time it is not necessary to enter. There is such a thing in command runas , but not in ShellExecute . How to do this?
And yet - the main code is launched by bat. Whatever the window would not interfere with, I hid it, using the same VBS transferred it to hidden processes, but I don’t like the name of the process "Windows Command Handler". Can this be changed somehow? Preferably without /^.*(C|Delphi).*$/i .
PS Tried to search, did not find.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem @Jump, 2015-10-22
curated by the

runas /savecred
When launched with this key, a password entry window appears. Once entered, the password is remembered.
After that, you can simply run it, it will not ask for a password.
This key does not work in Windows 7 Home and Windows 7 Starter.

O
oia, 2015-10-22
@oia

admilink.narod.ru/admilink.htm use

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question