Adapting .REG Files.

Page 12 of 13 FirstFirst ... 210111213 LastLast

  1. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #111

    Matthew Wai said:
    Yet another suggestion:
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
    Set "Folder=C:\Users\System-Admin\System-Admin_Implement"
    For %%i In ("%Folder%\*.bat") Do (echo Processing "%%i"&CMD /C "%%i" & echo.)
    echo Press a key to restart "explorer.exe". & pause > nul
    taskkill /f /im explorer.exe & start explorer.exe
    "explorer.exe" will be restarted only after you press a key after all the .bat files have been processed.
    That's even better @Matthew Wai, thank you.
      My Computer


  2. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #112

    Hello @Matthew Wai,

    Just a quick question, what is the difference between . . .
    Code:
    (Net Session >NUL 2>&1)||(PowerShell Start -verb RunAs '%~0' & Exit /b)
    Code:
    (Net Session >NUL 2>&1)||(PowerShell Start """%~0""" -verb RunAs & Exit /b)
    Thanks in advance.
      My Computer


  3. Posts : 7,607
    Windows 10 Home 20H2
       #113

    Try to figure out this thread: PowerShell start 'D:\Matthew's scripts\Testing.cmd'
    If you can't figure it out, I will try to explain it.
      My Computer


  4. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #114

    Hello @Matthew Wai,

    My question is why the first one was used for the BAT files is different to the second one used for the REG files.

    Is it to escape any special characters [spaces etc] because of literal interpretations etc?

    The difference between the two is that the first one shows -verb RunAs '%~0' and the second one shows """%~0""" -verb RunAs. Could I use """%~0""" -verb RunAs in BOTH?

    Thanks in advance.
      My Computer


  5. Posts : 7,607
    Windows 10 Home 20H2
       #115

    Paul Black said:
    My question is why the first one was used for the BAT files is different to the second one used for the REG files.
    Because I did not know the second one when I used the first one. Now I know the second one is better than the first one.

    Paul Black said:
    Could I use """%~0""" -verb RunAs in BOTH?
    Yes.

    Paul Black said:
    '%~0'
    It does not work if the file path contains apostrophes.

    Paul Black said:
    """%~0"""
    It works even if the file path contains apostrophes.
      My Computer


  6. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #116

    Brilliant @Matthew Wai, thank you!
      My Computer


  7. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #117

    Hello @Matthew Wai,

    As you know the final part of this is to run ALL .ps1 files from a folder.
    I have come up with this but it continuously opens blank Windows . . .
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
    Set "Folder=C:\Users\System-Admin\System-Admin_Implement"
    For %%i In ("%Folder%\*.ps1") Do PowerShell -Command (echo Processing "%%i"&CMD /C "%%i" & echo.)
    echo Press a key to restart "explorer.exe". & pause > nul
    taskkill /f /im explorer.exe & start explorer.exe
    Thanks in advance.
      My Computer


  8. Posts : 7,607
    Windows 10 Home 20H2
       #118

    Paul Black said:
    As you know the final part of this is to run ALL .ps1 files from a folder.
    This part is much more difficult! An expert can certainly do it much better than I do. I can only come up with the following awkward method:
    Code:
    @echo off
    (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)
    If exist "%temp%\✱.vbs" (del "%temp%\✱.vbs")
    Echo Set X = CreateObject("Wscript.shell")>>"%temp%\✱.vbs"
    Set "Folder=C:\Users\System-Admin\System-Admin_Implement"
    For %%i In ("%Folder%\*.ps1") Do (Echo  File found: "%%i"
    Echo X.run ^"Powershell -executionpolicy bypass -file ^" ^& chr^(34^) ^& "%%i" ^& chr^(34^), 0, true >> "%temp%\✱.vbs")
    Echo  Processing the files. & "%temp%\✱.vbs"
    Echo  Operations completed. & Del "%temp%\✱.vbs"
    Echo  Press a key to restart "explorer.exe". & pause > nul
    taskkill /f /im explorer.exe & start explorer.exe
      My Computer


  9. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #119

    Hello @Matthew Wai,

    I came up with this that part works!
    Code:
    @echo off
    Set "Folder=C:\Users\System-Admin\System-Admin_Implement"
    rem PowerShell -Command "& {Set-ExecutionPolicy ByPass}" -NoExit
    rem For %%i in (*.ps1) Do PowerShell -Command "& {.\%%i}" -NoExit
    For %%i In (%Folder%\*.ps1) Do PowerShell -Command "& {%%i}"
    echo Press a key to restart "explorer.exe". & Pause > NUL
    TaskKill /f /im explorer.exe & Start explorer.exe
    The trouble is it lists everything within the file and does NOT list just the filename etc.

    Thanks in advance.
      My Computer


  10. Posts : 7,607
    Windows 10 Home 20H2
       #120

    Paul Black said:
    I came up with this that part works!
    It does not work at my end. It produced the following error:
    Code:
    C:\Users\System-Admin\System-Admin_Implement\PS1.ps1 : File C:\Users\System-Admin\System-Admin_Implement\PS1.ps1
    cannot be loaded because running scripts is disabled on this system. For more information, see
    about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
    At line:1 char:4
    + & {C:\Users\System-Admin\System-Admin_Implement\PS1.ps1}
      My Computer


 

  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 03:15.
Find Us




Windows 10 Forums