Adapting .REG Files.

Page 13 of 13 FirstFirst ... 3111213
  1. Paul Black's Avatar
    Posts : 12,191
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #121

    Hello @Matthew Wai,

    Is this any better . . .
    Code:
    @echo off
    Set "Folder=C:\Users\System-Admin\System-Admin_Implement"
    rem (Net Session >NUL 2>&1)||(PowerShell Start """%~0""" -verb RunAs & Exit /b)
    
    PowerShell -Command "& {Set-ExecutionPolicy ByPass}" -NoExit
    For %%i In (%Folder%\*.ps1) Do PowerShell -Command "& {%%i}"
    
    echo Press a key to restart "explorer.exe". & Pause > nul
      My Computer

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

    I got the following when I just double-clicked on the .cmd file.
    Code:
    Set-ExecutionPolicy : Access to the registry key
    'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied. To change the execution
    policy for the default (LocalMachine) scope, start Windows PowerShell with the "Run as administrator" option. To
    change the execution policy for the current user, run "Set-ExecutionPolicy -Scope CurrentUser".
    However, the .ps1 files could still be run. Have you run my code in post #118?
      My Computer

  3. Paul Black's Avatar
    Posts : 12,191
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #123

    Hello @Matthew Wai,

    In your code, are the supposed to be *?
      My Computer

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

    Paul Black said:
    In your code, are the supposed to be *?
    No, they are not supposed to be *
    I don't know what will happen if they are replaced with *
    My code works fine with

    Paul Black said:
    Is this any better . . .
    The output was "PermissionDenied", but my .ps1 files could still be run properly.
      My Computer

  5. Paul Black's Avatar
    Posts : 12,191
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #125

    Hello @Matthew Wai,

    I just found this which I am going through . . .
    Provide A Batch File To Run Your PowerShell Script From.

    I came up with this but it doesn't quite work . . .
    Code:
    @echo off
    Set "Folder=C:\Users\System-Admin\System-Admin_Implement"
    PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%Folder%\*.ps1""' -Verb RunAs}";
    echo Press a key to restart "explorer.exe". & Pause > nul
    rem TaskKill /f /im explorer.exe & Start explorer.exe
      My Computer

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

    It cannot run .ps1 files one by one in a folder.
    You may use your codes in #119/121 if you are happy with it.

    Paul Black said:
    In your code, are the supposed to be *?
    My code works with the former but not with the latter, which will cause an error.
      My Computer

  7. Paul Black's Avatar
    Posts : 12,191
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #127

    Hello @Matthew Wai,

    Matthew Wai said:
    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
    I copied your code above into Notepad and saved it as a .cmd.
    In the code copied, it shows [6 points] instead of the normal * [5 points].
    Anyway, I ran the code and it works!
    Adapting .REG Files.-image.png
    Could you just explain why there is an echo at the beginning of this line please . . .
    Code:
    echo Set X = CreateObject("Wscript.shell")>>"%temp%\✱.vbs"
    Thanks in advance.
      My Computer

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

    Paul Black said:
    Could you just explain why there is an echo at the beginning of this line please . . .
    echo Set X = CreateObject("Wscript.shell")>>"%temp%\✱.vbs"
    The above tells Windows to do the following:
    Write the text Set X = CreateObject("Wscript.shell") into the file "%temp%\✱.vbs"

    Paul Black said:
    In the code copied, it shows [6 points] instead of the normal * [5 points].
    Anyway, I ran the code and it works!
    Do a simple test: replace all with ❤️ and run the code, which will still work.
      My Computer

  9. Paul Black's Avatar
    Posts : 12,191
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
    Thread Starter
       #129

    Hello @Matthew Wai,

    Thanks for the explanation, I understand now!

    This is very strange!
    I am on my Laptop, and it shows ✱ as a little box!
    On my Desktop, it shows as a 6 pointed star instead of a 5 pointed star.
    It doesn't matter as the script still runs OK and it will be my Desktop where the changes will be made anyway.
      My Computer


 
Page 13 of 13 FirstFirst ... 3111213

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




Windows 10 Forums