Exécution d'un script en Administrateur sans les droits
Bonjour,
J'ai écrit un petit script qui fonctionne très bien lorsque je le lance depuis Powershell ISE en administrateur.
Cependant, lorsque je le lance en faisant un clic-droit puis "executer avec powershell", mon script ne fonctionne pas car il n'est pas lancé en tant qu'administrateur.
Je cherche donc à intégrer dans le script une commande permettant de s'exécuter en tant qu'administrateur.
Mais je commence à m'emmêler les pinceaux entre les -runas , -verbAS , start-process ....
En gros, je voudrais pouvoir double clique sur mon script et qu'il se lance en tant qu'administrateur (ou en .bat)
Quelqu'un pour m'aider ?
Wi-Fi_Diagnostic_Report.bat
:salut:
Voici un exemple : Wi-Fi_Diagnostic_Report.bat
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| @echo off
@REM This batch script generates a wireless network report saved as HTML file, which you can open it with your favorite web browser.
@REM The report shows all the Wi-Fi events for the last three days and groups them by Wi-Fi connection sessions.
@REM It also shows the results of several network-related command line scripts and lists all of the network adapters in your PC.
Mode 80,15
Title Get Wi-Fi Diagnostic Report
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Automatically check & and start the batch file with admin rights
(Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Call :GetFileNameWithDateTime MyCurrentDate
netsh wlan show wlanreport
Set "wlan_report=%ProgramData%\Microsoft\Windows\WlanReport\wlan-report-latest.html"
If exist "%wlan_report%" Copy "%wlan_report%" "%~dp0wlan-report-latest_%MyCurrentDate%.html">nul
Start "" "%~dp0wlan-report-latest_%MyCurrentDate%.html" & exit
::----------------------------------------------------------------------------------
:GetFileNameWithDateTime <FileName>
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set "MyDate=%%x"
set "%1=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%-%MyDate:~8,2%-%MyDate:~10,2%"
Exit /B
::---------------------------------------------------------------------------------- |