New
#51
Did you try the following?
PowerShell start "d:\batchfiles\tuneup-mod.bat" -verb RunAs
Yes, I did. As I mentioned, Powershell is changing the default directory out from under me so it can't find test2.bat any more:
My Powershell 7 profile is Set-Location C:\Users\ztruk\PowerShellScriptsD:\BatchFiles\Save>test2
D:\BatchFiles\Save>Rem If not admin NET SESSION wil fail and call Powershell to elevate to Admin
D:\BatchFiles\Save>(Net session 1>nul 2>&1 ) || (PowerShell dir * & start """D:\BatchFiles\save\test2.bat""" -verb RunAs & Exit /B )
Directory: C:\Users\ztruk\PowerShellScripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 8/4/2020 4:16 PM Backup
-a---- 8/4/2020 12:14 AM 1664 getBuildInfo.cmd
-a---- 8/4/2020 12:14 AM 1664 getBuildInfo.ps1
-a---- 8/3/2020 10:07 PM 167 model.ps1
-a---- 8/3/2020 7:04 PM 45 profile.ps1
PowerShell has done the same at my end, but it can still find my .cmd file.
The following is the output on standard Command Prompt:
The above has produced the following results on elevated Command Prompt:Code:Microsoft Windows [Version 10.0.18362.30] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\Matthew_Wai>"E:\Batch Files\Run as admin.cmd" C:\Users\Matthew_Wai>(Net session 1>nul 2>&1 ) || (PowerShell dir * ; start """E:\Batch Files\Run as admin.cmd""" -verb RunAs & Exit /B ) Directory: C:\Users\Matthew_Wai Mode LastWriteTime Length Name ---- ------------- ------ ---- d-r--- 8/14/2020 4:41 AM Desktop d-r--- 7/3/2020 2:04 PM Documents d-r--- 7/27/2020 3:26 PM Downloads d-r--- 6/21/2020 3:58 PM Favorites d-r--- 5/11/2020 2:49 PM Music d-r--- 7/20/2020 2:31 AM Pictures d-r--- 7/28/2020 2:38 PM Searches d-r--- 7/23/2020 12:02 PM Videos
Code:C:\Windows\system32>(Net session 1>nul 2>&1 ) || (PowerShell dir * ; start """E:\Batch Files\Run as admin.cmd""" -verb RunAs & Exit /B ) C:\Windows\system32>echo Administrative privileges got. & pause1>nul Administrative privileges got.
Rich,
Am I right in thinking that your day-to-day user account is a standard one and that you are authorising elevation using a different account?
This might well be the significant difference between your situation and that of others [including me].
You could test for this being significant by logging in to your admin account and then running the self-elevation code in it.
Denis
No, my everyday account is an Administrator level account on me Laptop, which I'm using now (wife using Desktop) and my Desktop.
Rich,
Sorry I couldn't help. The only time I've managed to make the admin test script fail is when I have put the script file in a path containing special characters [such as D:\Desktop\Test & see].
Denis
You don't have to help him solve the problem because it has already been solved at Place to store small batch files for use in the BSOD forum
Denis, Matthew worked with me on this a lot and with his VBS code got it working perfectly. It's now sop easy that the batch files can simple be launched from File Explorer via double click or right click and open.
Between you, Matthew, KYHI, Paul and others, this has been a fun learning experience.
I can't say enough about the quality of people on tenforums or the quality and amount of help they offer. Sometimes amazes me.
Thank you one and all