Check the state of the OS and proceed accordingly.

Page 6 of 7 FirstFirst ... 4567 LastLast
  1. Ztruker's Avatar
    Posts : 13,511
    Windows 10 Pro X64 20H4 19042.746
       #51

    Try3 said:
    Rich,

    If you open an admin prompt and change to the d:\batchfiles folder, does your [elevated] admin account have permission to list the folder contents and to run the d:\batchfiles\tuneup-mod.bat file?

    I cannot say that permissions are affecting this problem but it seems worth checking.

    Denis
    Yes, it works correctly in Admin powershell or command prompt.
      My Computers

  2. Ztruker's Avatar
    Posts : 13,511
    Windows 10 Pro X64 20H4 19042.746
       #52

    Matthew Wai said:
    Also try the following on standard Command Prompt:

    (Powershell "Start-Process ""d:\batchfiles\tuneup-mod.bat""")
    \

    I tried that earlier today and also yesterday. Also tried .\Tuneup-mod.bat. Neither worked.
      My Computers

  3. Matthew Wai's Avatar
    Posts : 5,072
    Windows 10 Home 20H2
       #53

    Did you try the following?

    PowerShell start "d:\batchfiles\tuneup-mod.bat" -verb RunAs
      My Computer

  4. Ztruker's Avatar
    Posts : 13,511
    Windows 10 Pro X64 20H4 19042.746
       #54

    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:

    D:\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
    My Powershell 7 profile is Set-Location C:\Users\ztruk\PowerShellScripts
      My Computers

  5. Matthew Wai's Avatar
    Posts : 5,072
    Windows 10 Home 20H2
       #55

    Ztruker said:
    Powershell is changing the default directory out from under me so it can't find test2.bat any more
    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:
    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
    The above has produced the following results on elevated Command Prompt:
    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.
      My Computer

  6. Try3's Avatar
    Posts : 7,445
    Windows 10 Home x64 Version 20H2 Build 19042.928
       #56

    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
      My Computer

  7. Ztruker's Avatar
    Posts : 13,511
    Windows 10 Pro X64 20H4 19042.746
       #57

    No, my everyday account is an Administrator level account on me Laptop, which I'm using now (wife using Desktop) and my Desktop.
      My Computers

  8. Try3's Avatar
    Posts : 7,445
    Windows 10 Home x64 Version 20H2 Build 19042.928
       #58

    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
      My Computer

  9. Matthew Wai's Avatar
    Posts : 5,072
    Windows 10 Home 20H2
       #59

    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
      My Computer

  10. Ztruker's Avatar
    Posts : 13,511
    Windows 10 Pro X64 20H4 19042.746
       #60

    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
      My Computers


 
Page 6 of 7 FirstFirst ... 4567 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 19:39.
Find Us




Windows 10 Forums