How to run batch file with powershell

  1. Posts : 25
    windows 10

    How to run batch file with powershell

    I created a basic batch file that uses "net share" to share a local path. I saved the batch file. When I double click the file I get "access is denied"... note, I am logged on as a admin.

    Anyways... I figure it has to be run using power shell. I do not know much about powershell. Can anyone tell me how I can run this batch file (by double clicking on the icon) using power shell?

    Thank you

    edit.... if I right click the file and click "run as administrator" it runs fine. I want the ability to just double click it and execute.
      My Computer

  2. Posts : 810

    Create a shortcut to your batch file (right-click drag+drop the file). Then edit the shortcut's Properties->Shortcut->Advanced.

    How to run batch file with powershell-image.png
      My Computer

  3. lx07's Avatar
    Posts : 5,479

    Or you can auto elevate your .bat by sticking this at the start (copied from UUPtoISO)
    set "params=%*"
    cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || (  echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )
    Either way you'll get a UAC warning asking you to authorize running as Administrator. You can avoid this (see following tutorials...) if you want.

    If you are admin user: Create Elevated Shortcut without UAC prompt in Windows 10 Windows 10 Tutorials

    else (but a bit risky I think): Elevated Program Shortcut - Create for Standard User - Windows 7 Help Forums
      My Computer

  4. Posts : 25
    windows 10
    Thread Starter

    thank you
      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 06:19.
Find Us

Windows 10 Forums